Download presentation
Presentation is loading. Please wait.
Published byMark Simon Modified over 8 years ago
1
Object Oriented Middleware (OOMI) Presentation: Locating Distributed Objects - A presentation of the Interoperable Naming Service & Sun’s Java ORB/ Orbacus C++ ORB implementations
2
Outline Object Naming Motivation Common Principles CORBA Initialization Service CORBA Naming Service Real world implementations vs. Specification Real world example POA relations is next presentation Object Trading not part of Course Curriculum
3
Motivation Recap: last time on CORBA class, IOR as files Goal: avoid using physical locations for locating components Naming: Locating components by external names Similar to white pages Java RMI Registry, CORBA Naming Service Trading: Locating components by service characteristics Similar to yellow pages Web services UDDI
4
Naming - Common Principles (1) Object-oriented middleware uses object references to address server objects We need to find a way to get hold of these object references without assuming physical locations A name is a sequence of character strings that can be bound to an object reference A name binding can be resolved to obtain the object reference
5
Naming - Common Principles (2) Potentially many server objects in system Server objects may have several names Leads to large number of name bindings Name space has to be arranged in a hierarchy to avoid Name clashes Poor performance when binding/resolving names Hierarchy achieved by naming contexts Might not be necessary if you design coarse/grained
6
Naming - Common Principles (3): Composite Names Names are composed of possibly more than one component Used to describe traversals across several naming contexts Examples: ("UEFA","England","Premier", “Manchester United") ("UEFA",“Cup Winners", “Manchester United") HOWEVER: Often only a flat naming structure is used! Will help you deal with performance issues
7
CORBA Naming Service Consists of two elements: Standardized CORBA Interfaces Vendor dependent server implementations Two specifications ”Old version”: CORBA Naming Service “New version”: CORBA Interoperable Naming Service Alternative: Trading In agreement with the principles Names are scoped in naming contexts Multiple names can be defined for object references Remember not all object references need names Façade & Factory objects have names
8
CORBA Names Names are composed of simple names Simple names are value-kind pairs Value attribute is used for resolving names Kind attribute is used to provide information about the role of the object module CosNaming { typedef string Istring; struct NameComponent { Istring id; Istring kind; }; typedef sequence Name;... };
9
Example of a bind() operation Registration of a simple Name binding at a Name Server: CosNaming::Name name; name.length(1); name[0].id=CORBA::string_dup(“MyFactory"); name[0].kind= CORBA::string_dup(""); // bind name with my_factory servant at NameServer naming_context->bind(name,my_factory.in()); “MyFactory” MyFactoryImp NameServer ior
10
The IDL Interfaces Naming Service is specified by two IDL interfaces: NamingContext defines operations to bind objects to names and resolve name bindings BindingInterator defines operations to iterate over a set of names defined in a naming context interface NamingContext { void bind(in Name n,in Object obj) raises (NotFound,...); Object resolve(in Name n) raises(NotFound,CannotProceed,...); void unbind(in Name n) raises(NotFound,CannotProceed...); void list(in unsigned long how_many, out BindingList bl, out BindingIterator bi);... }; Excert of NamingContext interface – the Interoperable Naming Service has extensions found in the NamingContextExt interface
11
Bootstrapping Naming Service How to get access to the Root Naming Context? ORB Interface provides for initialization: CORBA Initialization Service is used CORBA::ORB_init() & the CORBA::ORB interface module CORBA { interface ORB { typedef string ObjectId; typedef sequence ObjectIdList; exception InvalidName{}; ObjectIdList list_initial_services (); Object resolve_initial_references ( in ObjectId identifier) raises(InvalidName); }
12
Implementation details Consists of two elements: Standardized CORBA Interfaces Vendor dependent server implementation Naming Services are themselves CORBA objects Need a server proces running Very differently implemented by vendors We look at Orbacus & Java J2SE SDK ORB
13
Vendor specific Naming Servers Orbacus C++ nameserv OR ntnameservice (native Windows NT service) Orbacus Java com.ooc.CosNaming.Server Java J2SE (prior to 1.4.1) tnameserv (transient only and NOT interoperable) Java J2SE (after 1.4.1) orbd (ORB Daemon – which includes a naming server) servertool (if you want to use a persistent naming service) Example: start orbd –ORBIntialPort 2500 will start a transient naming service listening on port 2500
14
Example implementation HelloWorld using the ORBD Nameservice (in transient mode) We need: Hello.idl HelloServer.java (pos. HelloImpl.java) HelloClient.java Then we need the IDLJ tool (with –fall) the ORBD daemon – as the nameserver
15
module HelloApp { interface Hello { string sayHello(); oneway void shutdown(); }; Hello.idl Setting up the module, interface & the methods needed for our example Two methods defined
16
import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA; import java.util.Properties; class HelloImpl extends HelloPOA { private ORB orb; public void setORB(ORB orb_val) { orb = orb_val; } // implement sayHello() method public String sayHello() { return "\nHello world !!\n"; } // implement shutdown() method public void shutdown() { orb.shutdown(false); } (continued on next slide) … HelloWorld Server 1 of 3 The Servant part – our implementation of the IDL interface -nothing new here Extends HelloPOA sayHello implemented Shutdown implemented
17
… (continued from last slide) public class HelloServer { public static void main(String args[]) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // get reference to rootpoa & activate the POAManager POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); // create servant and register it with the ORB HelloImpl helloImpl = new HelloImpl(); helloImpl.setORB(orb); // get object reference from the servant org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloImpl); Hello href = HelloHelper.narrow(ref); // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt which is part of the Interoperable // Naming Service (INS) specification. NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); (continued on next slide) … HelloWorld Server 2 of 3 The Server part – getting the Nameservice context As discussed last week Use Init. Service to get Name Service Just another CORBA object
18
… (continued from last slide) // create the name compoent String name = "Hello"; NameComponent path[] = ncRef.to_name( name ); // bind the Object Reference in Naming ncRef.rebind(path, href); System.out.println("HelloServer ready and waiting..."); // wait for invocations from clients orb.run(); } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } System.out.println("HelloServer Exiting..."); } HelloWorld Server 3 of 3 Binding the HelloApp object reference to the Nameserver context using the name ”Hello” Using the ”to_name” to create a Name Component Bind name & reference Run ORB & wait for invocations
19
import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; public class HelloClient { static Hello helloImpl; public static void main(String args[]) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // get the root naming context – getting hold of the Name Service (ORBD) org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt instead of NamingContext. This is // part of the Interoperable naming Service – meaning that you may com with // other ORBs NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // resolve the Object Reference in Naming – using ncRef’s resolve operation String name = "Hello"; helloImpl = HelloHelper.narrow(ncRef.resolve_str(name)); System.out.println("Obtained a handle on server object: " + helloImpl); System.out.println(helloImpl.sayHello()); helloImpl.shutdown(); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } }} HelloWorld Client Using same name service to get the name – now using the resolve operation
20
Commands used To compile static stubs idlj -fall Hello.idl Compile all Java files using javac To start-up the Naming Service orbd -ORBInitialPort 1050 Starting up the server: start java HelloServer -ORBInitialPort 1050 -ORBInitialHost localhost Starting up the client: java HelloClient -ORBInitialPort 1050 -ORBInitialHost localhost
21
Now with a C++ client We want to contact the ORBD Nameserver from a C++ Client Using the Orbacus C++ ORB Needed: Hello.idl HelloCORBAClient.cpp Orbbacus idl compiler
22
#include int run(CORBA::ORB_ptr); int main(int argc, char* argv[]) { int status = EXIT_SUCCESS; CORBA::ORB_var orb; try { //Connect to the ORB with supplied arguments orb = CORBA::ORB_init(argc, argv); status = run(orb); } catch(const CORBA::Exception&){ status = EXIT_FAILURE;} if(!CORBA::is_nil(orb)) { try { //remember to inform the orb that we no longer need it orb -> destroy(); } catch(const CORBA::Exception&){ status = EXIT_FAILURE; } } return status; } … (continued on next) … HelloWorld C++ Client Part 1 of 2 Do the usual initialization to connect to ORB and call the Run method Init. and run(orb)
23
… (continued from last slide) int run(CORBA::ORB_ptr orb) { //OBTAINING REFERENCE TO Name Server CORBA::Object_var obj = orb->resolve_initial_references("NameService"); //Narrow the Call – we need to turn the Name server obj into a NamingContext CosNaming::NamingContext_var naming_context; naming_context = CosNaming::NamingContext::_narrow(obj); //Now setup the CosNaming name that we want to find (Hello) CosNaming::Name name; name.length(1); name[0].id= CORBA::string_dup("Hello"); name[0].kind= CORBA::string_dup(""); //Using the resolve operation on the root naming_context - get the Hello Servant stub CORBA::Object_var tempObj = naming_context->resolve(name); //Call Narrow now to transform the generic CORBA Obj ínto an HelloApp::Hello class HelloApp::Hello_var hello = HelloApp::Hello::_narrow(tempObj); cout sayHello() << endl; return 0; } HelloWorld C++ Client Part 2 of 2 Using the ORBD name- service to get the IOR to the Java Servant Error handling has been excluded Find NameService Use the ”manual” mapping method from the CosNaming
24
Commands used To compile static stubs \ooc\bin\idl Hello.idl Compile all files Remember to start-up ORBD and the Java Servant on port 1050 Starting up the client: C:\OOC_DEV\HelloCorbaCppNaming\Debug>HelloCorba - ORBInitRef NameService=corbaloc::localhost:1050/NameService Here we see the corbaloc used for bootstrapping
25
Transient or Persistent Naming Transient Naming Service object references will not survive termination of nameserver servants need to reregister clients need to resolve again Persistent Naming Service Servants are activated automatically Object references are persisted Not the same as persistent servants! Need a persistent portable object adapter (POA) Need to register the servant with the servertool Need a persistence mechanism
26
Tutorials How to implement a Transient Name binding using ”orbd” http://java.sun.com/j2se/1.5.0/docs/guide/idl/jidlExample.html How to implement a Persistent Name binding using ”orbd & servertool” http://java.sun.com/j2se/1.5.0/docs/guide/idl/jidlExample2.ht mlhttp://java.sun.com/j2se/1.5.0/docs/guide/idl/jidlExample2.ht ml We shall be taking a closer look at this when we discuss the POA in detail
27
Limitations of Naming Limitation of Naming: Client always has to identify the servant by name Inappropriate if client just wants to use a service at a certain quality but does not know from who: Automatic cinema ticketing Video on demand Electronic commerce Trading Service Not curriculum
28
Læringsmål Alignment Når kurset er færdigt forventes den studerende at kunne: Definere, beskrive og sammenligne forskellige typer af objektorienterede middleware frameworks til apparater og computere, med primær fokus på CORBA og sekundært.NET Remoting teknologierne, herunder fordele og ulemper forbundet med de forskellige teknologier Definere og beskrive principper omkring transparens og heterogenitet i relation til middlewareteknologier Definere og beskrive gængse teorier, metoder og retningslinier indenfor det objektorienterede middleware paradigme og anvende disse til at designe effektive distribuerede systemer Designe og konstruere et distribueret system der gør brug af CORBA og.NET Remoting teknologierne med tilhørende værktøjssupport Naming Servicen er central for forståelsen af CORBA. Derfor skal både koncept og Kode kunne genkendes og forklares Naming Servicen er central for forståelsen af CORBA. Derfor skal både koncept og Kode kunne genkendes og forklares MANGLER: hvordan I praktisk omsætter denne viden Naming og location Transparens hænger tæt sammen Naming og location Transparens hænger tæt sammen Det forventes at I kan bruge CORBA Naming til jeres Opgave. Både design og i praksis Det forventes at I kan bruge CORBA Naming til jeres Opgave. Både design og i praksis
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.