public abstract class AbstractReadWriteAcces<State> extends java.lang.Object implements IReadAccess<State>, IWriteAccess<State>
IReadAccess.Priority<State>| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.locks.Lock |
readLock
This field should be
private. |
protected java.util.concurrent.locks.ReentrantReadWriteLock |
rwLock
This field should be
private. |
protected java.util.concurrent.locks.Lock |
writeLock
This field should be
private. |
| Constructor and Description |
|---|
AbstractReadWriteAcces() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterModify(State state,
java.lang.Object result,
IUnitOfWork<?,State> work)
is executed within the transaction right after the unit of work has been executed and delivered the result.
|
protected void |
afterReadOnly(State state,
java.lang.Object result,
IUnitOfWork<?,State> work)
is executed within the transaction right after the unit of work has been executed and delivered the result.
|
protected void |
beforeModify(State state,
IUnitOfWork<?,State> work)
Is called before a write lock is obtained
|
protected void |
beforeReadOnly(State state,
IUnitOfWork<?,State> work)
is called before a read lock is obtained
|
protected int |
getReadHoldCount()
Queries the number of reentrant read holds on this lock by the current thread.
|
protected abstract State |
getState() |
protected int |
getWriteHoldCount()
Queries the number of reentrant write holds on this lock by the current thread.
|
<Result> Result |
modify(IUnitOfWork<Result,State> work)
Modifies the State by executing
work on it. |
<Result> Result |
process(IUnitOfWork<Result,State> work)
Upgrades a read transaction to a write transaction, executes the work then downgrades to a read transaction
again.
|
<Result> Result |
readOnly(IUnitOfWork<Result,State> work)
Gets a read-only copy of the State and executes
work on it. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waittryReadOnly, tryReadOnly, tryReadOnlytryModify, tryModify, tryModifyprotected final java.util.concurrent.locks.ReentrantReadWriteLock rwLock
private. It is protected for API compatibility only. Never access
this from the outside.protected final java.util.concurrent.locks.Lock writeLock
private. It is protected for API compatibility only. Never access
this from the outside.protected final java.util.concurrent.locks.Lock readLock
private. It is protected for API compatibility only. Never access
this from the outside.protected abstract State getState()
public <Result> Result readOnly(IUnitOfWork<Result,State> work)
IReadAccesswork on it.
WARNING: the State passed to work can be null.
e.g. when reading from a read-only zip/jar entryreadOnly in interface IReadAccess<State>work - Work to execute on the Stateworkpublic <Result> Result modify(IUnitOfWork<Result,State> work)
IWriteAccesswork on it.
WARNING: the State passed to work can be null.modify in interface IWriteAccess<State>work - Work that modifies the Stateworkpublic <Result> Result process(IUnitOfWork<Result,State> work)
protected void beforeModify(State state, IUnitOfWork<?,State> work)
work - - the unit of work to be processedprotected void beforeReadOnly(State state, IUnitOfWork<?,State> work)
work - - the unit of work to be processedprotected void afterModify(State state, java.lang.Object result, IUnitOfWork<?,State> work)
result - - delivered resultwork - - the unit of work to be processedprotected void afterReadOnly(State state, java.lang.Object result, IUnitOfWork<?,State> work)
result - - delivered resultwork - - the unit of work to be processedprotected int getWriteHoldCount()
ReentrantReadWriteLock.getWriteHoldCount().protected int getReadHoldCount()
ReentrantReadWriteLock as well, but not before version 1.6. This is
why we have to find our own way to work around it.