Class ReadWriteLockObjectHolder<T>

  • Type Parameters:
    T - The type of object being held.
    All Implemented Interfaces:
    java.util.concurrent.locks.ReadWriteLock

    public class ReadWriteLockObjectHolder<T>
    extends ObjectHolder<T>
    implements java.util.concurrent.locks.ReadWriteLock
    An object that holds another object and provides read/write lock access to the object. This is a convenience class that is the equivalent of an ObjectHolder governed by a ReadWriteLock. The object holder itself also functions as read/write lock access.
    Author:
    Garret Wilson
    • Constructor Detail

      • ReadWriteLockObjectHolder

        public ReadWriteLockObjectHolder()
        Default constructor to hold null.
      • ReadWriteLockObjectHolder

        public ReadWriteLockObjectHolder​(java.util.concurrent.locks.ReadWriteLock readWriteLock)
        Read write lock constructor.
        Parameters:
        readWriteLock - The lock for controlling access to the properties.
        Throws:
        java.lang.NullPointerException - if the given lock is null.
      • ReadWriteLockObjectHolder

        public ReadWriteLockObjectHolder​(T object)
        Held object constructor.
        Parameters:
        object - The object to hold.
      • ReadWriteLockObjectHolder

        public ReadWriteLockObjectHolder​(T object,
                                         java.util.concurrent.locks.ReadWriteLock readWriteLock)
        Held object and read write lock constructor.
        Parameters:
        object - The object to hold.
        readWriteLock - The lock for controlling access to the properties.
        Throws:
        java.lang.NullPointerException - if the given lock is null.
    • Method Detail

      • readLock

        public java.util.concurrent.locks.Lock readLock()
        Specified by:
        readLock in interface java.util.concurrent.locks.ReadWriteLock
      • writeLock

        public java.util.concurrent.locks.Lock writeLock()
        Specified by:
        writeLock in interface java.util.concurrent.locks.ReadWriteLock
      • getObject

        public T getObject()
        This version returns the object under a read lock.
        Overrides:
        getObject in class ObjectHolder<T>
        Returns:
        The held object.
        See Also:
        readLock()
      • setObject

        public void setObject​(T object)
        Sets the held object. This version sets the object under a write lock.
        Overrides:
        setObject in class ObjectHolder<T>
        Parameters:
        object - The object to hold.
        See Also:
        writeLock()