aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI-cannot override interface methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI-cannot override interface methods" Watch "RMI-cannot override interface methods" New topic
Author

RMI-cannot override interface methods

Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Hi All,

I am trying to figure out how to solve this problem:

The methods I am making available via RMI need to throw RemoteException. However, the methods that they overwrite do not throw RemoteException. I guess this is a fairly common problem encountered when coding B&S but I havent been able to find any documentation that has been of use.

Any thoughts?

g


OCPJP 6, OCMJD
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2247

Howdy, Glen!

How about this one? I think it will be helpful to you!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Hey Roberto,

I think that is a step ahead of where I am. I cannot figure out how DennysDVD's gets around the problem. Put simply:

How can the methods in DvdDatabaseRemoteImpl throw RemoteException when the methods they are overriding (those which exist in DBClient) do not throw this exception?

g
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4925
    
  10

Maybe you should have a look at the inheritance tree of RemoteException. It will certainly clear your doubts


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Ahhhh. Got ya.

It still leaves me without a solution for the bigger picture .

So I get to write the exceptions that the sun provided interfaces' methods throw. So I guessed that if I made them extend RemoteException then I would have solved my problem. But I am still coming up with the following error when i try to run my Server:
java.lang.IllegalArgumentException: illegal remote method encountered: public abstract void suncertify.db.DBMain.lock(int) throws suncertify.db.RecordNotFoundException


From research, it seems that the error is occuring because the methods I am exposing via RMI do not throw the RemoteException. Maybe I am wrong on that one?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4925
    
  10

So I guessed that if I made them extend RemoteException then I would have solved my problem.

That's simply a bad design! You should only use inheritance if you have an IS-A relationship between 2 classes, not because it's convenient. And because RecordNotFoundException is not a RemoteException using inheritance is not the way to go.

Maybe I am wrong on that one?

Just create an own business service interface where each method throws RemoteException. Here you decide between a thick or thin client approach.

Here you'll find more info about the do's and don'ts about RMI (& RemoteException).
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Thanks Roel. I'll check it out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI-cannot override interface methods
 
Similar Threads
DBClient interface
RMI Error
Implementing Data interface in local and network mode
overridden method does not throw RemoteException
Stumped with RMI design