CORBA and Java u by Alex Chaffee u
CORBA and Java u by Alex Chaffee u alex@jguru. com u http: //www. jguru. com/ u Java online resources u http: //www. purpletech. com/ u Java training and consulting Copyright © 1998 Purple Technology, Inc
Abstract u CORBA loves Java! CORBA provides a platform-independent, language-independent way to write applications that can invoke objects that live across the room or across the planet. Java is an object-oriented language that's ideal for writing the clients and servers living on the Object Bus. In this session, we examine the ways they interoperate programmatically, as we walk you stepby-step from a CORBA IDL, to a server and client both written in Java, running on top of a 100%-Java ORB. We also discuss the relationship between CORBA and RMI, and discuss some of the real-world issues involved in deploying a CORBA-based application. Recommended: some knowledge of CORBA, ability to read Java source code. Copyright © 1998 Purple Technology, Inc
Introduction u Purple Technology u http: //www. purpletech. com u Java u Alex Training and Consulting Chaffee u Creator of Gamelan u Cool Java Dude Copyright © 1998 Purple Technology, Inc
Part I: CORBA Overview Copyright © 1998 Purple Technology, Inc.
What is CORBA? u Common Object Request Broker Architecture u Communication infrastructure for distributed objects u Allows a heterogeneous, distributed collection of objects to collaborate transparently Copyright © 1998 Purple Technology, Inc
What is CORBA good for? u Developing distributed applications u Locating remote objects on a network u Sending messages to those objects u Common interface for transactions, security, etc. u CORBA Services (more later) Copyright © 1998 Purple Technology, Inc
Why Distributed Applications? u Data is distributed u Administrative and ownership reasons u Heterogeneous systems u Shared by multiple applications u Scalability Copyright © 1998 Purple Technology, Inc
Why Distributed Applications? u Computation is distributed u Scalability: multiprocessing u Take computation to data u Heterogeneous architectures u Users are distributed u Multiple users interacting and communicating via distributed applications Copyright © 1998 Purple Technology, Inc
Distributed Object Systems u All entities are modeled as objects u Systems support location transparency u Interfaces, not implementations, define objects u Good distributed object systems are open, federated systems Copyright © 1998 Purple Technology, Inc
What is the OMG? u Designers of CORBA u Consortium of 700+ companies u Not including Microsoft u Members: u platform vendors u database u software tool developers u corporate u software vendors developers application vendors Copyright © 1998 Purple Technology, Inc
It’s Just A Spec u Has never been fully implemented u Probably never will be u Industry moves quickly and spec has to keep up u Interoperability vs. portability u Pass-by-value Copyright © 1998 Purple Technology, Inc
Basic CORBA Architecture Server Client response request ORB “Object Bus” Copyright © 1998 Purple Technology, Inc
CORBA Objects u Examples u Service u Client u Component u Business object u CORBA objects approach universal accessibility u Any Language u Any Host on network u Any Platform Copyright © 1998 Purple Technology, Inc
CORBA Elements u 1. ORB u 2. CORBA Services u 3. CORBA Facilities u 4. Application Objects Copyright © 1998 Purple Technology, Inc
ORB u Object Request Broker u “Object u Handles Bus” all communication among objects u Each host (machine) has its own ORB u ORBs know how to talk to each other u ORB also provides basic services to client Copyright © 1998 Purple Technology, Inc
ORB Responsibilities u Find the object implementation for the request u Prepare the object implementation to receive the request u Communicate the data making up the request u Retrieve results of request Copyright © 1998 Purple Technology, Inc
Network of ORBs u There’s an ORB on the server too u ORB receives request Copyright © 1998 Purple Technology, Inc
IIOP u Internet Inter-Orb Protocol u Network or “wire” protocol u Works across TCP/IP (the Internet protocol) Copyright © 1998 Purple Technology, Inc
ORB Features u Method invocations u Static and Dynamic u Remote objects or CORBA services u High-level language bindings u Use your favorite language; ORB translates u Self-describing u Provides services metadata for all objects and Copyright © 1998 Purple Technology, Inc
ORB Features u Local or remote u Same API wherever target object lives u Preserves context u Distributed security and transactions u Coexistence u Just with legacy code provide a wrapper object Copyright © 1998 Purple Technology, Inc
What is an ORB really? u Not a separate process u Library code that executes in-process u Listens to TCP ports for connections u One port per local object u Opens u. N TCP sockets to other objects ports per remote machine Copyright © 1998 Purple Technology, Inc
IDL u Interface Definition Language u Defines protocol to access objects u Like a contract u Well-specified u Language-independent Copyright © 1998 Purple Technology, Inc
IDL Example module Calc { interface Adder { long add(in long x, in long y); } } u Defines an object called Adder with a method called add Copyright © 1998 Purple Technology, Inc
Stubs and Skeletons u Stub u lives on client u pretends to be remote object u Skeleton u lives on server u receives requests from stub u talks to true remote object u delivers response to stub Copyright © 1997 Alex Chaffee
Stubs and Skeletons (Fig. ) Client Host Machine Server Host Machine Client Object Remote Object Stub Skeleton ORB IIOP ORB Copyright © 1997 Alex Chaffee
Client vs. Server u in CORBA, a client is a client relative to a particular object u i. e. an object with a reference to a “server” object u A client may also act as a server u If it has an IDL and stubs and skeletons u Technically, a CORBA server contains one or more CORBA objects Copyright © 1998 Purple Technology, Inc
Different Meanings of “Server” u Host machine u Program running on host machine u CORBA object running inside program u has IDL, stub, skeleton u Sometimes called a Servant Copyright © 1998 Purple Technology, Inc
Stubs and Skeletons -> Platform Independence u Client code has no knowledge of the implementation of the object or which ORB is used to access the implementation. Copyright © 1998 Purple Technology, Inc
CORBA Services u APIs for low-level, common tasks u Life Cycle Service u creating, copying, moving, removing objects u Naming Service u Register objects with a name u Look up objects by name Copyright © 1998 Purple Technology, Inc
CORBA Services u Concurrency u Obtain Control Service and release exclusive locks u Transaction Service u Two-phase commit coordination u Supports nested transactions u Persistence Service u Storing objects in a variety of databases u RDBMS, OODBMS, file systems Copyright © 1998 Purple Technology, Inc
CORBA Services u Security Service u Authentication, u Event ACLs, encryption, etc. Service u Uncoupled notifications Copyright © 1998 Purple Technology, Inc
CORBA Services u Relationship u Externalization u u u Query Licensing Properties u Time Trader u Collection u … and so on… u u See what I mean about it never being Copyright © 1998 Purple Technology, Inc implemented?
CORBA Facilities u Frameworks for specialized applications u Distributed Document Component Facility u Open. Doc u In progress: u Agents u Business Objects u Internationalization Copyright © 1998 Purple Technology, Inc
N-Tier Design with CORBA Storage “Tier” ORB DB ORB ORB DB Data Object ORB ORB Client Tier TP Monitor ORB Business Object Tier (after diagram in Orfali et al. ) Service “Tier” Copyright © 1998 Purple Technology, Inc
Three Tiers u User Interface Tier u Business Logic Tier u Data Storage Tier u Can use CORBA objects in each tier Copyright © 1998 Purple Technology, Inc
Part II: Java IDL - Using CORBA from Java Copyright © 1998 Purple Technology, Inc.
Java CORBA Products u The Java 2 ORB u Visi. Broker for Java u Orbix. Web u Netscape Communicator u Various free or shareware ORBs Copyright © 1998 Purple Technology, Inc
Java IDL u Should be named “Java CORBA” u More than just IDL u Full (? ) implementation of CORBA in 100% Java u Three Parts u ORB u Naming Service u idltojava compiler u Ships with JDK 1. 2 Copyright © 1998 Purple Technology, Inc
Transparent API u Java. IDL turns IDL into direct method calls u Easy to program u Clients have no knowledge of implementation u Highly portable Copyright © 1998 Purple Technology, Inc
The Java ORB u 100% Java u Generic u Allows Java IDL applications to run either as stand-alone Java applications, or as applets within Java-enabled browsers u Uses IIOP Copyright © 1998 Purple Technology, Inc
Other Java ORBs u Visigenic (Inprise) Visi. Broker u Netscape Communicator u Oracle Web Server 3. 0 u Free download u Iona Orbix. Web Copyright © 1998 Purple Technology, Inc
IDL to Java Mapping u Defined by OMG u Translates IDL concepts into Java language constructs u Everything is accessible by writing normal-looking Java code Copyright © 1998 Purple Technology, Inc
IDL to Java Type Mapping IDL Type boolean char / wchar octet short / unsigned short long / unsigned long float double string / wstring Java Type boolean char byte short int long float double String Copyright © 1998 Purple Technology, Inc
IDL vs. Java vs. C++ concepts IDL module Java package C++ namespace interface abstract class operation method member function attribute pair of methods pair of functions Copyright © 1998 Purple Technology, Inc
IDL Modules u Map to Java packages u Unfortunately, it has the root level name of the module u Clutters up your package hierarchy u e. g. module Calc -> u package Calc u interface Calc. Adder u not package ORG. omg. CORBA. modules. Calc Copyright © 1998 Purple Technology, Inc
IDL Interfaces u Map to Java interfaces Copyright © 1998 Purple Technology, Inc
IDL Operations u Map to Java methods Copyright © 1998 Purple Technology, Inc
IDL Attributes u Map to pair of functions u IDL u string name; u Java u public void name(String val); u public String name(); u Yes, it looks stupid. Sorry. Copyright © 1998 Purple Technology, Inc
idltojava u Development tool u Automatically generates java stubs, skeletons, helpers, holders, . . . u Generates stubs for specific remote interfaces Copyright © 1998 Purple Technology, Inc
Stubs u Java objects call stub methods u Stubs communicate with CORBA objects u and vice versa u Transparent integration Copyright © 1998 Purple Technology, Inc
Skeletons u ORB passes request to skeleton (like a stub) u Skeleton calls local implementation Copyright © 1998 Purple Technology, Inc
Remote Interfaces and Stubs IDL Interface implements extends Client Stub Skeleton Remote Object (Server) Copyright © 1997 Alex Chaffee
Show Me The Source Code u OK, here it comes. . . Copyright © 1998 Purple Technology, Inc
idltojava input u Calc. idl module Calc { interface Adder { long add(in long x, in long y); } } Copyright © 1998 Purple Technology, Inc
idltojava output u idltojava Calc. idl · Adder. java (a Java interface that maps the IDL interface) · _Adder. Stub. java (a client stub) · _Adder. Impl. Base. java (a server skeleton) · Adder. Helper. java (a helper class) · Adder. Holder. java (a holder class) u Must compile these files and put them in your CLASSPATH Copyright © 1998 Purple Technology, Inc
Adder. java u Created for you by idltojava package Calc; public interface Adder extends org. omg. CORBA. Object { int add(int x, int y); } Copyright © 1998 Purple Technology, Inc
Implementing a server u Extend base class u Implement u Provide u Create all methods declared in IDL a main method an ORB instance u Create a server instance u Inform the ORB about the instance u Acquire a Naming Context u Register the instance in that Naming Context under some name Copyright © 1998 Purple Technology, Inc
Adder. Server. java class Adder. Server extends _Adder. Impl. Base { public int add( int x, int y ) { System. out. println(x + " + y + " = " + (x+y)); return x + y; } Copyright © 1998 Purple Technology, Inc
Adder. Server. java (cont. ) public static void main(String args[]) { // create and initialize the ORB orb = ORB. init(args, null); // create server and register it with the ORB Adder. Server adder. Ref = new Adder. Server(); orb. connect(adder. Ref); Copyright © 1998 Purple Technology, Inc
Adder. Server. java (cont. ) // get the root naming context org. omg. CORBA. Object obj. Ref = orb. resolve_initial_references("Name. Ser vice"); Naming. Context nc. Ref = Naming. Context. Helper. narrow(obj. Ref); // bind the Object Reference in Naming Name. Component nc = new Name. Component("Adder", ""); Name. Component path[] = {nc}; nc. Ref. rebind(path, adder. Ref); } Copyright © 1998 Purple Technology, Inc
Implementing a client u Create an ORB u Get a reference to the Naming Context u Look up the correct name in that Naming Context u Receive an object reference to that object u Actually, u Invoke to its Stub methods on the reference Copyright © 1998 Purple Technology, Inc
Adder. Client. java Copyright © 1998 Purple Technology, Inc
Object Reference u Two Meanings u 1. An abstract concept referring to a specific object living on a specific host, attached to a specific ORB u 2. A local Java reference to an object that relays messages to that object u Obtained from u new keyword u a Factory Object u the Naming Service Copyright © 1998 Purple Technology, Inc
Naming Service u tnameserv ut is for “transient” u Maps name to object reference u An implementation of the CORBA Object Service (COS) name service u to run the Naming Service u UNIX: tnameserv & u Win 32: start /m tnameserv Copyright © 1998 Purple Technology, Inc
Fire it up u start /m tnameserv u start java Adder. Server u java Adder. Client u 2 + 2 = ? Copyright © 1998 Purple Technology, Inc
CORBA Flow Client Virtual Machine Server Virtual Machine Client Remote Object Skeleton Stub Server “Fred” Name Server Virtual Machine Copyright © 1997 Alex Chaffee
CORBA Flow 1. Server Creates Remote Object Client Virtual Machine 2. Server Registers Remote Object Client Server Virtual Machine Remote Object 1 Skeleton Stub Server 2 “Fred” Name Server Virtual Machine Copyright © 1997 Alex Chaffee
CORBA Flow Client Virtual Machine 3. Client requests object from. Remote Name Server 4. Name Server returns remote reference Object (and stub gets created) Client Skeleton Stub 3 Server Virtual Machine Server 4 “Fred” Name Server Virtual Machine Copyright © 1997 Alex Chaffee
RMI Flow Client Virtual Machine Server Virtual Machine Client Remote Object 5 7 6 Stub Skeleton Server 5. Client invokes stub method 6. Stub talks to skeleton 7. Skeleton invokes remote object “Fred” method Name Server Virtual Machine Copyright © 1997 Alex Chaffee
Pseudo-objects u The ORB is a pseudo-object u It works just like a remote object, only it’s local Copyright © 1998 Purple Technology, Inc
The Basic Object Adapter (BOA) u Another pseudo-object u Helps register objects with the ORB u Functions u Maintain Implementation Repository u Generate and interpret object references u Activate and deactivate implementation objects u Invoke methods via skeletons Copyright © 1998 Purple Technology, Inc
Why do you need both an ORB and a BOA? u I’m not really sure u Allows vendors to optimize or enhance functionality u register many objects en masse u cache object state elsewhere u E. g. Object database Copyright © 1998 Purple Technology, Inc
Using the BOA u Slightly different procedure for initializing objects u Hides name service from you u Ask the BOA to register the object u Ask the Helper object to bind the object u Once the object is created, interface is identical u Just call methods using normal Java syntax Copyright © 1998 Purple Technology, Inc
BOA Object Activation u Shared server u Multiple objects, one server u Normal procedure u Multithreaded (handled by CORBA implementation) u Unshared u New server process for each object Copyright © 1998 Purple Technology, Inc
BOA Object Activation (cont. ) u Server-per-method u Batch processing u Persistent u Shared server, but object not created by ORB Copyright © 1998 Purple Technology, Inc
BOA Object Activation Scenario u Server u obj creates object instance = new My. Object(); u Server registers object with BOA u boa. create(interface_name, implementation_name, reference_data) u Visi. Broker does this for you in superclass constructor Copyright © 1998 Purple Technology, Inc
BOA Object Activation Scenario (cont. ) u Server tells BOA the object is ready u boa. obj_is_ready(obj) u Server tells BOA that all objects are ready u boa. impl_is_ready() u Objects shut down u boa. deactivate_obj(this) u Server shuts down u boa. deactivate_impl() Copyright © 1998 Purple Technology, Inc
Threads in Java. IDL u Remote invocations happen on a separate thread u Must make sure your remote objects are thread-safe Copyright © 1998 Purple Technology, Inc
Callbacks u Pass in a reference to some CORBA object u The server object can invoke methods on that reference u ORB automatically generates a stub on the server side u The server has become the client, and vice versa Copyright © 1998 Purple Technology, Inc
Obtaining Object References u From the ORB u orb. resolve_initial_references(“Name. Servi ce”) u From a Naming Context u From a Stringified reference u From another object u From a parameter to your remote method Copyright © 1998 Purple Technology, Inc
Helper Objects u How CORBA does casting u narrow method changes the type of an object reference // get the root naming context org. omg. CORBA. Object obj. Ref = orb. resolve_initial_references("Name. Ser vice"); Naming. Context nc. Ref = Naming. Context. Helper. narrow(obj. Ref); Copyright © 1998 Purple Technology, Inc
Naming Contexts u Directory structure for CORBA u Naming Component = file u Naming Context = directory u Can add a Context as a Component u like subdirectories u Can add a Context on a different name server u like symbolic links Copyright © 1998 Purple Technology, Inc
Stringification u Stringified reference is ORBindependent u Object to string org. omg. CORBA. Object obj =. . . String str = orb. object_to_string(obj); u String to object u org. omg. CORBA. Object obj = orb. string_to_object(str); Copyright © 1998 Purple Technology, Inc
Visigenic: Caffeine u Java to IDL compiler Copyright © 1998 Purple Technology, Inc
Symantec: Visual Café 3. 0 Enterprise Suite u Java to IDL compiler u Automatic client adapter bean generation u Makes a Java. Bean that’s a proxy to a CORBA object u Distributed debugging u Follow call chain, examine variables, et al. u Across many VMs, many hosts, many OSs Copyright © 1998 Purple Technology, Inc
Part III: Example Application Copyright © 1998 Purple Technology, Inc
Publish-Subscribe System u Channel: an avenue for real-time data exchange u Consumers can subscribe to arbitrary data channels u Producers can publish data on channels u Invokes callback method on consumer Copyright © 1998 Purple Technology, Inc
Object Model u PSServer u Channel u creates get. Channel(String channel. Name) channel if it doesn’t already exist u Channel u void subscribe(Subscriber sub) u void publish(Object data) u Subscriber u void data. Arrived(Object data) Copyright © 1998 Purple Technology, Inc
Flow: Subscriber-side u Client acquires PSServer reference u Client acquires channel from PSServer u Client creates subscriber locally, passing reference to channel u Subscriber registers self with channel u channel. subscribe(this) u Client waits for callback to its data. Arrived method Copyright © 1998 Purple Technology, Inc
Flow: Publisher-side u Client acquires PSServer reference u Client acquires channel from PSServer u Client creates publisher locally, passing reference to channel u Publisher acquires data u From a database u From a data feed u Publisher calls channel. publish(data) Copyright © 1998 Purple Technology, Inc
Example Application: Stock data u Channel name = stock symbol name u Source code available Copyright © 1998 Purple Technology, Inc
Design issues u Name space for channels u TIBCO et al. use hierarchical directory structure u Caching prior messages u Subscribe should spawn a thread that sends previous N messages Copyright © 1998 Purple Technology, Inc
Design issues u Maintain local cache of data sent u Don’t want to go back across the network every time you draw a graph u Create local version of class Copyright © 1998 Purple Technology, Inc
Part IV: Advanced Topics Copyright © 1998 Purple Technology, Inc
Exceptions u CORBA exceptions are mapped to Java exceptions u System Exceptions u They’re subclasses of Runtime. Exception, so the compiler won’t complain if you forget to catch them u Minor codes u additional information u vendor-specific : -( u Completion Status Copyright © 1998 Purple Technology, Inc
Exceptions (cont. ) u User Exceptions u Generated by idltojava u Subclasses of Exception (declared) Copyright © 1998 Purple Technology, Inc
Dynamic Invocation Interface (DII) u CORBA is fully self-aware u Methods for acquiring u List of all services u List of known objects u Interfaces of known objects u Etc. u Well-documented elsewhere Copyright © 1998 Purple Technology, Inc
Interface Repositories u Java. IDL clients do not typically need or use an Interface Repository u All of the needed type information is available in the stubs or is resolved by an object's server u Java. IDL supports access to Interface Repository information made available by other CORBA object implementations. Copyright © 1998 Purple Technology, Inc
Implementation Repository u contains information that allows the ORB to locate and activate implementations of objects u also store additional information associated with implementations of ORB objects. u Debugging information u Administrative control u Resource allocation u Security Copyright © 1998 Purple Technology, Inc
Value Objects u CORBA 3. 0 u Blobs u Avoids network latency of pass-byreference objects Copyright © 1998 Purple Technology, Inc
RMI over IIOP u In Development u Uses IIOP as transport protocol u Uses Value Objects to pass Java serialized objects Copyright © 1998 Purple Technology, Inc
CORBA via RMI u Possible using middleware server u RMI from client to middleware u IIOP from middleware to other servers u Can use Servlet as middleware Copyright © 1998 Purple Technology, Inc
CORBA and EJB u Transport u EJB uses RMI interface, RMI uses IIOP u CORBA 3. 0 promises object compatibility with EJB u Not quite sure what that means u Some u All EJB Servers contain an ORB EJB Objects are also CORBA objects Copyright © 1998 Purple Technology, Inc
CORBA and EJB (Cont. ) u All EJB Servers use CORBA Transactions (via JTS) u That means that any client can make a distributed transaction that includes both CORBA and EJB Objects u Not an either-or decision u You can have both EJB and CORBA working together in a single system Copyright © 1998 Purple Technology, Inc
Java Transactions u Java Transaction Service (JTS) u. A standard Java mapping of the OMG Object Transaction Service (OTS) u packages org. omg. Cos. Transaction and org. omg. Cos. TSPortability u Java Transaction API (JTA) u High-level transaction management specification u package javax. transaction Copyright © 1998 Purple Technology, Inc
Object Transaction Service (OTS) u Distributed u Part transaction specification of CORBA, but also standalone u Transactions can span u multiple queries u multiple objects u multiple servers u multiple databases u multiple vendors’ products Copyright © 1998 Purple Technology, Inc
OTS Features u Distributed u Flat transactions or nested transactions u Two-phase u Vendor commit interoperability (? ) Copyright © 1998 Purple Technology, Inc
OTS Object Model u Transactional u Can Object participate in a transaction u Recoverable Object u Actually performs commit or rollback on its own data u Resource u. A system or server that can commit or rollback data stored inside it u E. g. a database server Copyright © 1998 Purple Technology, Inc
OTS Object Model (Cont. ) u Current u Reference/wrapper u Control to currently active transaction / Coordinator / Terminator u Registers objects u Performs distributed commit/rollback u Synchronization u An object that gets informed of the progress of the ongoing transaction u Implements callback methods Copyright © 1998 Purple Technology, Inc
Part V: CORBA/Java Case Studies Copyright © 1998 Purple Technology, Inc.
CORBA Case Study u Kaiser Permanente Northern California u KAHUNA a/k/a Web. Chart u http: //www. javaworld. com/jw-11 -1998/jw -11 -kaiser. html? 101698 txt Copyright © 1998 Purple Technology, Inc
Problem: Specific u Medical records, patient histories, clinical schedules, lab results, and medical images all stored in disparate databases u Many patients per doctor, many doctors per patient u Need immediate access to all information Copyright © 1998 Purple Technology, Inc
Problem: General u getting data u from a multitude of sources u in a multitude of media u putting u into data a single system u distributing data u to a wide variety of desktops u throughout a very large company Copyright © 1998 Purple Technology, Inc
Solution: Java/CORBA u “Not only did Java/CORBA solve all these problems, but Java/CORBA development is cheap, fast, scalable and works over the Internet. ” Copyright © 1998 Purple Technology, Inc
Web. Chart Architecture Copyright © 1998 Purple Technology, Inc
This is your brain on Java. Any questions? Copyright © 1998 Purple Technology, Inc
Conclusion Copyright © 1998 Purple Technology, Inc.
Where to Get More Information u Orfali & Harkey, Client/Server Programming with Java and CORBA (Wiley) u Orfali, Harkey & Edwards, Instant CORBA (Wiley) Copyright © 1998 Purple Technology, Inc
More Info: Links u This u http: //www. purpletech. com/ u JDK u Presentation 1. 2 CORBA documentation http: //java. sun. com/products/jdk/1. 2/docs/guide/idl/ u Glerum, Web. Chart serves up Kaiser patients, Java. World u http: //www. javaworld. com/jw-11 -1998/jw-11 kaiser. html? 101698 txt Copyright © 1998 Purple Technology, Inc
More Info: Links u Object Management Group - http: //www. omg. org u Java Transactions http: //java. sun. com/products/jta/ u http: //java. sun. com/products/jts/ u ftp: //www. omg. org/pub/docs/formal/97 -12 -17. pdf u Copyright © 1998 Purple Technology, Inc
- Slides: 120