• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Remoting layer

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I have already seen the related threads
here and here

I was given a DB interface
interface DB {
public long lock(int recNo) throws RecordNotFoundException;
}

For Remoting I wrote a
interface RemoteDB extends DB, Remote{
}

And the RemoteDBImpl class looks like
class RemoteDBIMpl extends UnicastRemoteObject implements RemoteDB{
public long lock(int recNo) throws RecordNotFoundException {
//delegate to the actual object
}
}

There is a problem in exporting the RemoteDBImpl since the exportObject method complains that the signature is illegal. Here is the problem
1) If I say the lock method to throw RemoteException as well, then it gives compilation errors since the extended interfaces cannot throw new exceptions
2) If I make RemoteDB interface to not extend DB and just copy over the interface methods, then my Controller which presently works with DB interface (irrespective of whether it is a local or remote connection) cannot work.

Can someone tell me what solution they devised for these problems?
[ December 06, 2008: Message edited by: Kannan Ekanath ]
 
Kannan Ekanath
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ December 06, 2008: Message edited by: Kannan Ekanath ]
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ran into a similar problem also.

You should remove the "extends DB" from RemoteDB declaration.
This is needed if you do not want to change the DB interface. I guess, Sun does not allow to change its interface.

The problem is that the methods of the class, you want to send through RMI, have to be declared throwing RemoteException. If you leave "extends DB" in the declaration of RemoteDB, you should change methods of DB to throwing RemoteException.

You should imagine RemoteDB as a wrapper class for DB. Methods of RemoteDB should throw RemoteException. The client will see the remote database through RemoteDB.

And I think, you should use a 3rd interface for Controller on the client side to hide the difference between RemoteDB and DB.


I guess, you also used the Monkhouse book ... It is a trick in this book that Monkhouse defined his DBClient methods throwing IOException. In this way, the DBClient methods can throw RemoteException also because RemoteException is an IOException. So, he could insert "extends DBClient" into the declaration of DvdDatabaseRemote. But this solution works only if the methods in Sun provided interface (DBMain, I guess) throw RemoteException or IOException.

Regards,
Attila
[ December 07, 2008: Message edited by: Attila J�borszki ]
 
Kannan Ekanath
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spot on Attila. That was the exact solution I came up with.

DB is the standard interface (which unfortunately doesnt throw IOException or RemoteException)

If DBRemote extends DB then that is when problem arises in that any implementation of DBRemote cant be exported.

Solution:
DBRemote - does not extend DB but copy over all methods in DB and alter the signature to throw RemoteException
DBRemoteImpl extends UnicastRemoteObject implements DBRemote - and show can be exported (It has a DB object of instance DBImpl to which it delegates to)
DBAdapter implements DB - And is constructed with a DBRemote object. So it calls the corresponding methods on DBRemote and catches RemoteExcpetion only to rethrow it back

Round about, but probably the only elegant way of doing it
 
reply
    Bookmark Topic Watch Topic
  • New Topic