Download CORBA — Common Object request Broker Architecture A

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CORBA
General Architecture
Client
CORBA — Common Object request Broker Architecture
A standardized way how objects can cooperate in a distributed environment.
Approved by the members of OMG — Object Management Group
Interface
Repository
Dynamic
Invocation
Examples of languages:
—
C
—
C++
—
Java
—
Ada
—
Cobol
—
Smalltalk
—
Objective C
—
Lisp
1 (25) - DISTRIBUTED SYSTEMS
ORB
Interface
IDL
Stubs
ORB CORE
Dynamic
Skeleton
Implementation
Repository
Object
Adapter
Static
Skeleton
Interface
ORB
Object Implementation
Normal call
Up call
2 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
Object Request Broker
—
CORBA - Sven Arne Andreasson - Computer Science and Engineering
ORB
Interface Definition Language —
IDL
Is used for static definition of object interfaces.
Object Broker, relieves the communication among objects.
Makes it possible to let objects implemented in different programming languages to cooperate.
searching for methods
IDL syntax resembles C++ with addition for distributed systems.
format transformation
Example: A Time Server:
parameter and return value adaptation
synchronization
activating
The communication between two ORBs must follow a given standardized protocol:
IIOP, Internet Inter-ORB Protocol
module TimeServer
{
struct Timevalue
{
long hour;
long minute;
long second;
};
exception Fault
{
string reason;
};
3 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
4 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
interface Time
{
// Reads current time
Timevalue get_time();
// Sets time zone.
void set_zone(in long zone) raises(Fault);
// Reads time zone,
long get_zone();
};
interface Alarming
{
void give_alarm(in string alarmText);
};
5 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
interface Alarm
{
// sets Alarm time
void set_alarm(in Timevalue alarmTime,
in Alarming WhichToBeAwaken)raises(Fault);
};
interface Timeserver // Interface for creating the others
{
Time createTime();
Alarm createAlarm();
};
};
6 (25) - DISTRIBUTED SYSTEMS
Stub and Skeleton
A Stub is generated for each object specified in IDL.
CORBA - Sven Arne Andreasson - Computer Science and Engineering
ORB interface
Using this interface both the client and the server can reach functions offered by the ORB kernel.
Will be linked into the client at compilation.
A Stub is the client programs view of the server,
it works as a local object.
In the same way a Skeleton is the servers interface to the ORB.
7 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
8 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
Dynamic Invocation Interface (DII)
and
Dynamic Skeleton Interface (DSI)
Interface Repository
Interface Repository is a database where the ORB keeps the different object interfaces.
(not included in the java toolkit ORB)
This is used for creating interfaces dynamically at runtime instead at the compilation.
The client should give parameter types and result type.
These can be found using the Interface Repository.
Corresponding for server and Implementation Repository
9 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
10 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
Object Adapters
Object Adapters are the interfaces between the ORB and the object implementation.
By removing the interface from the kernel, the kernel will become simpler.
It also makes it possible to construct custom-made interfaces.
Object Adapters have four interfaces:
Portable Object Adapter
— POA
Portable Object Adapter offers the following services:
Registering implementations so clients can access them.
Activating an implementation if an object is not available when a request arrives.
one private interface to the IDL skeleton.
Creating object references.
one private interface to the DSI.
Access and security control.
one private interface to the ORB kernel.
Call of methods in the implementation through skeleton.
one public interface that the object implementation uses.
In CORBA there exists a special predefined Object Adapter that is shipped with "all" ORBs:
Portable Object Adapter — POA
11 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
12 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
Portable Object Adapter
—
POA
There is also support for:
Properties
Static connection
Object survives restart of server.
Resembles Remote Procedure Call
Transparent object activating
Fast
Multiple concurrent object identities
When changing the servers interface the clients must be recompiled.
Transient objects
—
RPC
Dynamic connection
Object ID namespace
Slow
Policies: mulithreading, security, and object management
When changing the servers interface the clients doesn’t have to be recompiled.
Multiple distinct POAs in a single server with different policies and namespaces
13 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
14 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
CORBA & Java
IDL compiler
To achieve java stubs and skeletons the idl-file is compiled as:
ORB
The Java 2 ORB comes with Sun's Java 2 SDK.
It is missing several features.
VisiBroker for JavaA popular Java ORB from Inprise Corporation. VisiBroker is also embedded in other
products.
idlj
-fall TimeServer.idl
gives the following classes in package (directory) ’TimeServer’ :
OrbixWeb
A popular Java ORB from Iona Technologies.
Alarm.java
Fault.java
TimeValueHolder.java
WebSphere
A popular application server with an ORB from IBM.
Alarming.java
FaultHelper.java
Timeserver.java
AlarmingHelper.java
FaultHolder.java
TimeServerHelper.java
AlarmingHolder.java
Time.java
TimeServerHolder.java
AlarmingOperations.java
TimeHelper.java
TimeServerOperations.java
AlarmingPOA.java
TimeHolder.java
TimeServerPOA.java
AlarmHelper.java
TimeOperations.java
_AlarmingStub.java
AlarmHolder.java
TimePOA.java
_AlarmStub.java
AlarmOperations.java
Timevalue.java
_TimeServerStub.java
AlarmPOA.java
TimeValueHelper.java
_TimeStub.java
Various free or shareware
ORBs CORBA implementations for various languages are
available for download on the web from various sources.
Netscape browsers used a version of VisiBroker embedded in them.
Applets can issue request on CORBA objects without downloading ORB classes into the browser. They are
already there.
15 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
16 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
The Server
If the server should be able to offer the needed objects it has to be given implementations of these objects.
This is done by implementing a class KImpl for each class K. according to:
In our example Time could be implemented as:
public class TimeImpl extends TimePOA
{
int Hour; int Minute; int Second;
public Timevalue get_time()
{
return new Timevalue(Hour,Minute,Second);
}
public class KImpl extends KPOA
On the other side a struct S { ... doesn’t have to be implemented.
That is done automatically by the idl compiler.
public void set_zone(int zone) throws Fault
{
if(No_time_zone(zone))
throw new Fault("Not a proper time zone: " + zone);
x.set_Zone(zone);
}
Also exceptions are done automatically. In our example it possible to write directly:
throw new fault("no proper timevalue!")
provided that there is an import of package TimeServer
public int get_zone()
{
return x.get_Zone();
}
}
17 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
18 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
Timeserver is implemented as:
The server should start its ORB and connect classes to it:
public class TimeServerImpl extends TimeServerPOA
{
POA poa;
import
import
import
import
public TimeServerImpl(POA poa)
{
this.poa = poa;//We need a POA to create remote obj.
}
public Time createTime()
{
TimeImpl time_impl = new TimeImpl();
org.omg.CORBA.Object TimeRef =
poa.servant_to_reference(time_impl);
return TimeHelper.narrow(TimeRef));
}
public Alarm createAlarm()
{
AlarmImpl alarm_impl = new AlarmImpl();
org.omg.CORBA.Object AlarmRef =
poa.servant_to_reference(alarm_impl);
return AlarmHelper.narrow(AlarmRef));
}}
19 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
TimeServer.*;
modellen.*;
org.omg.CORBA.ORB;
org.omg.PortableServer.*;
public class Start
{
public static void main(String[] args)
{
PrintWriter IORfil = null;
try
{
ORB orb = ORB.init(args,null); // Initialize the ORB.
POA poa =
// get rootpoa
POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
poa.the_POAManager().activate(); // activate the POAManager
// Create Timeserver object.
TimeServerImpl timeserver = new TimeServerImpl(poa);
org.omg.CORBA.Object timeserverRef =
poa.servant_to_reference(timeserver);
String iorString = orb.object_to_string(timeserverRef);
20 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
The Client
// Write stringified object reference to ior file.
PrintWriter out =
new PrintWriter(new BufferedWriter(new FileWriter(args[0])));
out.println(iorString);
out.close();
System.out.println("\nTimeServer Running!\n");
orb.run(); // wait for invocations from clients
}
catch(Exception e)
{
System.err.println("ERROR: "+e);
e.printStackTrace(System.out);
}
System.out.println("Timer Exiting ....");
}
}
The client first must log in to the server by requesting an object with interface Timeserver.
This is done using the text string written by the server in a .ior-file when the server started.
Then it will get a reference to the TimeServerImpl object that the server has created.
This reference to the object offers the interface Timeserver.
All information that is needed to reach the server is given in the ior-string.
From this object new objects can be created, there is no need for an ior-string for them.
Now the server is waiting for calls to its object timeserver which is of type TimeServerImpl and has
got the interface Timeserver.
The client then can create object with interfaces Time and Alarm from this object and then continue ...
21 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
22 (25) - DISTRIBUTED SYSTEMS
The client should at first start its ORB and log on:
import TimeServer.*;
import org.omg.CORBA.*;
public class StartClient
{
Timeserver myTimeServer;
Time myTimeObject;
Alarm myAlarm;
public static void main(String[] args)
{
try
{
ORB orb = org.omg.CORBA.ORB.init(args, null);// Init ORB.
BufferedReader in =
new BufferedReader(new FileReader(args[0]));
String ior = in.readLine();//Read in stringified reference.
in.close();
org.omg.CORBA.Object obj = orb.string_to_object(ior);
myTimeServer = TimeServerHelper.narrow(obj);
}
catch(Exception e)
{
System.err.println("Klient error: " + e.getMessage());
23 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
CORBA - Sven Arne Andreasson - Computer Science and Engineering
e.printStackTrace(System.out);
}
}
public void createTime()
{
myTimeObject = myTimeServer.createTime();
}
public void createAlarm()
{
myAlarm = myTimeServer.createAlarm();
}
public void setAlarm(Timevalue alarmTime,
AlarmingImpl returnObject)
{
try
{
myAlarm.set_alarm(alarmTime, returnObject);
}
catch(Fault e)
{
System.out.println("Unable to set alarm: " +e.reason);
}} osv }
24 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering
Running the system
Now we are ready to run the system.
At first the server is started.
Then the client that in some way gets the ior-string that was made by the server
(e.g. as an .ior-file)
Many clients can be started with the same ior-string.
If the server is restarted the clients must use the new ior-string from the server.
25 (25) - DISTRIBUTED SYSTEMS
CORBA - Sven Arne Andreasson - Computer Science and Engineering