• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where would you implement the crashed client code??

 
Derick Potgieter
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I`m using RMI to handle the networking part, but where would i need to
implement the code for a crashed client.

I create a new Database object for each client. and then when they
change any data the record gets locked...

but now what is the client times out and the record does`nt get unlocked??
where can i implement this? i thought about adding a timeout, but is there a way to say if timeout then do this... or finally ???

is it even nessesary to handle this case??

Thanks
Derick
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Derick,

It is not necessary to handle this.

However it can be an interesting exercise to try and work out how to do it, and it is certainly something you would want to think about in real life.

Depending on your instructions, you may not be able to have a timeout value for how long a lock may be kept. You will have to check your instructions to see whether you can or not.

The other things you can think about are:

Since you have a Database object per client, I assume you are using the Database object as the key in your collection of owned locks. In which case you might want to use a WeakHashMap as the collection - if the remote client disconnects (or crashes) there will no longer be a remote reference to the Database object, so it will be automagically removed from the WeakHashMap (after RMI's lease value expires + garbage collector runs). Almost a no brainer solution. (You may want to create a separate daemon thread to monitor when locks disapear and notifyAll waiting threads that a lock has gone).

Alternatively you might want to have your per-client remote object implement the Unreferenced interface. If you do this then when the remote client disconnects (or crashes) then the unreferenced() method in that instance of the remote object will be run (after RMI's lease value expires + garbage collector runs) and you can manually clean up any locks.

Regards, Andrew
 
John Canavan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Derick,

You could implement a �thin client� whereby the lock-update-unlock sequence is implemented by the server. See Stephen�s post in this thread.

Regards,
John

[ June 10, 2004: Message edited by: John Canavan ]
[ June 10, 2004: Message edited by: John Canavan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic