Originally posted by Jonathan Moore:
I am using RMI and have decided not to expose the methods in the DB interface to the client, but to have an intermediate interface, ClientInterface, with find() and book() methods defined. My reasons for this are as follows:
Originally posted by Jonathan Moore:
2) The DB interface does not extend Remote and none of the methods throw RemoteException. You would therefore need to create another interface with similar methods to expose it via RMI (since changing the DB interface would probably result in a failure), with an wrapper to convert between the new interface and DB. My design allows for a single interface to be used in the client, regardless of whether the client is running alone or connecting to the server.
Thanks for the reply Alan - you've raised a good point. I've been working from Alain Trottier's Exam Cram examples, and was planning on having a single interface used by the client in both local and networked mode, and was going to use the Remote extension for this. As you point out though, this would mean having code to catch RemoteExceptions in local mode, which is not a good design. I'm not sure that the Exam Cram book is up to much...
I think I was on the right lines but had oversimplified my design - the class structure in the link you sent makes more sense.
Another question - my only reference to my Data class is in the ServiceImpl class (RemoteServiceImpl is an adapter for ServiceImpl). The book() method does the following:
lock
find record
check validity
update
unlock
This means that locking and unlocking is done even when running in local mode. I've thought of a couple of ways round this, but feel it overcomplicates things, and the overhead of locking and unlocking is very small. I think this is justifiable, since the instructions state that a clear design will be prefered to a more complex one, even if the complex one is a little more efficient. Does this seem reasonable?
Poop goes in a willow feeder. Wipe with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|