Corba
Corba
based on Distributed
Systems: Concepts
and Design, Edition 3, Distributed Systems Course
Addison-Wesley 2001.
2 •
Don't be put off by GIOP and IIOP
Introduction to CORBA They are just names for familiar things
4 •
CORBA IDL interfaces Shape and ShapeList
struct Rectangle{ struct GraphicalObject {
long width; string type;
long height; Rectangle enclosing;
long x; boolean isFilled;
long y; this struct is used in };
}; defining another struct. this struct is used as a parameter or result
type in methods in the remote interfaces.
interface Shape {
long getVersion() ;
GraphicalObject getAllState() ; // returns state of the GraphicalObject
}; an interface specifies a name and a set of methods
6 •
CORBA Naming Service (see Section17.3.1)
7 •
Illustration of programming CORBA
This A has
class Javatoserver hasCORBA
create classes for its
objects
import org.omg.CORBA.*;
IDL interfaces (e.g. Shape and
of type
class ShapeListServant extends _ShapeListImplBase { Shape. HowHere
ShapeList). does it do
is the that?
class
ORB theOrb;
private Shape theList[]; ShapeListServant
a servant class extends the corresponding
private int version;
private static int n=0; skeleton class (e.g. ShapeListImplBase)
public ShapeListServant(ORB orb){
theOrb = orb; CORBA objects are instances of servant classes.
// initialize the other instance variables
}
In non-OO languages implementations of CORBA
public Shape newShape(GraphicalObject g) objects can’t be classes. What might
throws ShapeListPackage.FullException { they be in C?
version++;
Shape s = new ShapeServant( g, version);
if(n >=100) throw new ShapeListPackage.FullException();
theList[n++] = s;
a servant class implements the methods in the
theOrb.connect(s);
return s;
interface (ShapeList). newShape is a factory
} method. It creates new CORBA objects. It uses the
public Shape[] allShapes(){ ... } connect method to inform the ORB about the new
public int getVersion() { ... } CORBA object. (it has a remote reference module)
} 9 •
Java class ShapeListServer (the server class)
import org.omg.CosNaming.*; The server class contains the main method
1. itimport
gets org.omg.CosNaming.NamingContextPackage.*;
a reference to the Naming Service
2. narrows it to NamingContext- from Object
import org.omg.CORBA.*;
3. makes a NameComponent
public class ShapeListServer { containing the it creates and initialises the ORB
name “ShapeList”
public static void main(String args[]) {
4. makes a try{
path
ORB orb = ORB.init(args, null);
5. uses rebind to register the name and object
reference ShapeListServant shapeRef = new ShapeListServant(orb);
orb.connect(shapeRef);
it creates an instance of ShapeListServant class - a Java
org.omg.CORBA.Object object - which
objRef = is made a CORBA object
by using the connect method to register it with the ORB
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
NameComponent nc = new NameComponent("ShapeList", "");
NameComponent path[] = {nc};
ncRef.rebind(path, shapeRef); it waits for client requests
java.lang.Object sync = new java.lang.Object(); Figure 17.4
synchronized (sync) { sync.wait();}
10 •
Java client program for CORBA interfaces Shape and
ShapeList
import org.omg.CosNaming.*;
1. it contacts the NamingService for initial context
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*; 2. Narrows it to NamingContext
it creates and initialises an ORB
public class ShapeListClient{ 3. It makes a name component
4. {It makes a path
public static void main(String args[])
try{ 5. It gets a reference to the CORBA object called
ORB orb = ORB.init(args, null); “ShapeList”, using resolve and narrows it
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
it uses one ofinthe remote references in the array to
it invokes the allShapes
NamingContext ncRef method the CORBA object
= NamingContextHelper.narrow(objRef); to get an array
containing remote invoke
references thetogetAllState
all of the method in the corresponding
GraphicalObjects currently
NameComponent nc = new NameComponent("ShapeList",
CORBA object whose type is Shape "");
stored by the serverpath
NameComponent [] = { nc };
the value returned is of type GraphicalObject
ShapeList shapeListRef =
ShapeListHelper.narrow(ncRef.resolve(path));
Shape[] sList = shapeListRef.allShapes();
GraphicalObject g = sList[0].getAllState();
} catch(org.omg.CORBA.SystemException e) {...}
} Figure 17.5
11 •
The main components of the CORBA architecture
DynamicClient stubs/proxies
Skeletons
invocation interface is designed to allow clients
ORB The CORBA
core– these
Object
are architecture
inadapter
the client
–skeleton language.
classes (for OO languages) are generated in the
In some applications (e.g. browsers), a client without the appropriate
to invoke
The proxy
role ofclass
the IDLmethods
Implementation
– an –may
ORBan language
compiler
object
needisadapter
core tosimilar
invoke
in
forofthe
the
repository CORBA
bridgesserver
client
toathat ofthe
method
by
language
thegap
in
objects
an between
IDL compiler.
uses
communication an IDL interface to
a remote object.module of Figure 5.6.
Interface –
In addition, repository
generate
clients
an
CORBA doesfor
and
ORB
one
–remote
objects
core
activates
CORBA of
notobject-oriented
allow
the
can
registered
objects
provides
classes
following:
methodbe
an with
for
invocations
implemented
servers on
IDL interfaces
interface
proxies
are
demand
that
to be indispatched
and aand
includes variety
downloaded locates
the viaprogramming
of the appropriate
running
following:
at run time servers
skeleton to a particular
languages servant,
the class of a proxy
inlanguages
theasinterface uses the
repository theprogramming
provides
object adapterlanguage
information name interfaces
about
to of the
registered
register andcorresponding
IDL interfaces
activate servant
servers. classes.
to clients
- operations Javaenabling
RMI. it to be started and stopped;
and–servers
it has –itfor
that
the does –the
procedural
require
followingthe work languages
it.skeleton
More of about
additionalthe athis
unmarshalsset later.
remote ofreference
components
stub
the procedures.
arguments
and
compared
in requestmodules
despatcherto
messages
Figure 5.6 in Fig. 5.6
- operations
The dynamic –toas before,
more
convert
invocation
andabout
between this
marshals
the client later
interface
remote is object
CORBA’s
exceptions
stubs/proxies references
and alternative.
results and
in strings;
(we
reply
marshal the arguments in will discuss
messages.
–more
object about
adapter, the object
implementation adapter later.
repository and interface repository
it later with
- operations the Interface
invocation
to provide requests
argument Repository)
and
listsunmarshal
for requests exceptions
using dynamic and results in replies.
invocation.
client server
implementation interface
repository repository object skeleton
adapter
or dynamic invocation
Figure 17.6 or dynamic skeleton
12 •
Object adapter
an object adapter bridges the gap between
– CORBA objects with IDL interfaces and
– the programming language interfaces of the corresponding servant (classes).
– it does the work of the remote reference and despatcher modules in Fig. 5.6.
An object adapter has the following tasks:
– it creates remote object references for CORBA objects;
– it dispatches each RMI via a skeleton to the appropriate servant;
– it activates objects.
An object adapter gives each CORBA object a unique object name.
– the same name is used each time an object is activated.
it is specified by the application program or generated by the object adapter.
– Each active CORBA object is registered with its object adapter,
which keeps a remote object table to maps names of CORBA objects to servants.
Each object adapter has its own name - specified by the application
program or generated automatically.
13 •
Implementation repository
Implementation repository
– it activates registered servers on demand and locates running servers
– it uses the object adapter name to register and activate servers.
– it stores a mapping from the names of object adapters to the
pathnames of files containing object implementations.
when a server program is installed it can be registered with the
implementation repository.
when an object implementation is activated in a server, the hostname and
port number of the server are added to the mapping.
– Implementation repository entry:
- not all CORBA objects (e.g. call backs) need be activated on demand
- access control information can be stored in an implementation repository
14 •
Interface repository
15 •
CORBA IDL
16 •
IDL module Whiteboard
module Whiteboard {
Figure 17.7 struct Rectangle{
...} ;
struct GraphicalObject {
...};
interface Shape {
...};
typedef sequence <Shape, 100> All;
interface ShapeList {
...};
};
17 •
we saw raises in the newShape
IDL method signatures method of ShapeList
18 •
Figure 17.8
IDL constructed types – 1
20 •
17.2.4 CORBA remote object references
22 •
Summary