Title: CS4812
1CS4812
- CORBA vs. RMI
- Whose Kung Fu
- Is Better?
Being a Comparison of Javas CORBA and RMI Capab
ilities
21.
Motivation
3CORBA RMITwo Flavors of Alphabet Soup?
Maybe youve heard of CORBA and/or RMI
the new hot thing in computing.
GUI
CORBA
(UDP)
HTML
Foo
HORB
OMG IDL
(TCP/IP)
Thin Clients
(CGI)
URL
Null Clients
(Non-type-safe Interaction)
Java ORB
Its hard to understand CORBA and RMI,
in part because of all the confusing terms...
4What is CORBA?
The Common Object Request Broker Architecture
defines a model of distributed computing.
Allows local invocation of operations on objects
located anywhere on a network.
5What is RMI?
Javas Remote Method Invocation defines a model
of distributed computing.
Allows local invocations of operations on objects
located anywhere on a network.
6Whats the Difference?
- CORBA supports multiple languages
- RMI is (relatively) easier to implement
- RMI allows optimization of protocols for
communication
- CORBA separates interface definitions from
implementation
- HORB, a variant of RMI, actually works in JDK
1.02 (and therefore most browsers without error).
Here, we only add to the confusion with more
terms.
Lets see some examples of the two.
72.
Hello RMI
8A Contrived Experiment With RMI
For this experiment, you will need
Two Java-ready Computers Two Fake Passports
Three round trip tickets to Moscow 3,500 Mile
s of CAT-5 wiring An MI5 License to Thread
9Experiment With RMI (Contd)
10Experiment With RMI (Contd)
4.
Return home. You now have a network.
(You may use a different networking configurat
ion,
if youre short on cable.)
RMI lets us invoke methods that are found on th
e remote machine. So lets write a little program
. . .
11Program Matryoshka Doll Server
We will use this network to smuggle Matroyska
dolls into the U.S. Our Moscow server will take
in a doll, and return a new instance,
encapsulating our original reference.
Moscovite Implementation
Stubs
DollClient
DollServer
public MatroyskaDoll ge
tDoll (MatroyskaDoll d) // working
code
public MatroyskaDoll getDoll
(MatroyskaDoll d)
12RMI Design Cycle
CLIENT
SERVER
131. Common Data Type
public class Matryoska implements java.io.Se
rializable private Matryoska child pr
ivate String strMicrofilm public Matryoska(S
tring strMicrofilm, Matryos
ka child) setChild(child) setMicrofilm(strMi
crofilm) public void setMicrofilm (S
tring strMicrofilm) this.strMicrofilm strMicr
ofilm public void setChild(Matryoska
child) this.child child public M
atryoska getChild() return child
public String getMicrofilm() return
strMicrofilm // class Matryoska
142. Define The Interface
import java.rmi.Remote import java.rmi.RemoteExc
eption public interface DollDesign extends Rem
ote Matryoska getDoll(Matryoska doll)
throws RemoteException
The java.rmi package java.rmi java.rmi.activ
ation java.rmi.dgc java.rmi.registry java.
rmi.server
153. Implement the Interface
Or extend java.rmi.activation. Activatable (JDK
1.2)
import java.rmi. import java.rmi.server. imp
ort java.net. public class DollImplementation e
xtends UnicastRemoteObject implements DollDesig
n public DollImplementation() throws RemoteEx
ception super() public Matryos
ka getDoll(Matryoska doll) throws RemoteExcep
tion return new Matryoska
(strMessage, doll) public static Stri
ng strMessageFrom Moscow With Stubs"
Causes object to be exported
163. Implement Interface (contd)
public static void main (String arg)
if (System.getSecurityManager() null)
System.setSecurityManager(new
RMISecurityManager()) try String name
"secretAgent" / or //host/secretAgent /
strMessage InetAddress.getLocalHost().getHo
stName() String name "secretAgent" D
ollDesign secretAgent new DollImplementation()
System.out.println ("Attempting to bind
name" name) Naming.rebind(name, secretAge
nt) System.out.println ("Mission accomplishe
d." "\n\tOperative " name "bound o
n " strMessage) catch (Exception e)
System.err.println ("Nyet.") System
.err.println (e.getMessage())
e.printStackTrace() //main //DollIm
plemenation
Note upcasting to interface from implementation
this
exposes the stubs and not the object!
174. Compile (javac rmic)
Rmic is an RMI compiler for java. Its in the
soup.
Skel Server Stubs Client
186. From Moscow With Stubs
import java.rmi. import java.net.
public class DollClient public static void ma
in (String arg) if (System.getSecurityMana
ger()null) System.setSecurityManager
(new RMISecurityManager())
try String name "//" arg0 "/secretAg
ent" String agents Naming.list(name) f
or (int i0 i System.out.println ("\t--" a
gentsi " found") String localHost InetAd
dress. getLocalHost().getHo
stName() DollDesign secretAgent
(DollDesign) Naming.lookup(name)
Matryoska doll new Matryoska (localHost,
null) doll secretAgent.getDoll(doll) Sys
tem.out.println ("Done) while (doll!null)
System.out.println ("Doll--"
doll.getMicrofilm()) dolldoll.getChi
ld() //try
Note use of debugging listing of available ob
jects
196. From Moscow With Stubs (contd)
catch (Exception e) System.err.println
("Error " e.getMessage())
e.printStackTrace() //Main //Dol
lClient
NOTE We only create an instance of the inte
rface,
not the remote implementation
NOTE Client must set a security manager as
well a similar
policy must be invoked
NOTE Remote resolution of stubs requires
use of security manager
20Smuggling Matryoska Dolls
grant permission java.net.SocketPermission
"1024-65535", connect,acce
pt" permission java.net.SocketPermission
"80", "connect"
7.
Bash rmiregistry 5 Pid 4523 Bash unset
CLASSPATH Bash java -Djava.security.policyjav
a.policy DollImplementation 6 Pid 4524 Ba
sh
OK. Fly back to Moscow and make a file called
java.policy
Set the policy file on startup with the -D op
tion, or else!
218. Start The Client
8.
Fly home and create a similar policy file for
the
client. Start the service.
Failure to start with the policy option will thr
ow a security exception. This is new to JDK 1.
2
223.
RMI Redux
23RMI Summary Value
RMI passes local objects by value--a copy gets
sent. RMI passes remote objects by reference--n
ot by copying. RMI stubs are proxies for the cl
ient to remote object (just like CORBA).
24RMI Summary Errors GC
Additional errors can be encountered new
exceptions must be addressed. RMI uses a refere
nce counting gc a zero count marks the
distributed object as a weak reference. A
lease is made on remote objects with a dirty
call. Leases must be renewed or will expire.
The java.rmi.server.Unreferenced interface allow
s objects to receive notification just prior to
finalization. (Single method unreferenced() ).
25RMI Summary LocateRegistry
Default port 1099 Class java.rmi.registry.Loca
teRegistry helps locate remote registries
public static Registry getRegistry() / local
/ public static Registry getRegistry
(String host, int port)
public static Registry getRegistry
(String host) public static Regis
try createRegistry (int port)
26java.rmi.Naming Class
void bind(String name, Remote obj) throws
RemoteException, AlreadyBoundException, AccessExc
eption Binds the specified name to a remote
object. String list() throws RemoteException,
AccessException Returns an array of the nam
es bound in the registry. Remote lookup(String
name) throws RemoteException,
NotBoundException, AccessException
Returns a reference, a stub, for the remote
object associated with the specified name.
void rebind(String name, Remote obj) throws Remo
teException, AccessException Rebinds the spe
cified name to a new remote object.
void unbind(String name) throws RemoteException,
NotBoundException, AccessException
Destroys the binding for the specified name
that is associated with a remote object.
27RMI Dynamic Stub Loading
Dynamic stub loading is used where the client
does not have local copies of the remote object.
The stubs can even be generated on the fly. L
ookup 1) Local resolution attempted via C
LASSPATH -- no security manager requi
red 2) Server tells client the stubs URL
java.rmi.server.codebase --
can even be a third party Registry !
-- requires security manager