Professional Documents
Culture Documents
Outline
Let first builds a simple home-made
framework
This is useful to understand the main
issues
We see later how java-rmi works and how
it solves the same issues
Generic architecture
server
client
object A proxy for B
skeleton
& dispatcher
for Bs class
Request
remote
object B
Reply
Communication
Remote
reference module
module
Communication
module
Remote reference
module
servant
Implementation
Wed like something like this
client
proxy for Counter
object A
Receive input
Client Object
Communication
Remote
reference module
module
Implementation
Proxy
object A
client
proxy for Counter
Communication
Remote
reference module
module
Implementation
Communication module
server
skeleton
& dispatcher
for Bs class
remote
object B
Initialize
Register an object
Communication
Module
Remote reference
module
servant
Receive request
Implementation
Skeleton
server
skeleton
& dispatcher
for Bs class
Communication
module
remote
object B
Remote reference
module
Initialize
(bound to a
Counter)
servant
Skeleton &
Dispatcher
Receive request
Send the reply
Implementation details
See RMI-LAB on the web site
Exercise: add a new object
Lesson learned
Java-rmi solution
Managing communication
Embedded into the JVM
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Server
{
public static void main(String args[]) throws RemoteException
{
//Create a remote object..
Counter c = new Counter_impl() ;
Counter stub =
(Counter)UnicastRemoteObject.exportObject(c, 0);
//bind "counter" to the stub
Registry registry = LocateRegistry.getRegistry();
registry.rebind("counter", stub);
System.out.println("Counter bound");
}
}
Export object =
It can receive requests
Client
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client
{
public static void main(String args[])
{
try{
Registry registry = LocateRegistry.getRegistry(args[0]);
Counter c = (Counter) registry.lookup("counter");
int i = c.inc(10);
System.out.println(i);
}
catch (Exception e){e.printStackTrace();}
}
}
Class downloading
JAVA-RMI allows to
download the definition
of an object's class if
the class is not defined
in the receiver's Java
virtual machine.
Classes definitions are
typically made network
accessible through a
web server
Class downloading
Class downloading are
controlled by a
Security manager
Without a security
manager installed, RMI
will not download
classes, other than
from the local class
path.
This restriction ensures
that the operations
performed by
downloaded code are
subject to a security
policy.
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new SecurityManager());
}
LAB2
Account example
LAB3
Shared whiteboard