Two Laptop Bag
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI implementation and Adapter Class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "RMI implementation and Adapter Class" Watch "RMI implementation and Adapter Class" New topic
Author

RMI implementation and Adapter Class

stefan andersson
Greenhorn

Joined: Nov 22, 2004
Posts: 5
Hi!

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 ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 10816
    
  25

Hi Stefan,

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).

Do you get any exceptions thrown? If so what?

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
stefan andersson
Greenhorn

Joined: Nov 22, 2004
Posts: 5
Hi Andrew!

Thanks for replying!
I removed some System.outprintln rows when I posted the code.

I can start the rmiregistry, start the rmiserver which gets loaded into the registry and then call the rmiClient class that connects to the RemoteDataImpl instance. This I can see through printouts.

I have a print in the Data constructor that indicates that Data gets instantiated. For the moment I only instantiate one RemoteDataImpl but I plan to have one instance per remoteCient.

Data is istantiated, but all the private values of Data such as numberOfFields and filePointer are all 0 when accessed through DataClient.

Data uses these private values in its methods to calculate the right position in the database file.

Do primitive values get reset when they are unmarshalled?

I am using JDK 1.4.2

What could be wrong?
[ November 23, 2004: Message edited by: stefan andersson stefan andersson ]
Bridget Kennedy
Ranch Hand

Joined: Nov 30, 2004
Posts: 84
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.
Jim Janssens
Ranch Hand

Joined: Sep 24, 2004
Posts: 210
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) ?

Like:

- 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]

is this correct ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI implementation and Adapter Class
 
Similar Threads
Stand alone criteria [B&S]
Initial design review
Can my Data class implement an interface which extends the DataAccess interface?
RMI Exceptions RecordNotFoundException
About:My URLyBird1.3.2 Locking