Interface DataSetLock<D extends DataSet>

  • Type Parameters:
    D - generics reference, usually to <? extends DataSet>
    All Superinterfaces:
    java.io.Serializable
    All Known Implementing Classes:
    DefaultDataSetLock

    public interface DataSetLock<D extends DataSet>
    extends java.io.Serializable
    A Simple ReadWriteLock for the DataSet interface and its fluent-design approach Some implementation recommendation: write lock guards behave the same as ReentrantLock with the additional functionality, that a writeLock() and subsequent writeUnLock() mute and, respectively, un-mute the given DataSet's auto-notification states, e.g. example:
      lock.writeLock(); // stores isAutoNotification state
         [..] some other code [..]
      lock.writeUnLock(); // restores isAutoNotification state
     
    However, the recommended usage is using the lock guard primitives, e.g.
     lock.readLockGuard(() -> {
        [..] some read-lock protected code [..]
        return retVal; // N.B. optional return - here: assumes Objects or boxed primitives
     });
     
    Alternatively the best performing option for frequent simple reads without major data processing
     Result ret = lock.readLockGuardOptimistic(() -> {
        [..] some read-lock protected code [..]
              return retVal; // N.B. optional return - here: assumes Objects or boxed primitives
     });
     
    The latter assumes infrequent writes (e.g. a single writer thread) and frequent unobstructed reads (ie. many reader threads). The lock internally acquires the data w/o explicitly locking, checks afterwards if the data has potentially changed a write-lock acquiring thread, and as a automatic fall-back uses the guaranteed (but more expensive) read lock to assure that the read data structure is consistent.
    Author:
    rstein
    • Method Detail

      • readLock

        D readLock()
        reentrant read-lock
        Returns:
        supporting DataSet (fluent design)
      • readLockGuard

        D readLockGuard​(java.lang.Runnable reading)
        Parameters:
        reading - typ. lambda expression that is executed with read lock
        Returns:
        supporting DataSet (fluent design)
      • readLockGuard

        <R> R readLockGuard​(java.util.function.Supplier<R> reading)
        Type Parameters:
        R - generic return type
        Parameters:
        reading - typ. lambda expression that is executed with read lock
        Returns:
        supporting DataSet (fluent design)
      • readLockGuardOptimistic

        D readLockGuardOptimistic​(java.lang.Runnable reading)
        Parameters:
        reading - typ. lambda expression that is executed with read lock
        Returns:
        supporting DataSet (fluent design)
      • readLockGuardOptimistic

        <R> R readLockGuardOptimistic​(java.util.function.Supplier<R> reading)
        Type Parameters:
        R - generic return type
        Parameters:
        reading - typ. lambda expression that is executed with read lock
        Returns:
        supporting DataSet (fluent design)
      • readUnLock

        D readUnLock()
        Returns:
        supporting DataSet (fluent design)
      • writeLock

        D writeLock()
        Returns:
        supporting DataSet (fluent design)
      • writeLockGuard

        D writeLockGuard​(java.lang.Runnable writing)
        Parameters:
        writing - typ. lambda expression that is executed with write lock
        Returns:
        supporting DataSet (fluent design)
      • writeLockGuard

        <R> R writeLockGuard​(java.util.function.Supplier<R> writing)
        Type Parameters:
        R - generic return type
        Parameters:
        writing - typ. lambda expression that is executed with write lock
        Returns:
        supporting DataSet (fluent design)
      • writeUnLock

        D writeUnLock()
        Returns:
        supporting DataSet (fluent design)