Class ReadWriteLockHolder

  • All Implemented Interfaces:
    com.tangosol.io.ExternalizableLite, com.tangosol.io.pof.PortableObject, Serializable

    public class ReadWriteLockHolder
    extends Object
    implements com.tangosol.io.ExternalizableLite, com.tangosol.io.pof.PortableObject
    A data structure that encapsulates server-side read/write locking logic.
    Since:
    21.12
    Author:
    Aleks Seovic 2021.10.19
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ReadWriteLockHolder.RemoveLocks
      An EntryProcessor that will remove locks for the provided member ID, or all the locks for the members that are not in the cluster any longer (if the specified member ID is null).
    • Constructor Summary

      Constructors 
      Constructor Description
      ReadWriteLockHolder()
      Default constructor for serialization interfaces
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getReadLockCount()
      Return the count of active read locks.
      Set<? extends LockOwner> getReadLocks()
      Return the set of read lock owners.
      LockOwner getWriteLock()
      Return the owner of a write lock, if any.
      boolean isLocked()
      Return true if this lock is currently locked for reads or writes by anyone.
      boolean isLockedBy​(LockOwner owner)
      Return true if this lock is currently locked for reads by the specified owner.
      boolean isLockedByMember​(com.tangosol.util.UUID memberId)
      Return true if this lock is currently locked for either reads or writes by the specified member, regardless of which thread on that member locked it.
      boolean isReadLocked()
      Return true if this lock is currently locked for reads by one or more threads.
      boolean isReadLockedBy​(LockOwner owner)
      Return true if this lock is currently locked for reads by the specified owner.
      boolean isReadLockedByMember​(com.tangosol.util.UUID memberId)
      Return true if this lock is currently locked for reads by the specified member, regardless of which thread on that member locked it.
      boolean isWriteLocked()
      Return true if this lock is currently owned exclusively by anyone.
      boolean isWriteLockedBy​(LockOwner owner)
      Return true if this lock is currently owned exclusively by the specified owner.
      boolean isWriteLockedByClient()
      Return true if this lock is currently owned exclusively by a client.
      boolean isWriteLockedByMember​(com.tangosol.util.UUID memberId)
      Return true if this lock is currently owned exclusively by the specified member, regardless of which thread on that member owns it.
      boolean lockRead​(LockOwner owner)
      Attempt to obtain read lock, and return true if successful.
      boolean lockWrite​(LockOwner owner)
      Attempt to obtain write lock, and return true if successful.
      void readExternal​(com.tangosol.io.pof.PofReader in)  
      void readExternal​(DataInput in)  
      protected boolean removeLocksFor​(com.tangosol.util.UUID memberId)
      Remove all the locks that are owned by a specified member.
      protected boolean retainLocksFor​(Set<com.tangosol.util.UUID> setMemberIds)
      Remove all the locks that are NOT owned by one of the specified members.
      String toString()  
      boolean unlockRead​(LockOwner owner)
      Release read lock, and return true if successful.
      boolean unlockWrite​(LockOwner owner)
      Release write lock, and return true if successful.
      void writeExternal​(com.tangosol.io.pof.PofWriter out)  
      void writeExternal​(DataOutput out)  
    • Constructor Detail

      • ReadWriteLockHolder

        public ReadWriteLockHolder()
        Default constructor for serialization interfaces
    • Method Detail

      • isWriteLocked

        public boolean isWriteLocked()
        Return true if this lock is currently owned exclusively by anyone.
        Returns:
        true if this lock is currently owned exclusively by anyone
      • isReadLocked

        public boolean isReadLocked()
        Return true if this lock is currently locked for reads by one or more threads.
        Returns:
        true if this lock is currently locked for reads by anyone
      • isLocked

        public boolean isLocked()
        Return true if this lock is currently locked for reads or writes by anyone.
        Returns:
        true if this lock is currently locked for reads or writes by anyone
      • isWriteLockedBy

        public boolean isWriteLockedBy​(LockOwner owner)
        Return true if this lock is currently owned exclusively by the specified owner.
        Parameters:
        owner - the lock owner to check
        Returns:
        true if this lock is currently owned exclusively by the specified owner
      • isWriteLockedByMember

        public boolean isWriteLockedByMember​(com.tangosol.util.UUID memberId)
        Return true if this lock is currently owned exclusively by the specified member, regardless of which thread on that member owns it.
        Parameters:
        memberId - the ID of the member to check
        Returns:
        true if this lock is currently owned exclusively by the specified member
      • isReadLockedBy

        public boolean isReadLockedBy​(LockOwner owner)
        Return true if this lock is currently locked for reads by the specified owner.
        Parameters:
        owner - the lock owner to check
        Returns:
        true if this lock is currently locked for reads by the specified owner
      • isReadLockedByMember

        public boolean isReadLockedByMember​(com.tangosol.util.UUID memberId)
        Return true if this lock is currently locked for reads by the specified member, regardless of which thread on that member locked it.
        Parameters:
        memberId - the ID of the member to check
        Returns:
        true if this lock is currently locked for reads by the specified member
      • isLockedBy

        public boolean isLockedBy​(LockOwner owner)
        Return true if this lock is currently locked for reads by the specified owner.
        Parameters:
        owner - the lock owner to check
        Returns:
        true if this lock is currently locked for reads by the specified owner
      • isLockedByMember

        public boolean isLockedByMember​(com.tangosol.util.UUID memberId)
        Return true if this lock is currently locked for either reads or writes by the specified member, regardless of which thread on that member locked it.
        Parameters:
        memberId - the ID of the member to check
        Returns:
        true if this lock is currently locked for either reads or writes by the specified member
      • isWriteLockedByClient

        public boolean isWriteLockedByClient()
        Return true if this lock is currently owned exclusively by a client.
        Returns:
        true if this lock is currently owned exclusively by a client
      • lockWrite

        public boolean lockWrite​(LockOwner owner)
        Attempt to obtain write lock, and return true if successful.
        Parameters:
        owner - the lock owner to obtain the lock for
        Returns:
        true if the lock was successfully obtained
      • unlockWrite

        public boolean unlockWrite​(LockOwner owner)
        Release write lock, and return true if successful.
        Parameters:
        owner - the lock owner to release the lock for
        Returns:
        true if the lock was successfully released
      • lockRead

        public boolean lockRead​(LockOwner owner)
        Attempt to obtain read lock, and return true if successful.
        Parameters:
        owner - the lock owner to obtain the lock for
        Returns:
        true if the lock was successfully obtained
      • unlockRead

        public boolean unlockRead​(LockOwner owner)
        Release read lock, and return true if successful.
        Parameters:
        owner - the lock owner to release the lock for
        Returns:
        true if the lock was successfully released
      • getWriteLock

        public LockOwner getWriteLock()
        Return the owner of a write lock, if any.
        Returns:
        the owner of a write lock, if any; null otherwise
      • getReadLocks

        public Set<? extends LockOwner> getReadLocks()
        Return the set of read lock owners.
        Returns:
        the set of read lock owners; could be empty
      • getReadLockCount

        public int getReadLockCount()
        Return the count of active read locks.
        Returns:
        the count of active read locks
      • removeLocksFor

        protected boolean removeLocksFor​(com.tangosol.util.UUID memberId)
        Remove all the locks that are owned by a specified member.
        Parameters:
        memberId - the UID of a member to remove the locks for
        Returns:
        true if this holder was modified
      • retainLocksFor

        protected boolean retainLocksFor​(Set<com.tangosol.util.UUID> setMemberIds)
        Remove all the locks that are NOT owned by one of the specified members.
        Parameters:
        setMemberIds - the UIDs of the valid members to retain the locks for
        Returns:
        true if this holder was modified
      • readExternal

        public void readExternal​(DataInput in)
                          throws IOException
        Specified by:
        readExternal in interface com.tangosol.io.ExternalizableLite
        Throws:
        IOException
      • writeExternal

        public void writeExternal​(DataOutput out)
                           throws IOException
        Specified by:
        writeExternal in interface com.tangosol.io.ExternalizableLite
        Throws:
        IOException
      • readExternal

        public void readExternal​(com.tangosol.io.pof.PofReader in)
                          throws IOException
        Specified by:
        readExternal in interface com.tangosol.io.pof.PortableObject
        Throws:
        IOException
      • writeExternal

        public void writeExternal​(com.tangosol.io.pof.PofWriter out)
                           throws IOException
        Specified by:
        writeExternal in interface com.tangosol.io.pof.PortableObject
        Throws:
        IOException