aspose file tools*
The moose likes Distributed Java and the fly likes RMI callback Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI callback" Watch "RMI callback" New topic
Author

RMI callback

Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
We have a local RMI server which provides for clients to register for callback.

public void registerForNotification(Notifiable n){
clientList.addElement(n);
}

The client is an Applet which implements Notifiable,and exports itself to the registry:

Registry registry =
LocateRegistry.getRegistry(RMIInterface.REGISTRY_PORT);
RMIInterface remoteReference =
(RMIInterface) registry.lookup(RMIInterface.REGISTRY_NAME);

try {

UnicastRemoteObject.exportObject(this);
remoteReference.registerForNotification(this);
}
catch(RemoteException re) {
re.printStackTrace();
}
......

The client receives the server callbacks sucessfully - but the client stub has to be available at both the client and server.
Is there some way to make this work with the client stub available only as part of the server process?
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

You don't need the RMI Registry for your client.

Pass the exported remote object:
InterfaceName in = (InterfaceName)UnicastRemoteObject.exportObject(this);
to the server as a parameter in your remote method call:
server.helloBigBoy(in, other fields);

Now the server can call your client without going to the registry.


Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
We pass in the 'this' reference to registerfornotification method of the server(which is in line with what you said).

remoteReference.registerForNotification(this).

The registerforNotification simply adds the interface to a vector ,to be called back on later.

However,if we remove the client stub from the server classpath ,we get the following exception:

Jan 11, 2007 11:21:26 AM sun.rmi.server.LoaderHandler loadClass
FINE: RMI TCP Connection(2)-60.254.69.76: name = "com.ibm.applet.PackagedApplet_
Stub", codebase = "http://<machine-name>:8888/appletRMI/applet/remotermi.jar ht
tp://<machine-name>:8888/appletRMI/"
Jan 11, 2007 11:21:26 AM sun.rmi.server.LoaderHandler loadClass
FINER: RMI TCP Connection(2)-60.254.69.76: (thread context class loader: sun.misc.Launcher$AppClassLoader@133056f)
Jan 11, 2007 11:21:26 AM sun.rmi.server.LoaderHandler loadClass
FINE: RMI TCP Connection(2)-60.254.69.76: class com.ibm.applet.PackagedApplet_Stub" not found via thread context class loader (no security manager: codebase disabled)
java.lang.ClassNotFoundException: com.ibm.applet.PackagedApplet_Stub
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
......
.......


What is the way out of this - apart from the alternative of adding the client stub in the server classpath.
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

You can't pass "this" as a remote object. This is why you now need the stub in the classpath.

Get the remote object back from the export. Save it somewhere. Pass that remote object to the server, not "this".

InterfaceName in = (InterfaceName)UnicastRemoteObject.exportObject(this);

Pass "in" to the server, not "this".
Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
I saved the exportobject into an interface and passed it;I was getting the same problem.
However after configuring the Security Manager and the policy file,I can callback on the client without requiring the client stub on the server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI callback
 
Similar Threads
I am close to submit - question about rmi
Applet AccessControlException as RMI client
URLBirdy: RMI Question
RMI and callback client codebase
how RMI works?