This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

RMI question

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Serev Nikolaisen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the extra "."!
Now it is fixed.
 
Serev Nikolaisen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: https://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 ]
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Serev Nikolaisen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic