I'm currently working on the B&S assignment. I've gotten to the point where I'm trying to get RMI to work.
My design is as follows:
Data implements the mandatory DBMain-interface
I have 2 interfaces called LocalDataAdapter and RemoteDataAdapter. These 2 interfaces introduce business methods, find() and book(). By using these interfaces I'm effectively hiding the methods in Data. The business methods implement a lock, update, unlock strategy.
RemoteDataAdapter extends LocalDataAdapter as well as Remote.
I also have 2 classes LocalImpl and RemoteImpl that implement LocalDataAdapter and RemoteDataAdapter respectively.
RemoteImpl wraps an instance of Data. Data does not implement Serializable. Data contains private instance variables that are used to read the database file in a correct way. These varibales get their in readHeader and readSchema, which are methods called from the constructor.
I am able to compile my entire project, the Data implementation works fine in local mode (Using JUnit for various test). I can start the rmiregistry, run RemoteDataImpl, (its instance gets loaded into the registry). When RemoteDataImpl runs, a System.out.println tells me the Data constructor is called.
So far so good.
Through the client I can call the test HelloWorld() which returns the String "Hello".
When I attempt to call find() from the RemoteClient, it calls the find() in RemoteImpl which accesses find() in the Data class that RemoteImpl wraps. It seems as if the primitive instance variables in Data are all 0. All instance reference valuables on the other hand are intact.
What am I doing wrong? Please help!!! [ November 23, 2004: Message edited by: stefan andersson ]
Sorry, I am don't understand what you are saying your problem is.
I take it that your Data class is working correctly in stand alone mode, and that everything is compiling and running in remote mode, but Data class is not working in that case?
Do you get any output from either client or server? I noticed you have an output message if Data class cannot find the database file - how about putting an output message to show when it is instantiated correctly (or even better - change your output messages to log messages, then they can always exist: just change the log level to whatever is appropriate to hide them).
One thought: static variables are ignored in the serialization - the mechanism behind rmi object transfers. The behavior you are describing would occur if the primitives are declared static in the remote implementation class.
Yes, you must consider static variables as transient by default.
Anyway, I'm not trying to steal the topic , but I find it a bit overkill to start a new topic about this, its just a tiny question and can maybe also help TS. What I would like to know about the RMI server thing is:
Is it normal the server is nothing more then approx 3 classes (depending on the design) ?
- remote interface - implementing class - main that launches the registry and registers the service
I feel that this is too easy to be true...
The total story would be:
[gui] [rmi server (consists out of 3 classes] [database]