wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI question" Watch "RMI question" New topic
Author

RMI question

Serev Nikolaisen
Greenhorn

Joined: Nov 17, 2008
Posts: 6
Hello!

I'm following the "SCJD Exam" book and are trying to implement a RMI test following the factory pattern explained in the book. Should be fairly easy but I run into some trouble

I have the following classes/interfaces:

DatabaseInterface
DatabaseRemoteInterface extends Remote, DatabaseInterface
DatabaseRemoteImpl extends UnicastRemoteObject implements DatabaseRemoteInterface

In DatabaseRemoteImpl I have to throw RemoteException according to RMI. But when I declare the methods my IDE says I can't throw RemoteException because it's not valid according to the throw declarations in the DatabaseInterface (which DatabaseRemoteInterface is inheriting from)

What am I missing ? The guys in the book adds RemoteException to the methods in DvdDatabaseImpl
Serev Nikolaisen
Greenhorn

Joined: Nov 17, 2008
Posts: 6
It looks like the IOException thrown in all DBClient methods is the reason for the book example to work.

If I remove IOException or replaces it with a custom Exception the IDE gives me an error.

So.. What is the magic RMI link between IOException and RemoteException ?

Andrew ?
Serev Nikolaisen
Greenhorn

Joined: Nov 17, 2008
Posts: 6
Ok.. my mistake.. IOException is super to RemoteException

But.. If I don't want the DatabaseInterface methods to throw exceptions.. How should I design the Remote Interface/Impl so the "remote methods" is able to throw RemoteException ?
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Partner, do you want a suggestion? Follow this tutorial: http://java.sun.com/docs/books/tutorial/rmi/server.html. This is how I developed my server and got 40 points for it.
[ November 17, 2008: Message edited by: Roberto Perillo ]

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Serev Nikolaisen
Greenhorn

Joined: Nov 17, 2008
Posts: 6
Thanks, but the url gives me "page not found"

Edit: But after deleting the last . if works
http://java.sun.com/docs/books/tutorial/rmi/server.html
[ November 17, 2008: Message edited by: Serev Nikolaisen ]
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Sorry for the extra "."!
Now it is fixed.
Serev Nikolaisen
Greenhorn

Joined: Nov 17, 2008
Posts: 6
The tutorial explains the basics, but I'm still a bit confused on how to solve this for the assignment.

I guess something like the solution in this thread is the way to go: http://www.coderanch.com/t/183727/java-developer-SCJD/certification/NX-DBAccess-RemoteException

In my example it will look something like:

DatabaseInterface
DatabaseImpl
AdapterDatabaseInterface
DatabaseRemoteInterface extends Remote, AdapterDatabaseInterface
DatabaseRemoteImpl extends UnicastRemoteObject implements AdapterDatabaseRemoteInterface
DatabaseLocalImpl extends AdapterDatabaseInterface

DatabaseInterface and AdapterDatabaseInterface have the same methods but the Adapter in addition throws IOException on all methods

DatabaseRemoteImpl and DatabaseLocalImpl both holds an instance of the DatabaseImpl

Does this look like an ok design ? The only thing worrying me is the IOException I have to catch in the standalone mode.

[ November 17, 2008: Message edited by: Serev Nikolaisen ]
[ November 17, 2008: Message edited by: Serev Nikolaisen ]
Alecsandru Cocarla
Ranch Hand

Joined: Feb 29, 2008
Posts: 158
I think the idea was that the adapter interfaces do not throw IOException or RemoteException. They just wrap those exceptions into something more GUI-friendly. The GUI does not even have to know about RemoteExceptions at all (Except, maybe, the exception handler, which will probably unwrap it and do something with it).


SCJP 1.4 100%
SCJD 99.5%
Serev Nikolaisen
Greenhorn

Joined: Nov 17, 2008
Posts: 6
I tested the design described in my previous post and at looks like it will work.

When it comes to the IOException and standalone mode I think it will be OK since my client implementation will be "mode independent" and only work against the Adapter interface.

Thanks for the help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI question
 
Similar Threads
DBMain database interface & RemoteException
Basic Design
Can my Data class implement an interface which extends the DataAccess interface?
B&S 2.2.2 - Network Layer Query
Handle RemoteException