File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Remote interface for Data class with RMI

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2419
    
    7

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/OCM-JD OCPJP7 OCPWCD5
Kevin Florish
Ranch Hand

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

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

Joined: Sep 13, 2007
Posts: 2419
    
    7

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: http://aspose.com/file-tools
 
subject: Remote interface for Data class with RMI