Class AbstractReadWriteAcces<State>

    • Field Summary

      Fields 
      Modifier and Type Field 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.
    • Field Detail

      • rwLock

        protected final java.util.concurrent.locks.ReentrantReadWriteLock rwLock
        This field should be private. It is protected for API compatibility only. Never access this from the outside.
        Noreference:
      • writeLock

        protected final java.util.concurrent.locks.Lock writeLock
        This field should be private. It is protected for API compatibility only. Never access this from the outside.
        Noreference:
      • readLock

        protected final java.util.concurrent.locks.Lock readLock
        This field should be private. It is protected for API compatibility only. Never access this from the outside.
        Noreference:
    • Constructor Detail

      • AbstractReadWriteAcces

        public AbstractReadWriteAcces()
    • Method Detail

      • getState

        protected abstract State getState()
      • readOnly

        public <Result> Result readOnly​(IUnitOfWork<Result,​State> work)
        Description copied from interface: IReadAccess
        Gets a read-only copy of the State and executes work on it. WARNING: the State passed to work can be null. e.g. when reading from a read-only zip/jar entry
        Specified by:
        readOnly in interface IReadAccess<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: IWriteAccess
        Modifies the State by executing work on it. WARNING: the State passed to work can be null.
        Specified by:
        modify in interface IWriteAccess<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 result
        work - - 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 result
        work - - 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 to ReentrantReadWriteLock.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 in ReentrantReadWriteLock as 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: