• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Lease pattern

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Would you recommend implementation of a leasing system to track client connection loss from server side in order to clean the locking tables appropriately.
If yes would you use net.jini.core.lease.*, or would you implement something from scratch.
Many thanks,
Charles.
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charles,
I'd be careful with anything beyond the scope of core Java. And packages such as net.jini... sound quite exotic to me! The assignment is about solving a problem with standard java technology. Therefore I'd advise you to develop something from scratch (besides: I don't know what "leasing pattern" means - could you explain that to me?)
Thanks!
 
Charles Dupin
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mag,
The leasing pattern: When a client wants to obtain some resource from the server (a lock for example) it must first acquire a Lease (a permission) from the server. This Lease is valid for a certain amount of time. The client must renew the lease before its expiration if it wants to keep the resource.
If the client fails to renew the lease, the server can take action pertaining to this situation. In our case, the server can free the lock and notifyAll. With this pattern the server can easily detect if the client connection breaks.
This involves quite a lot of nice thread programming of course.
Regards,
Charles.
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Charles,
Remember that no timeouts or extra complexity are specified in the requirements. If you give each remote client a unique connection object, you can use RMI's built in unreferenced() functionality to achieve a simple solution for dealing with clients that disconnect while holding one or more locks. Anything beyond that is overkill and just more chance for mistakes. Also, the assignment must be made up entirely of classes from java.* and suncertify.* that are either provided with the JDK or written by you, so any third party classes are strictly off limits.
Pete
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pete is absolutely correct: use of net.jini.core.lease.*, com.borland.jbcl.layout.*, and the like, falls under this stern caveat:

Target Platform
Throughout this exercise, you must use exclusively the Java 2 platform. You are not required to develop your code using any particular implementation of the Java 2 platform, but the submission that you return must have been tested and shown to work under a production (not development) version of the Sun Microsystems' Java 2 platform.
Failure to adhere to these directions will result in automatic failure


On the other hand, I did choose to implement a 60 second lock-lease (configurable in my config.xml file ), mostly to take a small step in the direction of database transaction-rollback functionality, and to demonstrate the "gracefulness" of my server shutdown.
Every "spiffy" feature you add must be adequately commented, however, or you'll end up with a score of 154, like Michael Morris :roll:
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a thought off the top of my head: is the lock and unlock methods the client class calls not essentially an implementation of the lease pattern? The call to lock provides the client the right (i.e. lease) to use the record for X amount of time. Of course, unlock gives up the lease.
If we decided to add the lease pattern on top of the lock/unlock methods, we would essentially have a double lock check; namely:

The double 'lock' is worriesome to me. So my thought was to say in my DESIGN_DECISIONS.txt that the lock/unlock mechanism follows the lease pattern, with the caveat that clients cannot renew a lease. The server researves the right to revoke a clients' lease on any lock if the lease period expires.
Comments?
--Dave.
 
Thomas Fly
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The usual approach to locking is to attach a ClientID to a record, using HashMap. Instead, I use a class that contains the ClientID along with a timestamp & progress counter, which can be checked by the server to decide whether or not to revoke the lock held by a given client.
It's hard to say how big a problem a "stalled" (as opposed to "dead") client would really be in a production environment, however.
There's really not even much of a good reason to attach a ClientID to the locks, except to handle the infrequent occurence of a client dying just after acquiring a lock- but if you're writing an online banking application...
 
Charles Dupin
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,
I do not consider doing a leasing pattern like the one you described here :
lease(recordNum);
lock(recordNum);
unlock(recordNum);
release(recordNum);
Leasing and locking done by two different threads on both sides.
lets say leases are valid 5 seconds
Client X:
Th1---------------------------- Th2---------------
t1-- ask for a lease (5 secs)
t2-- get it tell thread 2 to work --- lock
t3-- renew the lease (5 secs) -----read write
t4-------------------------------- unlock
t5-- quit leasing
t6--
Server:
Th1------------------------- Th2---------------
t1++ give the lease to X(5 secs)
t2-- -------------------------------- check all leases
t3++ give the lease to X(5 secs)
t4-- ----------------------------- --- check all leases
t5--
t6-- -------------------------------- --- find dead lease of X ( > 5 secs), check lock table
for X dead locks

Regards. :roll:
[ November 08, 2002: Message edited by: Charles Dupin ]
[ November 08, 2002: Message edited by: Charles Dupin ]
[ November 08, 2002: Message edited by: Charles Dupin ]
 
Charles Dupin
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the poor readability of the previous message, I dont know how to edit tables with this bulletin board.
Regards
Charles
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Re: tables -- anything you put between [ CODE ] tags will be displayed using a fixed-with font. So you can use good oldfashioned ASCII art.
- Peter
 
Thomas Fly
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Peter den Haan:
Re: tables -- anything you put between [ CODE ] tags will be displayed using a fixed-with font. So you can use good oldfashioned ASCII art.
- Peter



 
Charles Dupin
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to Peter,
I could not make the [CODE] stuff working.
Sorry.
 
Thomas Fly
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just use the CODE button:
 
Charles Dupin
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic