aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI blues 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 "RMI blues" Watch "RMI blues" New topic
Author

RMI blues

Arthur Logtenberg
Greenhorn

Joined: Oct 11, 2001
Posts: 2
Spooky things happening....
I thought this was perfect... RemoteInterface lists the public Data methods,
The server implementation class:
public class ServerImpl extends UnicastRemoteObject implements RemoteInterface
In the FlightsTableModel class I have a class member:
RemoteInterface myDataObject
Dependant on the mode (local/network) I do:
if ( networkmode ) {
myDataObject =
(RemoteInterface) Naming.lookup("rmi://"+serverName+"/ServerImpl instance");
} else { // local mode
myDataObject = new ServerImpl("ServerImpl instance", dbname);
}
So, myDataObject can be used transparently in the client, without having to bother about the mode. The server process is running all the time.
... and it all works perfect, both in local and in network mode... except when I change mode. If I am in local mode, switch mode to network in the GUI (app terminates) and start the client again, it does not work (unless I stop and start the server process again).
There is no exception generated during the Naming.lookup(..) (although it takes some 10 seconds, probably timing out). However the program flow falls flat (ConnectException) on executing the first method on myDataObject. Why is this ? The local and remote databases are 2 separate files. I do not want to ask the examinator to stop and start the server !!
Who can help me ?? Thanks in advance.
- Arthur

[This message has been edited by Arthur Logtenberg (edited October 09, 2001).]
Arthur Logtenberg
Greenhorn

Joined: Oct 11, 2001
Posts: 2
Found the solution myself. Had to read half the excellent book 'java.rmi, the remote method invocation guide', from Pitt/McNiff, before I got the clou (not from the book though): this method should NOT be executed in local mode:
Naming.rebind(name, this);
An extra mode (local/network) parameter to the constructor of ServerImpl enables me to avoid executing rebind(..) in local mode.
Now I think I have the perfect, most elegant solution, for using just 1 RMI-server class in both local and server mode.
Kind regards, Arthur

[This message has been edited by Arthur Logtenberg (edited October 12, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI blues