Title: ObjectOriented Middleware OOMI
1Object-Oriented Middleware(OOMI)
- Locating Distributed Objects Emmerich Chapter
8.
16.03.2003
2Outline
- Quick recap on object references
- 2. Object Naming
- Principles
- CORBA Naming Service
- 3. Object Trading
- (not part of Course Curriculum)
3Recap on IOR so far
IOR000000000000001749444c3a48656c6c6f4170702f4865
6c6c6f3a312e30000000000001000000000000006c00010200
0000000e3139322e3136382e312e3130300011b600000021af
abcb0000000020a80a25030000000100000000000000000000
0004000000000a000000000000010000000100000020000000
00000100010000000205010001000100200001010900000001
00010100
- IOR Interoperable Object Reference
- Includes info on Repository ID (standard),
Endpoint Info (standard) - including IP and port
number, Object Key (proprietary) - Can be written into a file read
- as we have seen the last two lectures
- Not really nice with a file-based reference or
what? - File-based may be necessary due to firewall
problems - Possible to use a HTTP or FTP server for
distributing the references
4include ltOB/CORBA.hgt include ltHello.hgt
include ltfstream.hgt int run(CORBAORB_ptr)
int main(int argc, char argv) int status
EXIT_SUCCESS CORBAORB_var orb try
orb CORBAORB_init(argc, argv) status
run(orb) catch(const CORBAException)
status EXIT_FAILURE
if(!CORBAis_nil(orb)) try
orb -gt destroy() catch(const
CORBAException) status EXIT_FAILURE
return status
HelloCorba C Client with file-based IOR Part 1
Init ORB
Destroy ORB
5 int run(CORBAORB_ptr orb) const
char refFile "object.ref" ifstream
in(refFile) char s2048 in gtgt s
CORBAObject_var obj orb -gt
string_to_object(s) HelloAppHello_var hello
HelloAppHello_narrow(obj) cout ltlt
hello-gtsayHello() ltlt endl return 0
HelloCorba C Client with file-based IOR Part 1
Object reference Read from file
Narrow the call (CORBA type cast)
Call via Proxy and print
6Motivation
- Avoid using physical locations for locating
components! Why? - 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
71. 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
8Common Principles (2)
- There may be many server objects in a distributed
object 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
9Common Principles Naming Contexts
UEFA
England
Germany
Cup Winners
2. Liga
First
1. Liga
Premier
Lautern
Manchester United
Bochum
QPR
South End United
1.FC Kaiserslautern
Man United
BVB
Bayern
Chelsea
10Common Principles 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!
11Common Principles Name Server Behavior
- Name bindings are managed by Name Servers
- Not every server object needs a name
- Server objects may have several names (aliases)
- Name servers must store bindings persistently
- Name servers should be tuned towards efficiently
resolving name bindings - Name server may itself be distributed
12Stock Quoter Example with NameServer
Stock Quoterclient 1
TCP/IPNetwork
Stock Quoterclient 2
Broker ArchitecturePattern
13CORBA Naming Service
CORBAFacilities
DomainInterfaces
ApplicationObjects
Object Request Broker
NamingService
CORBA Services
14CORBA Naming Service
- Supports bindings of names to CORBA object
references - Consists of two elements
- Standardized CORBA Interfaces
- Vendor dependent server implementation
- Names are scoped in naming contexts
- Multiple names can be defined for object
references - Not all object references need names
- Factory objects have names
15Client and Server using a NameServer
Stock Quoterclient 1
16CORBA 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
17IDL Types for Names
- module CosNaming
- typedef string Istring
- struct NameComponent Istring id Istring
kind -
- typedef sequence ltNameComponentgt Name
- ...
18Example of a bind() operation
Registration of a simple Name binding at a Name
Server CosNamingName namename.length(1)name
0.id CORBAstring_dup(MyFactory")name0.k
ind CORBAstring_dup("") // bind name with
my_factory servant at NameServer naming_context-gtb
ind(name,my_factory.in())
19The 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
20Excerpt of NamingContext Interface
- 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)
- ...
21Naming Scenario Binding
Promote Bielefeld to German '1. Liga' and
relegate Frankfurt
root Naming Context
cClient
22Bootstrapping Naming Service
- How to get the Root Naming Context?
- ORB Interface provides for initialization
-
- module CORBA
- interface ORB typedef string ObjectId
typedef sequence ltObjectIdgt ObjectIdList - exception InvalidName
- ObjectIdList list_initial_services()
- Object resolve_initial_references(
in ObjectId identifier) raises(InvalidName) -
-
23Naming Scenario Resolving
Print squad of Borussia Dortmund
24Implementation details
- Consists of two elements
- Standardized CORBA Interfaces
- Vendor dependent server implementation
- Need a server proces running
- We look at Orbacus Java J2SE SDK
25Vendor 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
- 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 naming service listening on port
2500
26Example implementation
- HelloWorld using the ORBD Nameservice
- We need
- Hello.idl
- HelloServer.java (pos. HelloServant.java)
- HelloClient.java
- Then we need
- the IDLJ tool (with fall)
- the ORBD daemon as the nameserver
27 module HelloApp interface Hello
string sayHello() oneway void shutdown()
Hello.idl
Setting up the module, interface the methods
needed for our example
28- 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"
HelloWorld Server 1 of 3
The Servant part our implementation of the IDL
interface -nothing new here
29- (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_i
nitial_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)
HelloWorld Server 2 of 3
The Server part getting the Nameservice context
30- (continued from last slide)
- // bind the Object Reference in Naming
- String name "Hello"
- NameComponent path ncRef.to_name( name
) - 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
31- 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
HelloWorld Client
Using same nameservice to get the name now
using the resolve operation
32Commands 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
33Now 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
34- include ltOB/CORBA.hgt
- include ltOB/CosNaming.hgt
- include ltHello.hgt
- int run(CORBAORB_ptr)
- int main(int argc, char argv)
-
- int status EXIT_SUCCESS
- CORBAORB_var orb
- try
- //Connect to the ORB with supplied
arguments - orb CORBAORB_init(argc, argv)
- status run(orb)
-
- catch(const CORBAException) status
EXIT_FAILURE - if(!CORBAis_nil(orb))
-
- try
HelloWorld C Client Part 1 of 2
Do the usual initialization to connect to ORB
35- (continued from last slide)
- int run(CORBAORB_ptr orb)
-
- //OBTAINING REFERENCE TO Name Server
- CORBAObject_var obj orb-gtresolve_initial_refe
rences("NameService") - //Narrow the Call we need to turn the Name
server obj into a NamingContext - CosNamingNamingContext_var naming_context
- naming_context CosNamingNamingContext_na
rrow(obj) - //Now setup the CosNaming name that we want to
find (Hello) - CosNamingName name
- name.length(1)
- name0.id CORBAstring_dup("Hello")
- name0.kind CORBAstring_dup("")
HelloWorld C Client Part 2 of 2
Using the ORBD name- service to get the IOR
to the Java Servant
36 int run(CORBAORB_ptr orb)
CORBAObject_var tempObj // OBTAINING
REFERENCE TO Name Server CORBAObject_var obj
orb-gtresolve_initial_references("NameService")
CosNamingNamingContext_var naming_context
try naming_context CosNamingNamingContext
_narrow(obj) catch (const CORBAException
e) cerr ltlt " Naming_Context narrow error "
ltlt endl throw 0 if (CORBAis_nil(naming_c
ontext)) cerr ltlt " No naming context found"
ltlt endl throw 0 //Now setup the CosNaming
name that we want to find (Hello) CosNamingName
name name.length(1) name0.id
CORBAstring_dup("Hello") name0.kind
CORBAstring_dup("") try //Using the
resolve operation on the root naming_context
tempObj naming_context-gtresolve(name) catch
(const CosNamingNamingContextNotFound)
cerr ltlt " Hello Object not found " ltlt endl
//Call Narrow using HelloAppHello_var hello
HelloAppHello_narrow(tempObj) cout ltlt
hello-gtsayHello() ltlt endl return 0
HelloWorld C Client Part 2 with error hand.
Same code but this time including error handling
37Commands 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\DebuggtHelloCorba
-ORBInitRef NameServicecorbaloclocalhost1050/N
ameService
38Transient 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
- Need to register the HelloWorld Server with the
servertool
39Tutorials
- How to implement a Transient Name binding using
orbd - http//java.sun.com/j2se/1.4.1/docs/guide/idl/tuto
rial/GSserver.html - How to implement a Persistent Name binding using
orbd servertool - http//java.sun.com/j2se/1.4.1/docs/guide/idl/jidl
Example2.html
40Limitations of Naming
- Limitation of Naming in all approaches Client
always has to identify the server 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
41CORBA Trading Service
CORBAFacilities
DomainInterfaces
ApplicationObjects
Object Request Broker
ObjectTrader
CORBA Services