Escolar Documentos
Profissional Documentos
Cultura Documentos
based on Distributed
Systems: Concepts
and Design, Edition 3, Distributed Systems Course
AddisonWesley 2001.
2 •
Don't be put off by GIOP and IIOP
Introduction to CORBA They are just names for familiar things
typedef sequence <Shape, 100> All; sequences and arrays in typedefs
interface ShapeList {
exception FullException{ }; interface ShapeList
Shape newShape(in GraphicalObject g) raises (FullException);
All allShapes(); // returns sequence of remote object references
long getVersion() ;
the parameter of newShape is an in parameter and
}; Exceptions defined by raises and set
of type Graphical Object The return value is an by throw. They can have arguments.
Figure 17.1
extra out parameter of type Shape. No classes can
be passed as arguments or results
5 •
Parameters in CORBA IDL
6 •
CORBA Naming Service (see Section17.3.1)
7 •
Illustration of programming CORBA
public interface ShapeList extends org.omg.CORBA.Object {
Consider resolve in the naming service, we ask it to look up
Shape newShape(GraphicalObject g) throws ShapeListPackage.FullException;
a reference to ShapeList, it returns an Object. What is the problem?
Shape[] allShapes();
int getVersion();
Figure 17.2
} What is the problem with out arguments in Java?
e.g. void getPerson(in string name, out Person p);
8 •
The ShapeListServant class of the Java server program for the
CORBA interface ShapeList. Figure 17.3
import org.omg.CORBA.*; This class has to create CORBA objects
A Java server has classes for its
IDL interfaces (e.g. Shape and
of type Shape. How does it do that?
class ShapeListServant extends _ShapeListImplBase {
ShapeList). Here is the 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
objects can’t be classes. What might they be in C?
public Shape newShape(GraphicalObject g) throws ShapeListPackage.FullException {
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
• itimport org.omg.CosNaming.NamingContextPackage.*;
gets a reference to the Naming Service
• narrows it to NamingContext- from Object
import org.omg.CORBA.*;
• public class ShapeListServer {
makes a NameComponent containing the it creates and initialises the ORB
name public static void main(String args[]) {
“ShapeList”
• makes a try{path
ORB orb = ORB.init(args, null);
– 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 objRef =
object - which is made a CORBA object
orb.resolve_initial_references("NameService");
by using the connect method to register it with the ORB
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.*;
• it contacts the NamingService for initial context
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*; • Narrows it to NamingContext
it creates and initialises an ORB
public class ShapeListClient{ • It makes a name component
• It makes a path
public static void main(String args[]) {
try{ • It gets a reference to the CORBA object called
“ShapeList”, using resolve and narrows it
ORB orb = ORB.init(args, null);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
it uses one ofinthe remote references in the array to
it invokes the allShapes method the CORBA object
NamingContext ncRef = NamingContextHelper.narrow(objRef); to get an array
containing remote invoke thetogetAllState
references all of the method in the corresponding
GraphicalObjects currently
NameComponent nc = new NameComponent("ShapeList", "");
stored by the server CORBA object whose type is Shape
NameComponent path [] = { 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)
without the are generated in the
In some applications (e.g. browsers), a client appropriate
to invoke
The proxy
role ofclass
the ORB IDLmethods
Implementation
– an –may
an language
compiler
object
core
need isadapter
tosimilar
invoke
in
forofthe
the
repository CORBA
bridgesserver
client
toathat ofthe
method
by
language
thegap
in
objects
an between
IDL compiler.
uses
communication
a remote an IDL
object. interface
module to
of Figure 5.6.
Interface –
In addition, repository
generate
clients
an
CORBA doesfor
and
ORB one
–remote
objects
activates
CORBA
core
of
provides
notobject-oriented
allow
the
can
registered following:
method
objects
classes be
an with
for
invocations
implemented
servers on
IDL interfaces
interface
proxies that
to be
are
demand 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 ofofa the
proxy
inlanguages
theasinterface the programming
repository
uses provides language
information interfaces
about registered corresponding
IDL interfaces servant classes.
to clients
- operations Javaenabling
RMI. it the
to beobject adapter
started and name
stopped; to register and activate servers.
and–servers –it for
that –the
procedural
require
does the languages
it.skeleton
More
work of about
the athis
unmarshalssetlater.
remote ofreference
stub
the procedures.
arguments
and in requestmodules
despatcher messages
- operations it has
The dynamic the
–toas more
convert following
invocation
andabout
between additional
this later
remote
interface
marshals is components
object
CORBA’s
exceptions references
and compared
resultsand
alternative. in strings;
(we
reply to
will Figure
discuss
messages. 5.6 in Fig. 5.6
before,
–more the client
about the objectstubs/proxies
adapter marshal the arguments in
later.
- operations
it later withobject
to provide adapter,
the Interface
invocation requests
argument implementation
Repository)
and
listsunmarshal repository
for requests usingand
exceptions interface
and results
dynamic repository
in replies.
invocation.
client server
implementation interface
repository repository object skeleton
adapter
or dynamic invocation
Figure 17.6 or dynamic skeleton
12 •
The OA has a remote object reference
Object adapter and a method to be invoked on it
an object adapter bridges What does dispatch do in C++/Java?
the gap between
What does dispatch in C?
– 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
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
this figure continues on the next slide
See Fig 5.1 for an example of string
19 •
Figure 17.8
IDL constructed types – 2
20 •
17.2.4 CORBA remote object references
ShapeList B XX V
P
C
D E S T
R Q U
22
Figure 17.10
Part of the CORBA Naming Service NamingContext
interface in IDL
struct NameComponent { string id; string kind; };
typedef sequence <NameComponent> Name;
interface NamingContext {
void bind (in Name n, in Object obj);
binds the given name and remote object reference in my context.
void unbind (in Name n);
removes an existing binding with the given name.
void bind_new_context(in Name n);
creates a new naming context and binds it to a given name in my context.
Object resolve (in Name n);
looks up the name in my context and returns its remote object reference.
void list (in unsigned long how_many, out BindingList bl, out BindingIterator bi);
returns the names in the bindings in my context.
};
23
Figure 17.11
CORBA event channels
event channel
supplier consumer
24
CORBA services include the following
Copyright © George
Coulouris, Jean Dollimore,
Tim Kindberg 2001
From Coulouris, Dollimore and Kindberg
email: authors@cdk2.net
This material is made Distributed Systems:
available for private study
and for direct use by
individual teachers.
Concepts and Design
It may not be included in any
product or employed in any Edition 3, © Addison-Wesley 2001
service without the written
permission of the authors.
Viewing: These slides
must be viewed in
slide show mode.
Exercise 17.1
The Task Bag is an object that stores pairs of (key and value). A key is a
string and a value is a sequence of bytes. Its interface provides the
following remote methods:
pairOut: with two parameters through which the client specifies a key and a value to be
stored.
pairIn: whose first parameter allows the client to specify the key of a pair to be removed
from the Task Bag. The value in the pair is supplied to the client via a second
parameter. If no matching pair is available, an exception is thrown.
readPair: is the same as pairIn except that the pair remains in the Task Bag.
Use CORBA IDL to define the interface of the Task Bag. Define an
exception that can be thrown whenever any one of the operations cannot
be carried out. Your exception should return an integer indicating the
problem number and a string describing the problem. The Task Bag
interface should define a single attribute giving the number of tasks in the
bag. page 680
28
Exercise 17.2
29
Exercise 17.3
30
Exercise 17.4
31
Exercise 17.5
32
Exercise 17.6
33
Exercise 17.7
34
Exercise 17.8
35
Exercise 17.9
36
Exercise 17.10
37
Exercise 17.11
38
Exercise 17.12
39
Exercise 17.13
40
Exercise 17.14
41
Exercise 17.15
42
Exercise 17.16
43
Exercise 17.17
44
Exercise 17.18
45
Exercise 17.19 (first part)
Describe how to interpose an Event Channel between the supplier and the
consumers in your solution to Exercise 17.18. An event channel has the following
IDL interface:
interface EventChannel {
ConsumerAdmin for_consumers();
SupplierAdmin for_suppliers();
};
where the interfaces SupplierAdmin and ConsumerAdmin, which allow the supplier
and the consumer to get proxies are defined in IDL as follows:
interface SupplierAdmin {
ProxyPushConsumer obtain_push_consumer();
---
};
interface ConsumerAdmin {
ProxyPushSupplier obtain_push_supplier();
---
};
46
Exercise 17.19 continued
The interface for the proxy consumer and procy supplier are
defined in IDL as follows:
interface ProxyPushConsumer : PushConsumer{
void connect_push_supplier (in PushSupplier supplier)
raises (AlreadyConnected);
};
interface ProxyPushSupplier : PushSupplier{
void connect_push_consumer (in PushConsumer consumer)
raises (AlreadyConnected);
};
47