File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: About RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: About RMI" Watch "NX: About RMI" New topic
Author

NX: About RMI

Flavio Nobili
Ranch Hand

Joined: Jan 28, 2004
Posts: 58
Hi people,
I've written the server class with the option to start/stop, and allowing the user to change the connection port number. But, when the user changes the port number and try to start the server again an exception is throwed (java.rmi.NoSuchObjectException).
This is the code to start the server:

Does anyone know what is wrong with it?

Another doubt: must I implement RMISecurityManager?

Regards,
Fl�vio.


Java Developer
SCJP, SCJD, SCWCD, SCBCD
Leo Tien
Ranch Hand

Joined: Sep 10, 2002
Posts: 156
Hi Fl�vio :
a)How you implement in your stop method ?
b)Which step you do on your test throw the Exception?
1) start(1234) --> start(1235)
2) start(1234) --> stop(1234) --> start(1235)
c)After read the java.rmi.NoSuchObjectException javadoc, I think the problem be caught by your remote object. the statement is :
A NoSuchObjectException is thrown if an attempt is made to invoke a method on an object that no longer exists in the remote virtual machine. If a NoSuchObjectException occurs attempting to invoke a method on a remote object, the call may be retransmitted and still preserve RMI's "at most once" call semantics. A NoSuchObjectException is also thrown by the method java.rmi.server.RemoteObject.toStub and by the unexportObject methods of java.rmi.server.UnicastRemoteObject and java.rmi.activation.Activatable
Flavio Nobili
Ranch Hand

Joined: Jan 28, 2004
Posts: 58
Hi Leo,

a)How you implement in your stop method ?

In my stop method I just unbind the remote object and set the registry variable to null.



b)Which step you do on your test throw the Exception?
1) start(1234) --> start(1235)
2) start(1234) --> stop(1234) --> start(1235)

The step 2.


c)After read the java.rmi.NoSuchObjectException javadoc, I think the problem be caught by your remote object.

The remote object is unbounded and set to null.
Do you have any idea about what is happening?

Thanks,
Fl�vio.
Leo Tien
Ranch Hand

Joined: Sep 10, 2002
Posts: 156
Hi Fl�vio:
I test your program in my machine, and find that the problem take place in the reference of registry.

When you call start() method second time and intend to create another registry on other port, the program reach a). Why this happen, will discuss it later. At a), your 'registry' variable simply create a local reference. Pls look this statement in javadoc:
Note that a getRegistry call does not actually make a connection to the remote host. It simply creates a local reference to the remote registry and will succeed even if no registry is running on the remote host. Therefore, a subsequent method invocation to a remote registry returned as a result of this method may fail.

This means that when you use createRegistry(1234) create one registry instence on your VM, VM will put it into one table stores running registry. But then you call getRegistry(1235) to get one registry reference, but this registry isn't in the table, in other words it isn't running on the VM, and later when you call rebind() method of its could catch the NoSuchObjectException. Because you attempt to invoke a method on an object that no longer exists in the remote virtual machine. This is point out above on javadoc.
Now we discuss why this happen, in other words why the second time the program execute getRegistry but not createRegistry. I think in your stop() method, the code don't make any sense at all. The unbind line only remove 'DBAccess' from bound list of registry(1234). Because you create a registry(1234) before, and not shut down it, so it exist in your VM yet when you attempt to create another registry. And in one VM, must there is a container hold the running registry, every registry instence have three attribute, IP Address, port number and objID. These value must be unique in one VM, so you cann't create registry(1235) before registry(1234) shut down.
So in your stop() method must shut down registry(1234), but I don't find the method to shut down a running registry , may be some body can tell us. Let's wait......
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Leo and Fl�vio,
Originally posted by Leo Tien:
So in your stop() method must shut down registry(1234), but I don't find the method to shut down a running registry , may be some body can tell us. Let's wait......

Well, I hope you're not waiting on me for the solution because I was never able to solve this problem.
My "solution" (not that it deservers that name) was to catch the NoSuchObjectException and display the following to the user in an error message dialog:

You have attempted to change the port for the RMI registry. You will need to restart the server for this change to take effect.

So the user was forced to shutdown the server and upon restarting it the registry was created without generating the NoSuchObjectException. I never investigated exactly why this seemed to work, but I can speculate that because the registry was started programmatically by the server that somehow it terminated when the server was shutdown.
Now, I'll admit that's a pretty ugly "solution," but I was never able to figure out how to programmatically shutdown the registry itself (short of shutting down the entire server). So good luck to you guys finding the real solution. I imagine it will either turn out to be really simple or impossible.
Hope this helps,
George
[ February 12, 2004: Message edited by: George Marinkovich ]

Regards, George
SCJP, SCJD, SCWCD, SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: About RMI