Hi, What happens if a thread tries to invoke UnicastRemoteObject.exportObject(server), if the server is already exported. Does it throw an exception ? Basically I didn't get the concept of exporting a server correctly. Does it mean that unless a RMI server is exported, we can't invoke methods on it ? or is there any way by which we can invoke remote methods without exporting the server ? Any info. regarding this will be helpful. Thanx & Regards, Gopals
What happens if a thread tries to invoke UnicastRemoteObject.exportObject(server), if the server is already exported.
Why are you trying to export the server? You don't need to, as it is done automatically when the object that extends Remote(your server) is instantiated. But that doesn't matter at all. It should be under your threshold of concern if you are just using standard RMI, as it is all done for you.
Does it throw an exception ?
I don't know, the docs only say that it throws an error if the export fails, but it doesn't state whether a duplication would constitute a failure. Try it. Run this command twice in a row in your code. I doubt it will throw an error.
Basically I didn't get the concept of exporting a server correctly. Does it mean that unless a RMI server is exported, we can't invoke methods on it ?
Don't worry about doing it directly like this. This is only used internally AFAIK. Use the registry to access it. You can't invoke methods on a server if it isn't exported, but it is done for you as I mentioned above, and you just have to bind it to the registry. If you really want to know some of the guts of RMI, read about halfway down in this post. If you're just getting started with RMI, ignore that. It will probably just confuse you. Or not, depends on how much you like to know about how things work. HTH, any other questions? Chris [ May 11, 2004: Message edited by: Chris Shepherd ]
posted 16 years ago
I got the answer. exportObject() method's purpose is to create the remote object stub. If a RMI server doesn't extend UnicastRemoteObject, then automatically stub object is not created. To create the stub, one needs to invoke this method. Answer to my question is 1. If server is not exported, it can't bind to the rmi registry and simply not function as rmi server, becoz the server stub object is not created. 2. If a server is exported more than once ??? What could possibly happen if I create more than one stub objects for the same server ? This looks like a problem. This is what I understand. Correct me if I am wrong. When a server is exported, a unique ObjID is associated with a server. On the server side, the RMI runtime uses the deserialized instance of ObjID to figure out for which stub the remote method invocation is intended. If there is more than one stub associated with a RMI server, than how would RMI runtime determine which stub to use. Using either stub would work, but ... This could be a problem if RMI servers and the stubs r expected to have one to one mapping. If that is the case, the developers of RMI shud never let a server to be exported more than once. It shud ideally throw an exception -> Remote exception as export would fail. Gopals [ May 12, 2004: Message edited by: Gopal Shah ]