Class AbstractReadWriteAcces<State>
- java.lang.Object
-
- org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces<State>
-
- All Implemented Interfaces:
IReadAccess<State>,IWriteAccess<State>
public abstract class AbstractReadWriteAcces<State> extends java.lang.Object implements IReadAccess<State>, IWriteAccess<State>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.xtext.util.concurrent.IReadAccess
IReadAccess.Priority<State>
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.locks.LockreadLockThis field should beprivate.protected java.util.concurrent.locks.ReentrantReadWriteLockrwLockThis field should beprivate.protected java.util.concurrent.locks.LockwriteLockThis field should beprivate.
-
Constructor Summary
Constructors Constructor Description AbstractReadWriteAcces()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidafterModify(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 voidafterReadOnly(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 voidbeforeModify(State state, IUnitOfWork<?,State> work)Is called before a write lock is obtainedprotected voidbeforeReadOnly(State state, IUnitOfWork<?,State> work)is called before a read lock is obtainedprotected intgetReadHoldCount()Queries the number of reentrant read holds on this lock by the current thread.protected abstract StategetState()protected intgetWriteHoldCount()Queries the number of reentrant write holds on this lock by the current thread.<Result> Resultmodify(IUnitOfWork<Result,State> work)Modifies the State by executingworkon it.<Result> Resultprocess(IUnitOfWork<Result,State> work)Upgrades a read transaction to a write transaction, executes the work then downgrades to a read transaction again.<Result> ResultreadOnly(IUnitOfWork<Result,State> work)Gets a read-only copy of the State and executesworkon it.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.xtext.util.concurrent.IReadAccess
tryReadOnly, tryReadOnly, tryReadOnly
-
Methods inherited from interface org.eclipse.xtext.util.concurrent.IWriteAccess
tryModify, tryModify, tryModify
-
-
-
-
Field Detail
-
rwLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock rwLock
This field should beprivate. It isprotectedfor API compatibility only. Never access this from the outside.- Noreference:
-
writeLock
protected final java.util.concurrent.locks.Lock writeLock
This field should beprivate. It isprotectedfor API compatibility only. Never access this from the outside.- Noreference:
-
readLock
protected final java.util.concurrent.locks.Lock readLock
This field should beprivate. It isprotectedfor API compatibility only. Never access this from the outside.- Noreference:
-
-
Method Detail
-
getState
protected abstract State getState()
-
readOnly
public <Result> Result readOnly(IUnitOfWork<Result,State> work)
Description copied from interface:IReadAccessGets a read-only copy of the State and executesworkon it. WARNING: the State passed toworkcan be null. e.g. when reading from a read-only zip/jar entry- Specified by:
readOnlyin interfaceIReadAccess<State>- Parameters:
work- Work to execute on the State- Returns:
- The result of executing
work
-
modify
public <Result> Result modify(IUnitOfWork<Result,State> work)
Description copied from interface:IWriteAccessModifies the State by executingworkon it. WARNING: the State passed toworkcan be null.- Specified by:
modifyin interfaceIWriteAccess<State>- Parameters:
work- Work that modifies the State- Returns:
- The result of executing
work
-
process
public <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.- Since:
- 2.4
- Noreference:
-
beforeModify
protected void beforeModify(State state, IUnitOfWork<?,State> work)
Is called before a write lock is obtained- Parameters:
work- - the unit of work to be processed
-
beforeReadOnly
protected void beforeReadOnly(State state, IUnitOfWork<?,State> work)
is called before a read lock is obtained- Parameters:
work- - the unit of work to be processed
-
afterModify
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.- Parameters:
result- - delivered resultwork- - the unit of work to be processed
-
afterReadOnly
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.- Parameters:
result- - delivered resultwork- - the unit of work to be processed
-
getWriteHoldCount
protected int getWriteHoldCount()
Queries the number of reentrant write holds on this lock by the current thread. Delegates toReentrantReadWriteLock.getWriteHoldCount().- Returns:
- the number of holds on the write lock by the current thread, or zero if the write lock is not held by the current thread
- Since:
- 2.4
- Noreference:
-
getReadHoldCount
protected int getReadHoldCount()
Queries the number of reentrant read holds on this lock by the current thread. A reader thread has a hold on a lock for each lock action that is not matched by an unlock action. That functionality is implemented inReentrantReadWriteLockas well, but not before version 1.6. This is why we have to find our own way to work around it.- Returns:
- the number of holds on the read lock by the current thread, or zero if the read lock is not held by the current thread
- Since:
- 2.4
- Noreference:
-
-