aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Question on lock/unlock implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Question on lock/unlock implementation" Watch "Question on lock/unlock implementation" New topic
Author

Question on lock/unlock implementation

Kevin Cao
Ranch Hand

Joined: Jun 19, 2002
Posts: 55
This is my implementation of lock/unlock. I implemented lock/unlock in Data by using a reference of LockManager. I think this is a "generic" functionality, and it should be here.

I don't have a LocalData, if it is in local mode, I just passed a wrapper class of Data (with business logic such as bookFlight, but without lock-read-modify-unlock sequence). If it is in remote mode, I passed the RemoteDataImpl(I aslo implement bookFlight here, but with the sequence), another Data wrapper.
Thanks for your comments.
-Kevin
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

I implemented lock/unlock in Data by using a reference of LockManager. I think this is a "generic" functionality, and it should be here.

Hmm, Data class was generic before you made it use your LockManager. Not anymore, -- if you want to replace your locking schema with something else, your (presumably generic) Data class has to change. So, here is a challenge for you, -- can your app use LockManager while you Data class knows nothing about it?
Eugene.
Kevin Cao
Ranch Hand

Joined: Jun 19, 2002
Posts: 55
Eugene-
I think the Data class is a reflection of the database(a file here), it should contains all the functinalities that a database needs: insert, delete, locking etc. Having a reference of LockManager won't affect it. But this is just my thought.
Actually, my question for this topic are:
1. Whether this implementation is correct? I have seen lots of people having LockManager and Datainterface in RemoteDataImpl, and applying lock schema there.
2. Is this the right place to apply business logic(the wrapper class)? I think it is the argument of fat-server vs. fat-client.
Again, thanks for your reponse.
-Kevin
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Kevin,
Think about not having two different wrapper versions of Data for local and remote mode. Assuming that your design decision doesn't include locking in local mode, there is no need for the Data object to interact or know about the LockManager. The sequence below is used by many submissions in this forum:
DataImpl -> LockManager -> Data
Keep in mind that LockManager doesn't have to implement all the public methods in the Data class.
There are lot of things you can do in LockManager including a CleanupThread inner class to remove locks on records locked by dead clients.
Kevin Cao
Ranch Hand

Joined: Jun 19, 2002
Posts: 55
Sai,
Thanks for your advice. After I read some threads from this forum, I convince myself to move the lock schema to RemoteDataImpl and move the business logic to client (Model of MVC).
Kevin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on lock/unlock implementation