You are on page 1of 120

CORBA and Java

by

Alex Chaffee alex@jguru.com http://www.jguru.com/


Java

online resources

http://www.purpletech.com/
Java

training and consulting

Copyright 1998 Purple Technology, Inc

Abstract

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
Purple
Java

Technology
Training and Consulting

http://www.purpletech.com

Alex

Chaffee

Creator

of Gamelan Cool Java Dude

Copyright 1998 Purple Technology, Inc

Part I: CORBA Overview

Copyright 1998 Purple Technology, Inc.

What is CORBA?
Common

Object Request Broker Architecture Communication infrastructure for distributed objects Allows a heterogeneous, distributed collection of objects to collaborate transparently

Copyright 1998 Purple Technology, Inc

What is CORBA good for?


Developing

distributed applications Locating remote objects on a network Sending messages to those objects Common interface for transactions, security, etc.
CORBA

Services (more later)

Copyright 1998 Purple Technology, Inc

Why Distributed Applications?


Data

is distributed

Administrative

and ownership reasons Heterogeneous systems Shared by multiple applications Scalability

Copyright 1998 Purple Technology, Inc

Why Distributed Applications?


Computation
Scalability:

is distributed

multiprocessing Take computation to data Heterogeneous architectures


Users

are distributed

Multiple

users interacting and communicating via distributed applications

Copyright 1998 Purple Technology, Inc

Distributed Object Systems


All

entities are modeled as objects Systems support location transparency Interfaces, not implementations, define objects Good distributed object systems are open, federated systems

Copyright 1998 Purple Technology, Inc

What is the OMG?


Designers

of CORBA Consortium of 700+ companies


Not

including Microsoft
vendors

Members:
platform database software

vendors
developers

tool developers

corporate software

application vendors

Copyright 1998 Purple Technology, Inc

Its Just A Spec


Has

never been fully implemented Probably never will be Industry moves quickly and spec has to keep up
Interoperability Pass-by-value

vs. portability

Copyright 1998 Purple Technology, Inc

Basic CORBA Architecture


Client Server response ORB Object Bus ORB

request

Copyright 1998 Purple Technology, Inc

CORBA Objects
Examples
Service Client Component Business

object

CORBA
Any

objects approach universal accessibility


Language Any Host on network Any Platform

Copyright 1998 Purple Technology, Inc

CORBA Elements
1.

ORB 2. CORBA Services 3. CORBA Facilities 4. Application Objects

Copyright 1998 Purple Technology, Inc

ORB
Object

Request Broker
Bus

Object

Handles

all communication among

objects Each host (machine) has its own ORB ORBs know how to talk to each other ORB also provides basic services to client

Copyright 1998 Purple Technology, Inc

ORB Responsibilities
Find

the object implementation for the request Prepare the object implementation to receive the request Communicate the data making up the request Retrieve results of request

Copyright 1998 Purple Technology, Inc

Network of ORBs
Theres

an ORB on the server too ORB receives request

Copyright 1998 Purple Technology, Inc

IIOP
Internet

Inter-Orb Protocol Network or wire protocol Works across TCP/IP (the Internet protocol)

Copyright 1998 Purple Technology, Inc

ORB Features
Method
Static

invocations

and Dynamic Remote objects or CORBA services


High-level
Use

language bindings

your favorite language; ORB translates metadata for all objects and

Self-describing
Provides

services

Copyright 1998 Purple Technology, Inc

ORB Features
Local

or remote
API wherever target object lives

Same

Preserves

context
security and transactions

Distributed

Coexistence
Just

with legacy code

provide a wrapper object

Copyright 1998 Purple Technology, Inc

What is an ORB really?


Not

a separate process Library code that executes in-process Listens to TCP ports for connections
One

port per local object

Opens
N

TCP sockets to other objects

ports per remote machine

Copyright 1998 Purple Technology, Inc

IDL
Interface

Definition Language Defines protocol to access objects Like a contract Well-specified Language-independent

Copyright 1998 Purple Technology, Inc

IDL Example
module Calc { interface Adder { long add(in long x, in long y); } }
Defines

an object called Adder with a method called add

Copyright 1998 Purple Technology, Inc

Stubs and Skeletons


Stub
lives

on client pretends to be remote object


Skeleton
lives

on server receives requests from stub talks to true remote object delivers response to stub
Copyright 1997 Alex Chaffee

Stubs and Skeletons (Fig.)


Client Host Machine Client Object Server Host Machine Remote Object

Stub

Skeleton

ORB

IIOP

ORB

Copyright 1997 Alex Chaffee

Client vs. Server


in

CORBA, a client is a client relative to a particular object i.e. an object with a reference to a server object A client may also act as a server
If

it has an IDL and stubs and skeletons

Technically,

a CORBA server contains one or more CORBA objects

Copyright 1998 Purple Technology, Inc

Different Meanings of Server


Host

machine Program running on host machine CORBA object running inside program
has

IDL, stub, skeleton Sometimes called a Servant

Copyright 1998 Purple Technology, Inc

Stubs and Skeletons -> Platform Independence


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
APIs

for low-level, common tasks Life Cycle Service


creating,

copying, moving, removing

objects
Naming

Service

Register

objects with a name Look up objects by name

Copyright 1998 Purple Technology, Inc

CORBA Services
Concurrency
Obtain

Control Service

and release exclusive locks

Transaction
Two-phase

Service

commit coordination Supports nested transactions


Persistence
Storing

Service

objects in a variety of databases RDBMS, OODBMS, file systems

Copyright 1998 Purple Technology, Inc

CORBA Services
Security
Event

Service
ACLs, encryption, etc.

Authentication,

Service
notifications

Uncoupled

Copyright 1998 Purple Technology, Inc

CORBA Services
Relationship
Externalization

Query Licensing Properties


Time Trader
Collection

and so on

See

what I mean about it never being Copyright 1998 Purple Technology, Inc implemented?

CORBA Facilities
Frameworks

for specialized applications Distributed Document Component Facility


OpenDoc

In

progress:

Agents Business

Objects Internationalization

Copyright 1998 Purple Technology, Inc

N-Tier Design with CORBA


Storage Tier
ORB

DB
ORB ORB ORB

DB
ORB
Data Object

ORB

TP Monitor
ORB ORB

ORB

Client Tier

Business Object Tier


(after diagram in Orfali et al.)

Service Tier

Copyright 1998 Purple Technology, Inc

Three Tiers
User

Interface Tier Business Logic Tier Data Storage Tier 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


The

Java 2 ORB VisiBroker for Java OrbixWeb Netscape Communicator Various free or shareware ORBs

Copyright 1998 Purple Technology, Inc

Java IDL
Should
More

be named Java CORBA

than just IDL Full (?) implementation of CORBA in 100% Java


Three
ORB Naming

Parts

Service idltojava compiler


Ships

with JDK 1.2

Copyright 1998 Purple Technology, Inc

Transparent API
JavaIDL

turns IDL into direct method

calls Easy to program Clients have no knowledge of implementation Highly portable

Copyright 1998 Purple Technology, Inc

The Java ORB


100%

Java Generic Allows Java IDL applications to run either as stand-alone Java applications, or as applets within Java-enabled browsers Uses IIOP

Copyright 1998 Purple Technology, Inc

Other Java ORBs


Visigenic

(Inprise) VisiBroker

Netscape

Communicator Oracle Web Server 3.0 Free download


Iona

OrbixWeb

Copyright 1998 Purple Technology, Inc

IDL to Java Mapping


Defined

by OMG Translates IDL concepts into Java language constructs 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 long long / unsigned long 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
interface operation attribute

Java package

C++ namespace

interface abstract class method pair of methods member function pair of functions

Copyright 1998 Purple Technology, Inc

IDL Modules
Map

to Java packages Unfortunately, it has the root level name of the module Clutters up your package hierarchy e.g. module Calc ->
package

Calc interface Calc.Adder not package ORG.omg.CORBA.modules.Calc 1998 Purple Technology, Inc Copyright

IDL Interfaces
Map

to Java interfaces

Copyright 1998 Purple Technology, Inc

IDL Operations
Map

to Java methods

Copyright 1998 Purple Technology, Inc

IDL Attributes
Map
IDL
string

to pair of functions
name;

Java
public

void name(String val); public String name();


Yes,

it looks stupid. Sorry.

Copyright 1998 Purple Technology, Inc

idltojava
Development

tool Automatically generates java stubs, skeletons, helpers, holders, ... Generates stubs for specific remote interfaces

Copyright 1998 Purple Technology, Inc

Stubs
Java

objects call stub methods Stubs communicate with CORBA objects


and

vice versa

Transparent

integration

Copyright 1998 Purple Technology, Inc

Skeletons
ORB

passes request to skeleton (like a

stub) Skeleton calls local implementation

Copyright 1998 Purple Technology, Inc

Remote Interfaces and Stubs


IDL Interface

implements

implements
extends

Client

Stub

Skeleton

Remote Object (Server)

Copyright 1997 Alex Chaffee

Show Me The Source Code


OK,

here it comes...

Copyright 1998 Purple Technology, Inc

idltojava input
Calc.idl

module Calc { interface Adder { long add(in long x, in long y); } }

Copyright 1998 Purple Technology, Inc

idltojava output
idltojava

Calc.idl

Adder.java (a Java interface that maps the IDL interface)

_AdderStub.java (a client stub)


_AdderImplBase.java (a server skeleton)

AdderHelper.java (a helper class)


AdderHolder.java (a holder class)

Must

compile these files and put them in your CLASSPATH Copyright 1998 Purple Technology, Inc

Adder.java
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
Extend

base class
all methods declared in IDL

Implement

Provide
Create

a main method

an ORB instance Create a server instance Inform the ORB about the instance Acquire a Naming Context Register the instance in that Naming Context under some name Copyright 1998 Purple Technology, Inc

AdderServer.java
class AdderServer extends _AdderImplBase { public int add( int x, int y ) { System.out.println(x + " + " + y + " = " + (x+y)); return x + y; }

Copyright 1998 Purple Technology, Inc

AdderServer.java (cont.)
public static void main(String args[]) { // create and initialize the ORB ORB orb = ORB.init(args, null); // create server and register it with the ORB AdderServer adderRef = new AdderServer(); orb.connect(adderRef);

Copyright 1998 Purple Technology, Inc

AdderServer.java (cont.)
// get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameSer vice"); NamingContext ncRef = NamingContextHelper.narrow(objRef); // bind the Object Reference in Naming NameComponent nc = new NameComponent("Adder", ""); NameComponent path[] = {nc}; ncRef.rebind(path, adderRef);

Copyright 1998 Purple Technology, Inc

Implementing a client
Create

an ORB Get a reference to the Naming Context Look up the correct name in that Naming Context Receive an object reference to that object
Actually,

to its Stub

Invoke

methods on the reference

Copyright 1998 Purple Technology, Inc

AdderClient.java

Copyright 1998 Purple Technology, Inc

Object Reference
Two
1.

Meanings

An abstract concept referring to a specific object living on a specific host, attached to a specific ORB 2. A local Java reference to an object that relays messages to that object
Obtained
new

from

keyword a Factory Object the Naming Service

Copyright 1998 Purple Technology, Inc

Naming Service
tnameserv
t

is for transient

Maps

name to object reference An implementation of the CORBA Object Service (COS) name service to run the Naming Service
UNIX:

tnameserv & start /m tnameserv

Win32:

Copyright 1998 Purple Technology, Inc

Fire it up
start

/m tnameserv start java AdderServer java AdderClient 2 + 2 = ?

Copyright 1998 Purple Technology, Inc

CORBA Flow
Client Virtual Machine Client Server Virtual Machine Remote Object

Stub

Skeleton 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

Stub

Skeleton Server
2

Fred Name Server Virtual Machine


Copyright 1997 Alex Chaffee

CORBA Flow
Client Virtual Machine Client Server Virtual Machine 3. Client requests object from Name Server Remote 4. Name Server returns remote reference Object (and stub gets created) Stub
3 4

Skeleton Server

Fred Name Server Virtual Machine


Copyright 1997 Alex Chaffee

RMI Flow
Client Virtual Machine Client
5 6 7

Server Virtual Machine Remote Object

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
The

ORB is a pseudo-object It works just like a remote object, only its local

Copyright 1998 Purple Technology, Inc

The Basic Object Adapter (BOA)


Another

pseudo-object Helps register objects with the ORB Functions


Maintain

Implementation Repository Generate and interpret object references Activate and deactivate implementation objects Invoke methods via skeletons

Copyright 1998 Purple Technology, Inc

Why do you need both an ORB and a BOA?


Im

not really sure Allows vendors to optimize or enhance functionality


register

many objects en masse cache object state elsewhere


E.g.

Object database

Copyright 1998 Purple Technology, Inc

Using the BOA


Slightly

different procedure for initializing objects Hides name service from you
Ask

the BOA to register the object Ask the Helper object to bind the object
Once

the object is created, interface is identical


Just

call methods using normal Java syntax Copyright 1998 Purple Technology, Inc

BOA Object Activation


Shared

server

Multiple

objects, one server Normal procedure Multithreaded (handled by CORBA implementation)


Unshared
New

server

process for each object

Copyright 1998 Purple Technology, Inc

BOA Object Activation (cont.)


Server-per-method
Batch

processing

Persistent
Shared

server

server, but object not created by

ORB

Copyright 1998 Purple Technology, Inc

BOA Object Activation Scenario


Server
obj

creates object instance


registers object with BOA

= new MyObject();

Server

boa.create(interface_name,

implementation_name, reference_data) VisiBroker does this for you in superclass constructor

Copyright 1998 Purple Technology, Inc

BOA Object Activation Scenario (cont.)


Server
Server

tells BOA the object is ready


tells BOA that all objects are

boa.obj_is_ready(obj)

ready
boa.impl_is_ready()

Objects Server

shut down

boa.deactivate_obj(this)

shuts down

boa.deactivate_impl()

Copyright 1998 Purple Technology, Inc

Threads in JavaIDL
Remote

invocations happen on a separate thread Must make sure your remote objects are thread-safe

Copyright 1998 Purple Technology, Inc

Callbacks
Pass

in a reference to some CORBA object The server object can invoke methods on that reference ORB automatically generates a stub on the server side The server has become the client, and vice versa

Copyright 1998 Purple Technology, Inc

Obtaining Object References


From

the ORB

orb.resolve_initial_references(NameServic

e)
From

a Naming Context From a Stringified reference From another object From a parameter to your remote method

Copyright 1998 Purple Technology, Inc

Helper Objects
How

CORBA does casting narrow method changes the type of an object reference
// get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameSer vice"); NamingContext ncRef = NamingContextHelper.narrow(objRef);

Copyright 1998 Purple Technology, Inc

Naming Contexts
Directory

structure for CORBA Naming Component = file Naming Context = directory Can add a Context as a Component
like

subdirectories

Can

add a Context on a different name server


like

symbolic links

Copyright 1998 Purple Technology, Inc

Stringification
Stringified

reference is ORBindependent Object to string


org.omg.CORBA.Object obj = ... String str = orb.object_to_string(obj); String to object org.omg.CORBA.Object obj = orb.string_to_object(str);

Copyright 1998 Purple Technology, Inc

Visigenic: Caffeine
Java

to IDL compiler

Copyright 1998 Purple Technology, Inc

Symantec: Visual Caf 3.0 Enterprise Suite


Java

to IDL compiler Automatic client adapter bean generation


Makes

a JavaBean thats a proxy to a CORBA object

Distributed
Follow

debugging

call chain, examine variables, et al. Across many VMs, many hosts, many OSs

Copyright 1998 Purple Technology, Inc

Part III: Example Application

Copyright 1998 Purple Technology, Inc

Publish-Subscribe System
Channel:

an avenue for real-time data exchange Consumers can subscribe to arbitrary data channels Producers can publish data on channels
Invokes

callback method on consumer

Copyright 1998 Purple Technology, Inc

Object Model
PSServer
Channel
creates

getChannel(String channelName)
channel if it doesnt already exist

Channel
void

subscribe(Subscriber sub) void publish(Object data)


Subscriber
void

dataArrived(Object data)

Copyright 1998 Purple Technology, Inc

Flow: Subscriber-side
Client

acquires PSServer reference Client acquires channel from PSServer Client creates subscriber locally, passing reference to channel Subscriber registers self with channel
channel.subscribe(this)

Client

waits for callback to its dataArrived method

Copyright 1998 Purple Technology, Inc

Flow: Publisher-side
Client

acquires PSServer reference Client acquires channel from PSServer Client creates publisher locally, passing reference to channel Publisher acquires data
From

a database From a data feed


Publisher

calls channel.publish(data)

Copyright 1998 Purple Technology, Inc

Example Application: Stock data


Channel

name = stock symbol name Source code available

Copyright 1998 Purple Technology, Inc

Design issues
Name

space for channels

TIBCO

et al. use hierarchical directory structure

Caching

prior messages

Subscribe

should spawn a thread that sends previous N messages

Copyright 1998 Purple Technology, Inc

Design issues
Maintain
Dont

local cache of data sent

want to go back across the network every time you draw a graph Create local version of class

Copyright 1998 Purple Technology, Inc

Part IV: Advanced Topics

Copyright 1998 Purple Technology, Inc

Exceptions
CORBA

exceptions are mapped to Java exceptions System Exceptions


Theyre

subclasses of RuntimeException, so the compiler wont complain if you forget to catch them Minor codes

additional information vendor-specific :-(

Completion

Status

Copyright 1998 Purple Technology, Inc

Exceptions (cont.)
User

Exceptions

Generated

by idltojava Subclasses of Exception (declared)

Copyright 1998 Purple Technology, Inc

Dynamic Invocation Interface (DII)


CORBA

is fully self-aware Methods for acquiring


List

of all services List of known objects Interfaces of known objects Etc.


Well-documented

elsewhere

Copyright 1998 Purple Technology, Inc

Interface Repositories
JavaIDL

clients do not typically need or use an Interface Repository All of the needed type information is available in the stubs or is resolved by an object's server JavaIDL supports access to Interface Repository information made available by other CORBA object implementations. Copyright 1998 Purple Technology, Inc

Implementation Repository
contains

information that allows the ORB to locate and activate implementations of objects also store additional information associated with implementations of ORB objects.
Debugging

information Administrative control Resource allocation Security

Copyright 1998 Purple Technology, Inc

Value Objects
CORBA
Blobs Avoids

3.0

network latency of pass-byreference objects

Copyright 1998 Purple Technology, Inc

RMI over IIOP


In

Development Uses IIOP as transport protocol Uses Value Objects to pass Java serialized objects

Copyright 1998 Purple Technology, Inc

CORBA via RMI


Possible

using middleware server RMI from client to middleware IIOP from middleware to other servers Can use Servlet as middleware

Copyright 1998 Purple Technology, Inc

CORBA and EJB


Transport
EJB

uses RMI interface, RMI uses IIOP

CORBA
Not

3.0 promises object compatibility with EJB


quite sure what that means

Some
All

EJB Servers contain an ORB

EJB Objects are also CORBA objects

Copyright 1998 Purple Technology, Inc

CORBA and EJB (Cont.)


All

EJB Servers use CORBA Transactions (via JTS)


That

means that any client can make a distributed transaction that includes both CORBA and EJB Objects

Not

an either-or decision

You

can have both EJB and CORBA working together in a single system

Copyright 1998 Purple Technology, Inc

Java Transactions
Java
A

Transaction Service (JTS)

standard Java mapping of the OMG Object Transaction Service (OTS)

packages

org.omg.CosTransaction and org.omg.CosTSPortability

Java

Transaction API (JTA)

High-level package

transaction management specification javax.transaction

Copyright 1998 Purple Technology, Inc

Object Transaction Service (OTS)


Distributed
Part

transaction specification can span

of CORBA, but also standalone


queries objects

Transactions
multiple multiple

multiple
multiple multiple

servers
databases vendors products

Copyright 1998 Purple Technology, Inc

OTS Features
Distributed
Flat

transactions commit

or nested transactions interoperability (?)

Two-phase Vendor

Copyright 1998 Purple Technology, Inc

OTS Object Model


Transactional
Can

Object

participate in a transaction

Recoverable
Actually

Object

performs commit or rollback on its own data system or server that can commit or rollback data stored inside it

Resource
A

E.g.

a database server

Copyright 1998 Purple Technology, Inc

OTS Object Model (Cont.)


Current
Reference/wrapper

to currently active transaction

Control

/ Coordinator / Terminator
objects distributed commit/rollback

Registers Performs

Synchronization
An

object that gets informed of the progress of the ongoing transaction callback methods

Implements

Copyright 1998 Purple Technology, Inc

Part V: CORBA/Java Case Studies

Copyright 1998 Purple Technology, Inc.

CORBA Case Study


Kaiser

Permanente Northern California KAHUNA a/k/a WebChart http://www.javaworld.com/jw-111998/jw-11-kaiser.html?101698txt

Copyright 1998 Purple Technology, Inc

Problem: Specific
Medical

records, patient histories, clinical schedules, lab results, and medical images all stored in disparate databases
patients per doctor, many doctors per patient immediate access to all information

Many Need

Copyright 1998 Purple Technology, Inc

Problem: General
getting
from

data

a multitude of sources in a multitude of media


putting
into

data

a single system

distributing
to

data

a wide variety of desktops throughout a very large company

Copyright 1998 Purple Technology, Inc

Solution: Java/CORBA
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

WebChart 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


Orfali

& Harkey, Client/Server Programming with Java and CORBA (Wiley) Orfali, Harkey & Edwards, Instant CORBA (Wiley)

Copyright 1998 Purple Technology, Inc

More Info: Links


This

Presentation
1.2 CORBA documentation

http://www.purpletech.com/ http://java.sun.com/products/jdk/1.2/docs/guide/idl/

JDK

Glerum,

WebChart serves up Kaiser patients, JavaWorld


http://www.javaworld.com/jw-11-1998/jw-11kaiser.html?101698txt

Copyright 1998 Purple Technology, Inc

More Info: Links


Object

Management Group - http://www.omg.org Java Transactions


http://java.sun.com/products/jta/ http://java.sun.com/products/jts/ ftp://www.omg.org/pub/docs/formal/97-12-17.pdf

Copyright 1998 Purple Technology, Inc

You might also like