org.objectweb.perseus.concurrency.distributed.globallock.lib
Class GlobalLockUser

java.lang.Object
  extended byorg.objectweb.perseus.concurrency.distributed.globallock.lib.GlobalLockUser
All Implemented Interfaces:
GlobalLock, java.io.Serializable

public class GlobalLockUser
extends java.lang.Object
implements GlobalLock, java.io.Serializable

This class the client side of global lock management. A global lock can be associated to each resource that is to be shared between different machines (actually JVMs). Global lock users are coordinated by a GlobalLockCoordinator and communicate with it through the DistResUserService interface. Global locks permit to share a resource between nodes, but not between tasks. One must ensure that the global lock that has been obtained locally is sufficient to satisfy the requirements of the local tasks, and that the local tasks are well synchronized according to the local lock levels they have obtained. Locks are managed in term of level. The lock level must be explicitly upgraded if what is grantable not sufficient to satisfy new local requirements and must be explicitly downgraded to the maximum local requirements when local requirements are released. Locks are cached: the local node indicates what is locally required but internally but what will be locally grantable can be bigger that what has been actually granted. The local lock level can be downgraded to NOLOCK, then later upgraded to some lock value without inducing a request to the coordinator provided the grantable level is bigger thant the new requested level. Lock levels are called back by the coordinator when required. For each shared resource the user state is composed of three lock level - what HAS BEEN granted locally - what CAN BE granted locally - what has been requested to the coordinator (which is hidden to users) Note that the different level of lock and their compatibility is configured through the LockValue interface. This implementation works well with Shared/Exclusive locks but should also work with more complex lock values like intention to read/write lock levels, provided lock levels are strictly ordered. This can be configured when initializing the GlobalLockMasterFactory Note that at the moment, deadlocks are detected with timeout. AE timeout can occur if the lock level cannot be granted because of its use, or because there are some communication problems. However, when in the future fault tolerence will be supported, the two behaviors will be distinguished. In this case, the timeout value will be a hint to indicate a normal amount of time a lock request should be blocked according to the application behaviour. The time spent due to failure correction should not be taken into account.

See Also:
GlobalLockCoordinator, GlobalLockCoordinatorFactory, LockValue, org.objectweb.perseus.distribution.api.DistResUser, org.objectweb.perseus.distribution.api.DistResUserService, Serialized Form

Field Summary
 DistResUserService drus
           
 
Constructor Summary
GlobalLockUser(java.io.Serializable objId, DistResUserService drus)
           
 
Method Summary
 void downgrade(byte lck)
          Notifies a lock downgrade.
 byte getGrantable()
          Get the maximum lock level that can be granted immediately without contacting the global lock coordinator (and so without blocking).
 java.io.Serializable getState(java.lang.Object resId)
           
 void receive(java.lang.Object objId, java.io.Serializable message)
           
protected  void sendCoordinator(java.io.Serializable message)
           
 java.lang.String toString()
           
protected  void trace(java.lang.String s)
           
 void uncache()
          Uncache the lock level.
 GlobalLockWaiter upgrade(byte lck, boolean sync, long timeout)
          Request a lock upgrade.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

drus

public transient DistResUserService drus
Constructor Detail

GlobalLockUser

public GlobalLockUser(java.io.Serializable objId,
                      DistResUserService drus)
Method Detail

getGrantable

public byte getGrantable()
Description copied from interface: GlobalLock
Get the maximum lock level that can be granted immediately without contacting the global lock coordinator (and so without blocking). Note that this is just a hint. There is no guarantee that a subsequent call to upgrade will not block.

Specified by:
getGrantable in interface GlobalLock
Returns:
the maximum grantable lock level

upgrade

public GlobalLockWaiter upgrade(byte lck,
                                boolean sync,
                                long timeout)
                         throws DeadLockException,
                                java.lang.InterruptedException
Description copied from interface: GlobalLock
Request a lock upgrade. In synchronous mode the method returns when the lock has been granted. In asynchronous mode the method returns a waiter object if the request cannot be granted immediately. The caller must call the waitLock method of this object to effectively wait for the lock. It must also call the signalHandled method when the granting has been handled to let other waiters be unblocked. This scheme let the possibility to implement a FIFO handling of requests.

Specified by:
upgrade in interface GlobalLock
Parameters:
lck - the requested lock level
sync - if true the method blocks until the request is granted
timeout - specifies the the maximum time to wait in sync mode
Returns:
a waiter object in asynchronous mode (sync == false) if the request cannot be satisfied immediately.
Throws:
java.lang.InterruptedException - if the thread has been interrupted while waiting
DeadLockException - if the timeout has expired
See Also:
GlobalLockWaiter

downgrade

public void downgrade(byte lck)
Description copied from interface: GlobalLock
Notifies a lock downgrade.

Specified by:
downgrade in interface GlobalLock
Parameters:
lck - the new level wanted for the lock

uncache

public void uncache()
Description copied from interface: GlobalLock
Uncache the lock level. The following call to upgrade will automatically generate a request to the coordinator.

Specified by:
uncache in interface GlobalLock

sendCoordinator

protected void sendCoordinator(java.io.Serializable message)

receive

public void receive(java.lang.Object objId,
                    java.io.Serializable message)

getState

public java.io.Serializable getState(java.lang.Object resId)

toString

public java.lang.String toString()

trace

protected void trace(java.lang.String s)


Copyright © 2000-2002 France Telecom S.A., INRIA, IMAG-LSR All Rights Reserved.