Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

RMI implementation and Adapter Class

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
author and jackaroo
Posts: 12199
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
stefan andersson
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

[rmi server (consists out of 3 classes]

is this correct ?
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic