Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Remote interface for Data class with RMI

 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have a question using RMI. Sun's provided interface is called DBMain. Now remote interface needs to extends Remote. My current files declaration looks like this:

//package suncertify.db
public interface DBMain { ... } // Sun provided interface
public class Data implements DBMain { } // local Data class

//package suncertify.server
public interface DBRemote extends Remote { ... } // declares DBMain methods with them throwing RemoteException
public class RemoteData implements DBRemote { ... } // get instance of Data class and call Data class methods

Now is it possible to make DBRemote "IS A" DBMain? Or RemoteData "IS A" Data? I ask this because in my client (local or remote) will need to connect to the data file - if there is a superclass that I can use then my client code will use that as the return type rather than Data or RemoteData or their respective interface DBMain or DBRemote.

If I extends DBMain for DBRemote, then the methods clashes with DBMain's method because RemoteException isn't thrown. Right?

On the other hand, if I do:
public class RemoteData implements Remote, DBMain { ... }

This would meet the "IS A" criteria but this doesn't look right for RMI apps?
 
Kevin Florish
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi K

Having had a nightmare with the RMI issues over the last 3 weeks and a very long post on this form concerning it

http://www.coderanch.com/t/424930/Developer-Certification-SCJD/certification/BS-Stub-errors-running-network

I used the resources linked in the post to get a grip on this area of the project.

The choices available to you are using a fat client (including Data) on the remote interface side or using a thin client where the remote interface knows nothing about Data.

I chose the thin client option and with some help from Ken Krebs replies managed to get this area working yesterday. Have a read through this post and see if it helps and I would also recommend the suggested reading article for this forum by Ken Krebs if you wish to take the thin client route.

Ken Krebs' notes: http://www.coderanch.com/t/184523/java-developer-SCJD/certification/NX-Notes-design-passed

In my project my remote services interface uses book and search and delegates to a data instance that is passed with the initial call to remote services when registering the database.

When creating the client connection I then delegate to this Data instance for Book and Search. This approach makes the network code very small indeed (my RemoteServicesImpl compiles to 3.8k).

I would also suggest reading the section on RMI from "Head First Java" if you have the book available. The example is very easy to code up and follow.

Hope this helps

Cheers Kevin.
 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kevin,

Thanks for your comments. In fact, I only about a week or so on RMI issues so far and make some good progress. Yet my RMI server runs properly I think, my database connection becomes an issue - Sun's DBMain for local and my DBRemote for remote. Then by the time I figure that out, I'm sure there will be some other problems with another part of the app.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic