Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A small issue about unreferenced

 
Abhinav Anand
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
There is an issue that needs to be tackeled.
I have implemented my locking mechanism using LockManager using the remote object as the connection identifier. I have ConnectionManager instance binded to the rmireigstry. The clients can get access to RemoteData by calling its getConnection() method. The RemoteData extends the UnicastRemoteObject and implements a remote interface.
To cleanup dead client's locks on database I maintain a HashSet that keeps track of all records locked. That is if a record is locked an Integer object for the record number is added to the hashset. If a record is unlocked that the Integer object for that record number is removed from the hashset.
My RemoteData class implements Unreferenced. So, Whenever the RemoteData object is unreferenced I call the releaseClientLocks() method which iterates through each record locked by this client (achieved by the HashSet already discussed) and unlocks them.
I have also added a finalize() method which when called also performs the same operation as that of unreferenced.
Now, the problem is that till now I have not been able to verify that these algorithms for clearing dead client's lock work. Is there any way to cause the Unreferenced situation to be invoked ??
Is there any problem with the above implementation??
Any suggetions....
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a standalone client and spawn multiple threads to simulate multiple clients. From each of these threads, you lock certain record and don't call unlock(). Wait for about 15 mins and you will see the unreferenced() being invoked by the RMI runtime at the server.
 
Abhinav Anand
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sai,
I will try it and keep you posted.
I heard from you after a long time. How are u doing?
Vishal
 
parthiban subramaniam
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
from what i understand .. unreferenced is not meant for a specific client who holds a stub for this rmi object but for the whole .. the unrefrenced method is invoked by the rmi system when the the no of remote client to this rmi object falls to 0 ..then how are your removing record locks which are locked by this client ??
quote==================
My RemoteData class implements Unreferenced. So, Whenever the RemoteData object is unreferenced I call the releaseClientLocks() method which iterates through each record locked by this client (achieved by the HashSet already discussed) and unlocks them.
===============
in my opinion if such a situation occurs then we can just pass a message to clear all the locks in the lockmanager for this rmi object same applys to finalize .. i wuld sugest you to kill all the clients and wait for sometime to see how it all goes .. or just trust the specifications
cheers,
parthi.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by parthiban subramaniam:
from what i understand .. unreferenced is not meant for a specific client who holds a stub for this rmi object but for the whole .. the unrefrenced method is invoked by the rmi system when the the no of remote client to this rmi object falls to 0 ..then how are your removing record locks which are locked by this client ??

Your understanding is correct about how the RMI runtime determines when to call unreferenced. If you have issued a unique connection to each client then it is obvious which client owns the locks held by the Unreferenced object. There can never be more than one remote reference in such a situation, so when the client dies the reference count falls to 0.

Originally posted by Vishal Sinha:
I have also added a finalize() method which when called also performs the same operation as that of unreferenced.

Bad idea. You don't need a finalize() method. Let GC, DGC and Unreferenced take care of everything for you. Unreferenced is going to called by the DGC anyway, so why do you need finalize()? Just let the object die gracefully when the client connection fails.
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic