aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI Design : Following Max's Book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI Design : Following Max Watch "RMI Design : Following Max New topic
Author

RMI Design : Following Max's Book

Sudhansu Pati
Ranch Hand

Joined: Sep 23, 2003
Posts: 77
Hello Gurus !! I have completed my Database Server degign/coding and now penetraitng to the RMI space.
While I was following Max's book, I got confused on the following topics.
Page 133 : Explains about DBClient interface. The name is somewhat misleading. It should be something like DBService.
Page 173 : DBClient interface doesn't throw RemoteException for the interface methods.
Here is my RMI design for Bodgitt and Scarper. Please comment.
DataService.java

DataAdapter.java

DataConnector.java

DataRemote.java

[ October 02, 2003: Message edited by: Suds Pati ]
[Andrew: Removed lots of code - see comment below]
[ October 02, 2003: Message edited by: Andrew Monkhouse ]

Sudhansu<br />SCJP, SCWCD, SCBCD, SCJD, SCEA, SCDJWS
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Suds,
Sorry, I deleted a lot of your code.
In general we allow people to ask for comments on one or two methods, or ask for comments on code that is "proof of concept" (that is, it gives an example of how to do something, but cannot be used directly in an assignment).
I think you provided nearly all the code necessary for the network interface to the database, and as such it was a bit too much. I have reduced it so that someone cannot copy your code and have a working network solution - they will still have to do some development work themselves. I have tried to leave some sample methods so that people can make comments.
You will generally get better comments if you try to restrict the scope of your questions. It appears that you have two separate questions: one regarding Max's book, and one generic request for peer review. I think the question about Max's book could be a separate topic, and I think you are better asking for a comment on one specific item of your code, for instance asking for "comments on the interface you are providing", or asking for comments on the "booking" method.
Now for some comments on your post ...
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Suds,
DBClient should not throw RemoteException - DBClient is used for other connections than just RMI.
DVDDatabaseRemote extends DBClient and DBClient. This is the interface that is used for RMI.
But DVDDatabaseRemote also does not throw RemoteException. This is a very nice trick - since DBClient throws IOException (which is a parent of RemoteException) DVDDatabaseRemote does not need to explicitly throw RemoteException.
Regards, Andrew
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Suds,
A couple of quick questions on your code, then I will stop posting in just this one thread
Why do you have both an update() method and a book() method?
What happens if a record has already been updated? According to the code you posted, the original update will be lost.
Regards, Andrew
Sudhansu Pati
Ranch Hand

Joined: Sep 23, 2003
Posts: 77
Hi Andrew,

Why do you have both an update() method and a book() method?
What happens if a record has already been updated? According to the code you posted, the original update will be lost.

It is not clear how Sun wants us to implement update(). The interface requirement asks to provide update on all fields.
But the UI requirement doesn't ask to create any screens to update a record. The only time a record can be updated is when the CSR book a contractor, i.e updating just the owner field of the record.
I am not sure if I need to provide update() as a public method for client layer. But you are right. If I keep it, I will be responsible for providing thread safety between book() and update().
What is your opinion ?
I will open another discussion for the RMI question.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Suds,
My opinion is in the thread Should lock methods be callable by the client. Although that topic centers on locking, the same logic applies to all the other methods in Sun's interface. I will let you read it and make up your own mind rather than stating my opinion again.
Apart from the possible interaction between the update() and bookContractor() methods, you also have to make sure that two calls to the same method with the same record will work correctly. That is, the first call to bookContractor() with record #1 will update the record while the second call to bookContractor() with record #1 will fail because the record has already been updated. It is not obvious in your code that you are catering for this.
Regards, Andrew
Sudhansu Pati
Ranch Hand

Joined: Sep 23, 2003
Posts: 77
Hi Andrew,
Thank you for your quick response.
[B]
Apart from the possible interaction between the update() and bookContractor() methods, you also have to make sure that two calls to the same method with the same record will work correctly. That is, the first call to bookContractor() with record #1 will update the record while the second call to bookContractor() with record #1 will fail because the record has already been updated. It is not obvious in your code that you are catering for this.
[B]
I am glad that you metioned this. At this moment the simplest solution I have to modify the update() method of Data.java as follows.
[I]Data.java[I]
[/CODE]
public synchronized void update(int recNo, String[] data, long lockCookie) throws
RecordNotFoundException, SecurityException {
1. dbRecord = the database record recNo
2. String dbOwner = owner field of dbRecord
3. String owner = the owner field of data.
4. If ((dbOwner !=null) && (owner!= null )) -> throw exception "contractor is already booked"
else -> proceed with update.
[/CODE]
Do you think this will work ?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Suds,
Yep, that looks pretty good.
Regards, Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI Design : Following Max's Book