Package org.jgroups.protocols
Class Locking
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.Locking
-
- Direct Known Subclasses:
CENTRAL_LOCK
,CENTRAL_LOCK2
public abstract class Locking extends Protocol
Base locking protocol, handling most of the protocol communication with other instances. To use distributed locking,LockService
is placed on a channel. LockService talks to a subclass of Locking via events.- Since:
- 2.12
- Author:
- Bela Ban
- See Also:
CENTRAL_LOCK
,CENTRAL_LOCK2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
Locking.ClientCondition
protected class
Locking.ClientLock
Implementation ofLock
.protected class
Locking.ClientLockTable
Manages access to client locksprotected static class
Locking.LockInfoResponse
static class
Locking.LockingHeader
static class
Locking.Request
protected static class
Locking.Response
A response to a request, to be sent back to the requester as a messageprotected class
Locking.ServerCondition
protected class
Locking.ServerLock
Server side queue for handling of lock requests (lock, release).static class
Locking.Type
-
Field Summary
Fields Modifier and Type Field Description protected boolean
bypass_bundling
protected Locking.ClientLockTable
client_lock_table
protected static java.util.concurrent.atomic.AtomicInteger
current_lock_id
protected Address
local_addr
protected java.util.Set<LockNotification>
lock_listeners
protected java.util.concurrent.locks.Lock[]
lock_stripes
protected int
lock_striping_size
protected java.util.concurrent.ConcurrentMap<java.lang.String,Locking.ServerLock>
server_locks
protected View
view
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description Locking()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.util.concurrent.locks.Lock
_getLock(java.lang.String lock_name)
Gets a lock from locks based on the hash of the lock namevoid
addLockListener(LockNotification listener)
protected Locking.ClientLock
createLock(java.lang.String lock_name, Owner owner)
java.lang.Object
down(Event evt)
An event is to be sent down the stack.java.lang.String
getAddress()
boolean
getBypassBundling()
protected Locking.ClientLock
getLock(java.lang.String name)
protected Locking.ClientLock
getLock(java.lang.String name, boolean create_if_absent)
int
getNumClientLocks()
int
getNumServerLocks()
protected Owner
getOwner()
java.lang.String
getView()
protected void
handleAwaitRequest(java.lang.String lock_name, Owner owner)
protected void
handleCreateAwaitingRequest(java.lang.String lock_name, Owner owner)
protected void
handleCreateLockRequest(java.lang.String lock_name, Owner owner)
protected void
handleDeleteAwaitingRequest(java.lang.String lock_name, Owner owner)
protected void
handleDeleteAwaitRequest(java.lang.String lock_name, Owner owner)
protected void
handleDeleteLockRequest(java.lang.String lock_name)
protected void
handleLockDeniedResponse(java.lang.String lock_name, int lock_id, Owner owner)
protected void
handleLockGrantedResponse(java.lang.String lock_name, int lock_id, Owner owner)
protected void
handleLockInfoRequest(Address requester)
protected void
handleLockInfoResponse(Address sender, Locking.Request rsp)
protected void
handleLockReleasedResponse(java.lang.String lock_name, int lock_id, Owner owner)
protected void
handleLockRequest(Locking.Request req)
protected void
handleLockRevoked(Locking.Request rsp)
protected void
handleRequest(Locking.Request req)
protected void
handleSignalRequest(Locking.Request req)
protected void
handleSignalResponse(java.lang.String lock_name, Owner owner)
protected void
handleView(View view)
void
init()
Called after instance has been created (null constructor) and before protocol is started.protected void
notifyAwaited(java.lang.String lock_name, Owner owner)
protected void
notifyAwaiting(java.lang.String lock_name, Owner owner)
protected void
notifyLockCreated(java.lang.String lock_name)
protected void
notifyLockDeleted(java.lang.String lock_name)
protected void
notifyLocked(java.lang.String lock_name, Owner owner)
protected void
notifyLockRevoked(java.lang.String lock_name, Owner current_owner)
protected void
notifyUnlocked(java.lang.String lock_name, Owner owner)
java.lang.String
printLocks()
java.lang.Object
printServerLocks()
void
removeLockListener(LockNotification listener)
protected void
requestReceived(Locking.Request req)
protected void
send(Address dest, Locking.Request req)
protected abstract void
sendAwaitConditionRequest(java.lang.String lock_name, Owner owner)
protected abstract void
sendDeleteAwaitConditionRequest(java.lang.String lock_name, Owner owner)
protected abstract void
sendGrantLockRequest(java.lang.String lock_name, int lock_id, Owner owner, long timeout, boolean is_trylock)
protected void
sendLockResponse(Locking.Type type, Owner dest, java.lang.String lock_name, int lock_id)
protected abstract void
sendReleaseLockRequest(java.lang.String lock_name, int lock_id, Owner owner)
protected void
sendRequest(Address dest, Locking.Type type, java.lang.String lock_name, int lock_id, Owner owner, long timeout, boolean is_trylock)
protected void
sendRequest(Address dest, Locking.Type type, java.lang.String lock_name, Owner owner, long timeout, boolean is_trylock)
protected abstract void
sendSignalConditionRequest(java.lang.String lock_name, boolean all)
protected void
sendSignalResponse(Owner dest, java.lang.String lock_name)
void
setBypassBundling(boolean bypass_bundling)
void
unlockAll()
void
unlockForce(java.lang.String lock_name)
java.lang.Object
up(Event evt)
An event was received from the protocol below.java.lang.Object
up(Message msg)
A single message was received.-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, destroy, down, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, start, statsEnabled, stop, up
-
-
-
-
Field Detail
-
bypass_bundling
protected boolean bypass_bundling
-
lock_striping_size
protected int lock_striping_size
-
local_addr
protected Address local_addr
-
view
protected View view
-
server_locks
protected final java.util.concurrent.ConcurrentMap<java.lang.String,Locking.ServerLock> server_locks
-
lock_stripes
protected java.util.concurrent.locks.Lock[] lock_stripes
-
client_lock_table
protected final Locking.ClientLockTable client_lock_table
-
lock_listeners
protected final java.util.Set<LockNotification> lock_listeners
-
current_lock_id
protected static final java.util.concurrent.atomic.AtomicInteger current_lock_id
-
-
Method Detail
-
getBypassBundling
public boolean getBypassBundling()
-
setBypassBundling
public void setBypassBundling(boolean bypass_bundling)
-
addLockListener
public void addLockListener(LockNotification listener)
-
removeLockListener
public void removeLockListener(LockNotification listener)
-
getAddress
public java.lang.String getAddress()
-
getView
public java.lang.String getView()
-
getNumServerLocks
public int getNumServerLocks()
-
getNumClientLocks
public int getNumClientLocks()
-
init
public void init() throws java.lang.Exception
Description copied from class:Protocol
Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.
-
down
public java.lang.Object down(Event evt)
Description copied from class:Protocol
An event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down()
.
-
up
public java.lang.Object up(Event evt)
Description copied from class:Protocol
An event was received from the protocol below. Usually the current protocol will want to examine the event type and - depending on its type - perform some computation (e.g. removing headers from a MSG event type, or updating the internal membership list when receiving a VIEW_CHANGE event). Finally the event is either a) discarded, or b) an event is sent down the stack usingdown_prot.down()
or c) the event (or another event) is sent up the stack usingup_prot.up()
.
-
up
public java.lang.Object up(Message msg)
Description copied from class:Protocol
A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
-
requestReceived
protected void requestReceived(Locking.Request req)
-
handleRequest
protected void handleRequest(Locking.Request req)
-
getLock
protected Locking.ClientLock getLock(java.lang.String name)
-
getLock
protected Locking.ClientLock getLock(java.lang.String name, boolean create_if_absent)
-
unlockAll
public void unlockAll()
-
unlockForce
public void unlockForce(java.lang.String lock_name)
-
printLocks
public java.lang.String printLocks()
-
printServerLocks
public java.lang.Object printServerLocks()
-
handleView
protected void handleView(View view)
-
createLock
protected Locking.ClientLock createLock(java.lang.String lock_name, Owner owner)
-
_getLock
protected java.util.concurrent.locks.Lock _getLock(java.lang.String lock_name)
Gets a lock from locks based on the hash of the lock name
-
getOwner
protected Owner getOwner()
-
sendGrantLockRequest
protected abstract void sendGrantLockRequest(java.lang.String lock_name, int lock_id, Owner owner, long timeout, boolean is_trylock)
-
sendReleaseLockRequest
protected abstract void sendReleaseLockRequest(java.lang.String lock_name, int lock_id, Owner owner)
-
sendAwaitConditionRequest
protected abstract void sendAwaitConditionRequest(java.lang.String lock_name, Owner owner)
-
sendSignalConditionRequest
protected abstract void sendSignalConditionRequest(java.lang.String lock_name, boolean all)
-
sendDeleteAwaitConditionRequest
protected abstract void sendDeleteAwaitConditionRequest(java.lang.String lock_name, Owner owner)
-
sendRequest
protected void sendRequest(Address dest, Locking.Type type, java.lang.String lock_name, Owner owner, long timeout, boolean is_trylock)
-
sendRequest
protected void sendRequest(Address dest, Locking.Type type, java.lang.String lock_name, int lock_id, Owner owner, long timeout, boolean is_trylock)
-
sendLockResponse
protected void sendLockResponse(Locking.Type type, Owner dest, java.lang.String lock_name, int lock_id)
-
sendSignalResponse
protected void sendSignalResponse(Owner dest, java.lang.String lock_name)
-
send
protected void send(Address dest, Locking.Request req)
-
handleLockRequest
protected void handleLockRequest(Locking.Request req)
-
handleLockGrantedResponse
protected void handleLockGrantedResponse(java.lang.String lock_name, int lock_id, Owner owner)
-
handleLockReleasedResponse
protected void handleLockReleasedResponse(java.lang.String lock_name, int lock_id, Owner owner)
-
handleLockDeniedResponse
protected void handleLockDeniedResponse(java.lang.String lock_name, int lock_id, Owner owner)
-
handleLockInfoRequest
protected void handleLockInfoRequest(Address requester)
-
handleLockInfoResponse
protected void handleLockInfoResponse(Address sender, Locking.Request rsp)
-
handleLockRevoked
protected void handleLockRevoked(Locking.Request rsp)
-
handleAwaitRequest
protected void handleAwaitRequest(java.lang.String lock_name, Owner owner)
-
handleDeleteAwaitRequest
protected void handleDeleteAwaitRequest(java.lang.String lock_name, Owner owner)
-
handleSignalResponse
protected void handleSignalResponse(java.lang.String lock_name, Owner owner)
-
handleSignalRequest
protected void handleSignalRequest(Locking.Request req)
-
handleCreateLockRequest
protected void handleCreateLockRequest(java.lang.String lock_name, Owner owner)
-
handleDeleteLockRequest
protected void handleDeleteLockRequest(java.lang.String lock_name)
-
handleCreateAwaitingRequest
protected void handleCreateAwaitingRequest(java.lang.String lock_name, Owner owner)
-
handleDeleteAwaitingRequest
protected void handleDeleteAwaitingRequest(java.lang.String lock_name, Owner owner)
-
notifyLockCreated
protected void notifyLockCreated(java.lang.String lock_name)
-
notifyLockDeleted
protected void notifyLockDeleted(java.lang.String lock_name)
-
notifyLockRevoked
protected void notifyLockRevoked(java.lang.String lock_name, Owner current_owner)
-
notifyLocked
protected void notifyLocked(java.lang.String lock_name, Owner owner)
-
notifyUnlocked
protected void notifyUnlocked(java.lang.String lock_name, Owner owner)
-
notifyAwaiting
protected void notifyAwaiting(java.lang.String lock_name, Owner owner)
-
notifyAwaited
protected void notifyAwaited(java.lang.String lock_name, Owner owner)
-
-