Corba | slide # 1 |
...Orb Structure | slide # 3 |
...Orb Vendors | slide # 4 |
...Interface Definition Language | slide # 6 |
......Data Types | slide # 7 |
......Attributes and Operations | slide # 9 |
......Inheritance | slide # 12 |
......Name Scopes | slide # 12 |
...A Simple Example | slide # 13 |
...The Tie Mechanism | slide # 21 |
...The CORBA Module | slide # 27 |
......Object | slide # 27 |
......ORB | slide # 28 |
......BOA | slide # 28 |
...CORBA Services | slide # 29 |
Client/Server Programming with Java and CORBA, Orfali and Harkey, John Wiley & Sons, Inc., 1997
Java Programming with CORBA, Vogel and Duddy, John Wiley & Sons, Inc., 1997
Note much of the material in this lecture follows very closely the material from the two texts listed above.
Server - the role of providing an implementation of a object that a client uses
Client and server roles can be found in the same program
Dynamic Invocation Interface (DII) A way to call remote methods with out IDL stubs.
IDL Stubs/Skeleton - client/server code generated to allow static invocation of remote object methods
ORB Interface - Offers various services to clients and servers
Object Adapter - Adapter interfaces for different
implementations of ORB Core. The Basic Object Adapter
(BOA) is currently the only adapter, but others are possible
Joe is 100% Java ORB from Sun
Joe 1.0 and NEO 1.0 used NEO ORB and Door protocols to communicate
Joe 2.0 and Neo 2.0 also support IIOP (Internet Inter-ORB Protocol)
IIOP is part of CORBA 2.0 to insure that different vender ORBs can talk to each other
Joe 1.0 can be down loaded for free at: http://www.sun.com/sunsoft/neo/joe/index.html
Orbix is the leading CORBA vender
Will be part of Netscape browsers and servers
It is available for a 30 day free trial at:
A list of Free ORBs
See http://adams.patriot.net/~tvalesky/freecorba.html for a list of free ORBs
The mapping (binding) from IDL to the language needs to be specified
Currently the bindings are specified by OMG for C, C++, Ada, Smalltalk, Cobol
The IDL to Java bindings were to be finalized March 1997
OMG is working on a Java to IDL bindings (Due end of 1997)
Several companies have systems that perform Java to IDL
bindings, this provides RMI development
Develop Java code (with some restrictions) and automatically
convert to Corba
Basic Types | |
Type | Description |
(unsigned) short | 16-bit integer |
(unsigned) long | 32-bit integer |
float | 16-bit IEEE float |
double | 32-bit IEEE float |
char | ISO Latin-1 character |
boolean | boolean type (TRUE, FALSE) |
string | variable length string |
octet | 8-bit uninterpreted type |
enum | enumerated type with named integer values |
any | can be any type |
struct struct_type_name { type1 member_name1; type2 member_name2; }; struct studentRecord { string name; float gradePoint; boolean isGraduateStudent; }
union union_type_name switch(discriminator_type) { case value1: type1 member_name1; case value2: type2 member_name2; default : type3 member_name3; }
Array - indexed list of fixed length
typedef array_type_name1 member_type1(20); typedef array_type_name2 member_type2(10)(31); typedef classList studentRecord(25);
typedef bounded_type_name sequence <memberType, 20> typedef unbounded_type_name sequence <memberType2>
exception exception_name{ type1 member_name1; type2 member_name2; };
Attribute - way to specify pair of operations to get/set a value
readonly attributes are get only
attribute type message_name; readonly attribute type message_name;
attribute long sum;
translates to (methods in an interface):
public void sum(int sum) throws CORBA.SystemException; public int sum() throws CORBA.SystemException;
interface TheaterBooking { enum seating_section {floor, gallery, balcony, noseBleed}; struct date { short day; short month; }; exception no_seats { sequence <seating_section> seats_still_available_in; }; exception no_performance { }; typedef short reservation_code; reservation_code make_booking( in date performance, in seating_section position, out float price) raises (no_performance, no_seats) context( ROW_PREF ); };
raises - list exceptions
context - a list of string names, which if exist on client end are sent
to the server
in parameters must be sent from client to server
If the parameter is an object, it and all its data members must be sent
Solution is to wrap the parameters in an object
The wrapper objects are passed back and forth
But the IDL only defines the interface, so this maps to Java interfaces
interface TheaterService : TheaterBooking { readonly attribute date next_performance; short number_free( in date performace, in seating_section position) raises (no_perfromance) }
module Botony { interface Leaf { readonly attribute float size; void grow( in float amoutOfSun); } module SearchTree { interface Leaf { attribute any value; }
::SearchTree::Leaf ::Botony::Leaf
It keeps a count which can be increased and accessed
This example is from Client/Server Programming with Java and
CORBA
Step 1) Create and Compile an IDL file
// count.idl file module Counter { interface Count { attribute long sum; long increment(); }; }; Unixprompt-> idl2java -T count.idl -no_comments Creating: Counter Creating: Counter/Count.java Creating: Counter/Count_var.java Creating: Counter/_st_Count.java Creating: Counter/_sk_Count.java Creating: Counter/CountOperations.java Creating: Counter/_tie_Count.java Creating: Counter/_example_Count.java
package Counter; public interface Count extends CORBA.Object { public void sum(int sum) throws CORBA.SystemException; public int sum() throws CORBA.SystemException; public int increment() throws CORBA.SystemException; }
package Counter; public class _st_Count extends pomoco.CORBA.Stub implements Counter.Count { public _st_Count() { } public String[] _getRepIds() { return _repIds; } static { pomoco.CORBA.Global.addMapping( "IDL:Counter/Count:1.0", "Counter::Count", new Counter._st_Count().getClass() ); } public static String[] _repIds = { "IDL:Counter/Count:1.0" }; public int increment() throws CORBA.SystemException { CORBA.IOStream _stream = this._create_request("increment", true); _invoke(_stream, true); int _result; _result = _stream.read_int(); return _result; } public void sum(int sum) throws CORBA.SystemException { CORBA.IOStream _stream = this._create_request("_set_sum", true); _stream.write_int(sum); _invoke(_stream, true); } public int sum() throws CORBA.SystemException { CORBA.IOStream _stream = this._create_request("_get_sum", true); _invoke(_stream, true); int _result; _result = _stream.read_int(); return _result; } }
package Counter; public class _example_Count extends Counter._sk_Count { public _example_Count(java.lang.String name) { super(name); } public _example_Count() { super(); } public int increment() throws CORBA.SystemException { // implement operation... } public void sum(int sum) throws CORBA.SystemException { // implement attribute writer... } public int sum() throws CORBA.SystemException { // implement attribute reader... } }
package Counter; // CountImpl.java: The Count Implementation class CountImpl extends Counter._sk_Count implements Counter.Count { private int sum; // Constructor CountImpl(String name) { super(name); System.out.println("Count Object Created"); sum = 0; } // get sum public int sum() throws CORBA.SystemException { return sum; } // set sum public void sum(int val) throws CORBA.SystemException { sum = val; } // increment method public int increment() throws CORBA.SystemException { sum++; return sum; } }
package Counter; // CountServer.java: The Count Server main program class CountServer { static public void main(String[] args) { try { // Initialize the ORB. CORBA.ORB orb = CORBA.ORB.init(); // Initialize the basic object adapter (BOA). CORBA.BOA boa = orb.BOA_init(); // Create the Count object. CountImpl count = new CountImpl("My Count"); // Export to the ORB newly created object. boa.obj_is_ready(count); // Ready to service requests. boa.impl_is_ready(); } catch(CORBA.SystemException e) { System.err.println(e); } } }
package Counter; // CountClient.java Static Client, VisiBroker for Java class CountClient { public static void main(String args[]) { try { // Initialize the ORB CORBA.ORB orb = CORBA.ORB.init(); // Bind to the Count Object Count counter =Count_var.bind("My Count"); // Set sum to initial value of 0 counter.sum((int)0); System.out.println("Incrementing"); for (int i = 0 ; i < 1000 ; i++ ) { counter.increment(); } System.out.println("Sum = " + counter.sum()); } catch(CORBA.SystemException e) { System.err.println("System Exception"); System.err.println(e); } } }
a) Compile client, server, and Count classes with javac
b) Make sure the ORB is running:
UnixPrompt-> osagent &
java Counter.CountServerd) Run the client
java Counter.CountClient
package Counter; // CountImpl.java: The Count Implementation class CountImpl extends Counter._sk_Count implements Counter.Count
package Counter; public interface Count extends CORBA.Object {
The above method would require it to inherit multiple _sk_ classes
We use the CountOperations interface:
package Counter; public interface CountOperations { public int increment() throws CORBA.SystemException; public void sum(int sum) throws CORBA.SystemException; public int sum() throws CORBA.SystemException; }
package Counter; // CountImpl.java: The Count Implementation class CountImpl implements Counter.CountOperations { private int sum; // Constructor CountImpl() { System.out.println("Count Object Created"); sum = 0; } // get sum public int sum() throws CORBA.SystemException { return sum; } // set sum public void sum(int val) throws CORBA.SystemException { sum = val; } // increment method public int increment() throws CORBA.SystemException { sum++; return sum; } }
package Counter; public class _tie_Count extends Counter._sk_Count { private Counter.CountOperations _delegate; public _tie_Count(Counter.CountOperations delegate, java.lang.String name) { super(name); this._delegate = delegate; } public _tie_Count(Counter.CountOperations delegate) { this._delegate = delegate; } public int increment() throws CORBA.SystemException { return this._delegate.increment( ); } public void sum(int sum) throws CORBA.SystemException { this._delegate.sum(sum); } public int sum() throws CORBA.SystemException { return this._delegate.sum(); } }
package Counter; // CountServer.java: The Count Server main program class CountServer { static public void main(String[] args) { try { // Initialize the ORB. CORBA.ORB orb = CORBA.ORB.init(); // Initialize the BOA. CORBA.BOA boa = orb.BOA_init(); // Create the Count object. CountImpl count = new CountImpl(); // Create the tie object _tie_Count count_Pseudo_Impl = new _tie_Count("My Count"); // Export to the ORB newly created object. boa.obj_is_ready(count_Pseudo_Impl); // Ready to service requests. boa.impl_is_ready(); } catch(CORBA.SystemException e) { System.err.println(e); } } }
package Counter; // CountClient.java Static Client, VisiBroker for Java class CountClient { public static void main(String args[]) { try { // Initialize the ORB CORBA.ORB orb = CORBA.ORB.init(); // Bind to the Count Object Count counter =Count_var.bind("My Count"); // Set sum to initial value of 0 counter.sum((int)0); System.out.println("Incrementing"); for (int i = 0 ; i < 1000 ; i++ ) { counter.increment(); } System.out.println("Sum = " + counter.sum()); } catch(CORBA.SystemException e) { System.err.println("System Exception"); System.err.println(e); } } }
package Counter; public class Count_var { public Counter.Count value; public static Counter.Count narrow(CORBA.Object object) throws CORBA.SystemException { if(object == null) { return null; } return (Counter.Count) object._toType(Counter._st_Count._repIds[0]); } public static Counter.Count bind() throws CORBA.SystemException { return (Counter.Count) pomoco.CORBA.ORB.instance().locate(Counter._st_Count._repIds[0], null, null, null); } public static Counter.Count bind(String name) throws CORBA.SystemException { return (Counter.Count) pomoco.CORBA.ORB.instance().locate(Counter._st_Count._repIds[0], name, null, null); } public static Counter.Count bind(String name, java.lang.String host) throws CORBA.SystemException { return (Counter.Count) pomoco.CORBA.ORB.instance().locate(Counter._st_Count._repIds[0], name, host, null); } public static Counter.Count bind(java.lang.String name, java.lang.String host, CORBA.BindOptions options) throws CORBA.SystemException { return (Counter.Count) pomoco.CORBA.ORB.instance().locate(Counter._st_Count._repIds[0], name, host, options); } public static CORBA.Any any(Counter.Count object) throws CORBA.SystemException { return new CORBA.Any().from_Object(object); } public static Counter.Count any(CORBA.Any any) throws CORBA.SystemException { return Counter.Count_var.narrow(any.to_Object()); } public static CORBA.TypeCode type() throws CORBA.SystemException { if(_type == null) { _type = CORBA.ORB.init().create_interface_tc(Counter._st_Count._repIds[0], "Count"); } return _type; } private static CORBA.TypeCode _type; }
void release();
InterfaceDef get_interface();
Startup Service