This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock and Unlock methods

 
Garry Kalra
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I leave the lock and unlock methods empty and
implement the locking and unlocking scheme in a
class used by the Remote Database Server as locking
is not required in the local mode.
Any comments will be appreciated.
Gaurav
 
Todor Todorov
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did almost the same. I left the lock and unlock empty and implemented them in a subclass of Data.
Todor
Originally posted by Garry Kalra:
Can I leave the lock and unlock methods empty and
implement the locking and unlocking scheme in a
class used by the Remote Database Server as locking
is not required in the local mode.
Any comments will be appreciated.
Gaurav

 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I am concerned that's the only way to do it. After all, as you note locking is irrelevant in local mode, therefore if you have your class responsibilities straight then there isn't a single line of locking related code in your Data class. In my case I didn't even have a Data subclass that implemented locking (there was, of course, a network-enabled class with locking that implemented the same interface).
I should note that there are plenty who've taken a contrary view and passed with good marks.
- Peter
 
Garry Kalra
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Information.
Regards
Gaurav
 
Raju, Gentle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Garry,
How did you implement the lock and unlock design. I have thought of different ways and I am listing them here. Please let me know
if you have any better way.

Having bookFlight in the Remote server:
---------------------------------------
I will have a bookflight method defined in the Remote Server and from there call lock, unlock, read, modify adn etc. The exact sequesnce is given below :
try{
lock
read
modify
write
}catch(Exception){
Some Exception
}finally{
unlock
}
Since I put the booking on server-side, if anything should happened, finally(unlock) gets executed no matter what. Also, because clients call this book method, only one client can execute this at a time, I don't even need to track clients.
Having bookFlight method defined in the client only:
----------------------------------------------------
Define bookFlight method the client and in the client call all other methods. Ofcourse this would require many calls to Remote server and my become expensive. There may be probelem here like if client dies after calling lock. Depending upon how these methods are implemented there may be too much of waiting for clients on the lock because of net work delays.

Create come Unique ID for each of the client :
----------------------------------------------
I am also leaning towards having a separate class on the Remote server which creates some number for the each client that connects. Client should call this as a firt call. There after client will pass this numner to bookFlight method. This may require to change the signature of lock and unlock.

Let me know your thoughts on this
 
Raju, Gentle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Appriciate if any body posts their ideas.
 
Raju, Gentle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Garla,
Can you comment on this ?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can certainly implement the business logic on the server, and there are probably quite a few who have done so. The reason I personally didn't is that you are explicitly requested to build your database code for re-use, and I figured it would be most reusable if the entire server was kept completely generic with no application-specific code in it. All business logic was in the client (the traditional thick-client client/server approach, call me a conservative if you want ).
True, you need to think about cleaning up after dead clients (although many haven't and passed). With the connection-oriented approach I took this was completely trivial, just a few lines of code implementing the Unreferenced interface.
- Peter
 
Gennady Shapiro
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have come to respect Peter's opinion, but I have to disagree on the chain of responsilibity. What we have is classic:
client->server->business->Data, or in other terms:
browser->HTTPServer/servlets->EJB->Database
for thread safety we subclass Data to SafeData. SafeData is Data with implemented locking mechanism. SafeData represents a database and it's database' responsibility to provide lock safety.
I am not entirely clear which component implements your locking, Peter.
On the same note, your RMI server seems to be concerned with database lock clean up. The locks have to be set and cleared from within SafeData's methods and with exceptions handled properly you should never have orphant-locks.
Also, even though Data provides public unlock() method I don't think it's meant to be used by RMI server. Your implementation of Unreferenced interface makes your RMI server database-dependant. You rely on the database to provide public unlock() method. What if have to plug in a database that does not have public unlock()?

[This message has been edited by Gennady Shapiro (edited September 28, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic