org.javagroups.blocks
Class DistributedLockManager

java.lang.Object
  |
  +--org.javagroups.blocks.DistributedLockManager
All Implemented Interfaces:
LockManager, TwoPhaseVotingListener

public class DistributedLockManager
extends java.lang.Object
implements TwoPhaseVotingListener, LockManager

Distributed lock manager is responsible for maintaining the lock information consistent on all participating nodes.

Author:
Roman Rokytskyy (rrokytskyy@acm.org)

Inner Class Summary
static class DistributedLockManager.AcquireLockDecree
          This class represents the lock to be released.
static class DistributedLockManager.LockDecree
          This class represents the lock
static class DistributedLockManager.ReleaseLockDecree
          This class represents the lock to be released.
 
Constructor Summary
DistributedLockManager(TwoPhaseVotingAdapter channel, java.lang.Object id)
          Constructor for the DistributedLockManager_cl object.
DistributedLockManager(VotingAdapter voteChannel, java.lang.Object id)
          Create instance of this class.
 
Method Summary
 void abort(java.lang.Object decree)
          Abort phase for the lock acquisition or release.
 boolean commit(java.lang.Object decree)
          Commit phase for the lock acquisition or release.
 void lock(java.lang.Object lockId, java.lang.Object owner, int timeout)
          Locks an object with lockId on behalf of the specified owner.
 boolean prepare(java.lang.Object decree)
          Prepare phase for the lock acquisition or release.
 void unlock(java.lang.Object lockId, java.lang.Object owner)
          Unlocks an object with lockId on behalf of the specified owner.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DistributedLockManager

public DistributedLockManager(VotingAdapter voteChannel,
                              java.lang.Object id)
Create instance of this class.
Parameters:
voteChannel - instance of VotingAdapter that will be used for voting purposes on the lock decrees. voteChannel will be wrapped by the instance of the TwoPhaseVotingAdapter.
id - the unique identifier of this lock manager.

DistributedLockManager

public DistributedLockManager(TwoPhaseVotingAdapter channel,
                              java.lang.Object id)
Constructor for the DistributedLockManager_cl object.
Parameters:
channel - instance of TwoPhaseVotingAdapter that will be used for voting purposes on the lock decrees.
id - the unique identifier of this lock manager.
Method Detail

lock

public void lock(java.lang.Object lockId,
                 java.lang.Object owner,
                 int timeout)
          throws LockNotGrantedException,
                 ChannelException
Locks an object with lockId on behalf of the specified owner.
Specified by:
lock in interface LockManager
Parameters:
lockId - Object representing the object to be locked.
owner - object that requests the lock.
timeout - time during which group members should decide whether to grant a lock or not.
Throws:
LockNotGrantedException - when the lock cannot be granted.
java.lang.ClassCastException - if lockId or owner are not serializable.
ChannelException - if something bad happened to underlying channel.

unlock

public void unlock(java.lang.Object lockId,
                   java.lang.Object owner)
            throws LockNotReleasedException,
                   ChannelException
Unlocks an object with lockId on behalf of the specified owner.
Specified by:
unlock in interface LockManager
Parameters:
lockId - long representing the object to be unlocked.
owner - object that releases the lock.
Throws:
LockOwnerMismatchException - when the lock cannot be released.
java.lang.ClassCastException - if lockId or owner are not serializable.

prepare

public boolean prepare(java.lang.Object decree)
                throws VoteException
Prepare phase for the lock acquisition or release.
Specified by:
prepare in interface TwoPhaseVotingListener
Parameters:
decree - should be an instance LockDecree, if not, we throw VoteException to be ignored by the VoteChannel.
Returns:
true when preparing the lock operation succeeds.
Throws:
VoteException - if we should be ignored during voting.

commit

public boolean commit(java.lang.Object decree)
               throws VoteException
Commit phase for the lock acquisition or release.
Specified by:
commit in interface TwoPhaseVotingListener
Parameters:
decree - should be an instance LockDecree, if not, we throw VoteException to be ignored by the VoteChannel.
Returns:
true when commiting the lock operation succeeds.
Throws:
VoteException - if we should be ignored during voting.

abort

public void abort(java.lang.Object decree)
           throws VoteException
Abort phase for the lock acquisition or release.
Specified by:
abort in interface TwoPhaseVotingListener
Parameters:
decree - should be an instance LockDecree, if not, we throw VoteException to be ignored by the VoteChannel.
Throws:
VoteException - if we should be ignored during voting.


Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.