Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

RMI callback

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
    Bookmark Topic Watch Topic
  • New Topic