Package org.jgroups.blocks
Class DistributedLockManager
java.lang.Object
org.jgroups.blocks.DistributedLockManager
- All Implemented Interfaces:
LockManager
,TwoPhaseVotingListener
,VoteResponseProcessor
,MembershipListener
public class DistributedLockManager
extends Object
implements TwoPhaseVotingListener, LockManager, VoteResponseProcessor, MembershipListener
Distributed lock manager is responsible for maintaining the lock information
consistent on all participating nodes.
- Version:
- $Id: DistributedLockManager.java,v 1.9.4.2 2008/05/22 09:51:25 belaban Exp $
- Author:
- Roman Rokytskyy (rrokytskyy@acm.org), Robert Schaffar-Taurok (robert@fusion.at)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class represents the lock to be released.static class
This class represents the lockstatic class
This class represents the lock that has to be marked as multilockedstatic class
This class represents the lock to be released. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDistributedLockManager
(TwoPhaseVotingAdapter channel, Object id) Constructor for the DistributedLockManager_cl object.DistributedLockManager
(VotingAdapter voteChannel, Object id) Create instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Abort phase for the lock acquisition or release.void
block()
Called (usually by the FLUSH protocol), as an indication that the member should stop sending messages.boolean
Commit phase for the lock acquisition or release.void
Locks an object withlockId
on behalf of the specifiedowner
.boolean
Prepare phase for the lock acquisition or release.boolean
processResponses
(RspList responses, int consensusType, Object decree) Processes the response list and votes like the default processResponses method with the consensusType VOTE_ALL If the result of the voting is false, but this DistributedLockManager owns the lock, the result is changed to true and the lock is released, but marked as multiple locked.void
Called whenever a member is suspected of having crashed, but has not yet been excluded.void
Unlocks an object withlockId
on behalf of the specifiedowner
.void
Unlocks an object withlockId
on behalf of the specifiedowner
.void
void
void
viewAccepted
(View new_view) Remove all locks held by members who left the previous view
-
Field Details
-
log
protected final org.apache.commons.logging.Log log
-
-
Constructor Details
-
DistributedLockManager
Create instance of this class.- Parameters:
voteChannel
- instance ofVotingAdapter
that will be used for voting purposes on the lock decrees. voteChannel() will be wrapped by the instance of theTwoPhaseVotingAdapter
.id
- the unique identifier of this lock manager. todo check if the node with the same id is already in the group.
-
DistributedLockManager
Constructor for the DistributedLockManager_cl object.- Parameters:
channel
- instance ofTwoPhaseVotingAdapter
that will be used for voting purposes on the lock decrees.id
- the unique identifier of this lock manager.- To do:
- check if the node with the same id is already in the group.
-
-
Method Details
-
lock
public void lock(Object lockId, Object owner, int timeout) throws LockNotGrantedException, ChannelException Locks an object withlockId
on behalf of the specifiedowner
.- Specified by:
lock
in interfaceLockManager
- Parameters:
lockId
-Object
representing the object to be locked.owner
- object that requests the lock. This should be the Address of a JGroups member, otherwise we cannot release the locks for a crashed member !timeout
- time during which group members should decide whether to grant a lock or not.- Throws:
LockNotGrantedException
- when the lock cannot be granted.ClassCastException
- if lockId or owner are not serializable.ChannelException
- if something bad happened to underlying channel.
-
unlock
Unlocks an object withlockId
on behalf of the specifiedowner
. since 2.2.9 this method is only a wrapper for unlock(Object lockId, Object owner, boolean releaseMultiLocked). Use that with releaseMultiLocked set to true if you want to be able to release multiple locked locks (for example after a merge)- Specified by:
unlock
in interfaceLockManager
- Parameters:
lockId
-long
representing the object to be unlocked.owner
- object that releases the lock.- Throws:
LockNotReleasedException
- when the lock cannot be released.ClassCastException
- if lockId or owner are not serializable.ChannelException
-
unlock
public void unlock(Object lockId, Object owner, long timeout) throws LockNotReleasedException, ChannelException -
unlock
public void unlock(Object lockId, Object owner, boolean releaseMultiLocked) throws LockNotReleasedException, ChannelException, LockMultiLockedException Unlocks an object withlockId
on behalf of the specifiedowner
.- Specified by:
unlock
in interfaceLockManager
- Parameters:
lockId
-long
representing the object to be unlocked.owner
- object that releases the lock.releaseMultiLocked
- releases also multiple locked locks. (eg. locks that are locked by another DLM after a merge)- Throws:
LockNotReleasedException
- when the lock cannot be released.ClassCastException
- if lockId or owner are not serializable.LockMultiLockedException
- if releaseMultiLocked is true and a multiple locked lock has been released.ChannelException
-
unlock
public void unlock(Object lockId, Object owner, boolean releaseMultiLocked, long timeout) throws LockNotReleasedException, ChannelException, LockMultiLockedException -
prepare
Prepare phase for the lock acquisition or release.- Specified by:
prepare
in interfaceTwoPhaseVotingListener
- Parameters:
decree
- should be an instanceLockDecree
, if not, we throwVoteException
to be ignored by theVoteChannel
.- Returns:
true
when preparing the lock operation succeeds.- Throws:
VoteException
- if we should be ignored during voting.
-
commit
Commit phase for the lock acquisition or release.- Specified by:
commit
in interfaceTwoPhaseVotingListener
- Parameters:
decree
- should be an instanceLockDecree
, if not, we throwVoteException
to be ignored by theVoteChannel
.- Returns:
true
when commiting the lock operation succeeds.- Throws:
VoteException
- if we should be ignored during voting.
-
abort
Abort phase for the lock acquisition or release.- Specified by:
abort
in interfaceTwoPhaseVotingListener
- Parameters:
decree
- should be an instanceLockDecree
, if not, we throwVoteException
to be ignored by theVoteChannel
.- Throws:
VoteException
- if we should be ignored during voting.
-
processResponses
public boolean processResponses(RspList responses, int consensusType, Object decree) throws ChannelException Processes the response list and votes like the default processResponses method with the consensusType VOTE_ALL If the result of the voting is false, but this DistributedLockManager owns the lock, the result is changed to true and the lock is released, but marked as multiple locked. (only in the prepare state to reduce traffic)Note: we do not support voting in case of Byzantine failures, i.e. when the node responds with the fault message.
- Specified by:
processResponses
in interfaceVoteResponseProcessor
- Parameters:
responses
- The responsesconsensusType
- The consensusType of the votedecree
- The vote decree- Returns:
- boolean
- Throws:
ChannelException
-
viewAccepted
Remove all locks held by members who left the previous view- Specified by:
viewAccepted
in interfaceMembershipListener
-
suspect
Description copied from interface:MembershipListener
Called whenever a member is suspected of having crashed, but has not yet been excluded.- Specified by:
suspect
in interfaceMembershipListener
-
block
public void block()Description copied from interface:MembershipListener
Called (usually by the FLUSH protocol), as an indication that the member should stop sending messages. Any messages sent after returning from this callback might get blocked by the FLUSH protocol. When the FLUSH protocol is done, and messages can be sent again, the FLUSH protocol will simply unblock all pending messages. If a callback for unblocking is desired, implementExtendedMembershipListener.unblock()
. Note that block() is the equivalent of reception of a BlockEvent in the pull mode.- Specified by:
block
in interfaceMembershipListener
-