File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Remote interface for Data class with RMI 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 "Remote interface for Data class with RMI" Watch "Remote interface for Data class with RMI" New topic

Remote interface for Data class with RMI

K. Tsang

Joined: Sep 13, 2007
Posts: 3130

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?

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
Kevin Florish
Ranch Hand

Joined: Jan 06, 2009
Posts: 181
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

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:

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.

Java5 Tutorials | Java6 Tutorials | HTML/CSS Tutorials | JavaScript and jQuery Tutorials
K. Tsang

Joined: Sep 13, 2007
Posts: 3130

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.

I agree. Here's the link:
subject: Remote interface for Data class with RMI
It's not a secret anymore!