Wednesday, October 1, 2003 05:01 PM
You can, of course, pass any kind of object around within an application. If that object fullfills a remote method interface, then you have to have gotten that object from the registry, or you created it yourself. Once you have it though, you can use it however you want, pass it around, etc. I haven't personally tried
passing a remote interface to another object via RMI, so I don't know if that works (I don't see why it wouldn't), but if you pass a locally created
object that happens to fullfill that remote interface, then stuff done in the remote VM will not affect the object where it was created since the object itself will get serialized and sent rather than a stub that points back at the object.
RMI is slower than intra-VM method calls, so it doesn't make sense to use it for local objects and methods; if you keep a reference to your RemoteObject locally after you create it, you can certainly access it via that reference rather than through RMI.
If you need to use RMI, you don't have to use the supplied rmiregistry program, which has some shortcomings. You can instanciate and use your own registry.
// Create a registry
Registry r = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
// bind your object to it as normal.
And now, locally only, you can access the same object without the RMI stub by using
I hope somewhere I've covered what you've asked!