org.eclipse.net4j.util.concurrent
Class RWLockManager<OBJECT,CONTEXT>
java.lang.Object
org.eclipse.net4j.util.event.Notifier
org.eclipse.net4j.util.lifecycle.Lifecycle
org.eclipse.net4j.util.concurrent.RWLockManager<OBJECT,CONTEXT>
- All Implemented Interfaces:
- IRWLockManager<OBJECT,CONTEXT>, INotifier, ILifecycle
public class RWLockManager<OBJECT,CONTEXT>
- extends Lifecycle
- implements IRWLockManager<OBJECT,CONTEXT>
Support Multiple reads/no write and upgrade lock from read to write. Many context could request
write
lock at the same time. It will privileges first context that has already
a read
lock. If no one has any read lock, it's "first come first serve".
- Since:
- 2.0
- Author:
- Simon McDuff
Method Summary |
protected void |
changeContext(CONTEXT oldContext,
CONTEXT newContext)
|
protected RWLockManager.LockEntry<OBJECT,CONTEXT> |
getLockEntry(OBJECT objectToLock)
|
protected RWLockManager.LockStrategy<OBJECT,CONTEXT> |
getLockingStrategy(IRWLockManager.LockType type)
|
protected void |
handleLockEntries(CONTEXT context,
RWLockManager.LockEntryHandler<OBJECT,CONTEXT> handler)
|
boolean |
hasLock(IRWLockManager.LockType type,
CONTEXT context,
OBJECT objectToLock)
|
boolean |
hasLockByOthers(IRWLockManager.LockType type,
CONTEXT context,
OBJECT objectToLock)
|
void |
lock(IRWLockManager.LockType type,
CONTEXT context,
Collection<? extends OBJECT> objectsToLock,
long timeout)
|
void |
lock(IRWLockManager.LockType type,
CONTEXT context,
OBJECT objectToLock,
long timeout)
|
void |
unlock(CONTEXT context)
Attempts to release all locks(read and write) for a given context. |
void |
unlock(IRWLockManager.LockType type,
CONTEXT context,
Collection<? extends OBJECT> objectsToUnlock)
Attempts to release for a given locktype, context and objects. |
Methods inherited from class org.eclipse.net4j.util.lifecycle.Lifecycle |
activate, checkActive, checkArg, checkArg, checkInactive, checkNull, checkState, checkState, deactivate, deferredActivate, doActivate, doAfterActivate, doBeforeActivate, doBeforeDeactivate, doDeactivate, dump, getLifecycleState, isActive, isDeferredActivation, toString |
RWLockManager
public RWLockManager()
lock
public void lock(IRWLockManager.LockType type,
CONTEXT context,
Collection<? extends OBJECT> objectsToLock,
long timeout)
throws InterruptedException
- Specified by:
lock
in interface IRWLockManager<OBJECT,CONTEXT>
- Throws:
InterruptedException
- Since:
- 3.0
lock
public void lock(IRWLockManager.LockType type,
CONTEXT context,
OBJECT objectToLock,
long timeout)
throws InterruptedException
- Specified by:
lock
in interface IRWLockManager<OBJECT,CONTEXT>
- Throws:
InterruptedException
- Since:
- 3.0
unlock
public void unlock(IRWLockManager.LockType type,
CONTEXT context,
Collection<? extends OBJECT> objectsToUnlock)
- Attempts to release for a given locktype, context and objects.
- Specified by:
unlock
in interface IRWLockManager<OBJECT,CONTEXT>
- Throws:
IllegalMonitorStateException
- Unlocking objects without lock.- Since:
- 3.0
unlock
public void unlock(CONTEXT context)
- Attempts to release all locks(read and write) for a given context.
- Specified by:
unlock
in interface IRWLockManager<OBJECT,CONTEXT>
hasLock
public boolean hasLock(IRWLockManager.LockType type,
CONTEXT context,
OBJECT objectToLock)
- Specified by:
hasLock
in interface IRWLockManager<OBJECT,CONTEXT>
- Since:
- 3.0
hasLockByOthers
public boolean hasLockByOthers(IRWLockManager.LockType type,
CONTEXT context,
OBJECT objectToLock)
- Specified by:
hasLockByOthers
in interface IRWLockManager<OBJECT,CONTEXT>
- Since:
- 3.0
handleLockEntries
protected void handleLockEntries(CONTEXT context,
RWLockManager.LockEntryHandler<OBJECT,CONTEXT> handler)
- Since:
- 3.1
getLockEntry
protected RWLockManager.LockEntry<OBJECT,CONTEXT> getLockEntry(OBJECT objectToLock)
- Since:
- 3.1
getLockingStrategy
protected RWLockManager.LockStrategy<OBJECT,CONTEXT> getLockingStrategy(IRWLockManager.LockType type)
- Since:
- 3.1
changeContext
protected void changeContext(CONTEXT oldContext,
CONTEXT newContext)
- Since:
- 3.1
Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.