Class ReadWriteLockHolder
- java.lang.Object
-
- com.oracle.coherence.concurrent.locks.internal.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 classReadWriteLockHolder.RemoveLocksAn 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 isnull).
-
Constructor Summary
Constructors Constructor Description ReadWriteLockHolder()Default constructor for serialization interfaces
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetReadLockCount()Return the count of active read locks.Set<? extends LockOwner>getReadLocks()Return the set of read lock owners.LockOwnergetWriteLock()Return the owner of a write lock, if any.booleanisLocked()Returntrueif this lock is currently locked for reads or writes by anyone.booleanisLockedBy(LockOwner owner)Returntrueif this lock is currently locked for reads by the specified owner.booleanisLockedByMember(com.tangosol.util.UUID memberId)Returntrueif this lock is currently locked for either reads or writes by the specified member, regardless of which thread on that member locked it.booleanisReadLocked()Returntrueif this lock is currently locked for reads by one or more threads.booleanisReadLockedBy(LockOwner owner)Returntrueif this lock is currently locked for reads by the specified owner.booleanisReadLockedByMember(com.tangosol.util.UUID memberId)Returntrueif this lock is currently locked for reads by the specified member, regardless of which thread on that member locked it.booleanisWriteLocked()Returntrueif this lock is currently owned exclusively by anyone.booleanisWriteLockedBy(LockOwner owner)Returntrueif this lock is currently owned exclusively by the specified owner.booleanisWriteLockedByClient()Returntrueif this lock is currently owned exclusively by a client.booleanisWriteLockedByMember(com.tangosol.util.UUID memberId)Returntrueif this lock is currently owned exclusively by the specified member, regardless of which thread on that member owns it.booleanlockRead(LockOwner owner)Attempt to obtain read lock, and returntrueif successful.booleanlockWrite(LockOwner owner)Attempt to obtain write lock, and returntrueif successful.voidreadExternal(com.tangosol.io.pof.PofReader in)voidreadExternal(DataInput in)protected booleanremoveLocksFor(com.tangosol.util.UUID memberId)Remove all the locks that are owned by a specified member.protected booleanretainLocksFor(Set<com.tangosol.util.UUID> setMemberIds)Remove all the locks that are NOT owned by one of the specified members.StringtoString()booleanunlockRead(LockOwner owner)Release read lock, and returntrueif successful.booleanunlockWrite(LockOwner owner)Release write lock, and returntrueif successful.voidwriteExternal(com.tangosol.io.pof.PofWriter out)voidwriteExternal(DataOutput out)
-
-
-
Method Detail
-
isWriteLocked
public boolean isWriteLocked()
Returntrueif this lock is currently owned exclusively by anyone.- Returns:
trueif this lock is currently owned exclusively by anyone
-
isReadLocked
public boolean isReadLocked()
Returntrueif this lock is currently locked for reads by one or more threads.- Returns:
trueif this lock is currently locked for reads by anyone
-
isLocked
public boolean isLocked()
Returntrueif this lock is currently locked for reads or writes by anyone.- Returns:
trueif this lock is currently locked for reads or writes by anyone
-
isWriteLockedBy
public boolean isWriteLockedBy(LockOwner owner)
Returntrueif this lock is currently owned exclusively by the specified owner.- Parameters:
owner- the lock owner to check- Returns:
trueif this lock is currently owned exclusively by the specified owner
-
isWriteLockedByMember
public boolean isWriteLockedByMember(com.tangosol.util.UUID memberId)
Returntrueif 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:
trueif this lock is currently owned exclusively by the specified member
-
isReadLockedBy
public boolean isReadLockedBy(LockOwner owner)
Returntrueif this lock is currently locked for reads by the specified owner.- Parameters:
owner- the lock owner to check- Returns:
trueif this lock is currently locked for reads by the specified owner
-
isReadLockedByMember
public boolean isReadLockedByMember(com.tangosol.util.UUID memberId)
Returntrueif 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:
trueif this lock is currently locked for reads by the specified member
-
isLockedBy
public boolean isLockedBy(LockOwner owner)
Returntrueif this lock is currently locked for reads by the specified owner.- Parameters:
owner- the lock owner to check- Returns:
trueif this lock is currently locked for reads by the specified owner
-
isLockedByMember
public boolean isLockedByMember(com.tangosol.util.UUID memberId)
Returntrueif 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:
trueif this lock is currently locked for either reads or writes by the specified member
-
isWriteLockedByClient
public boolean isWriteLockedByClient()
Returntrueif this lock is currently owned exclusively by a client.- Returns:
trueif this lock is currently owned exclusively by a client
-
lockWrite
public boolean lockWrite(LockOwner owner)
Attempt to obtain write lock, and returntrueif successful.- Parameters:
owner- the lock owner to obtain the lock for- Returns:
trueif the lock was successfully obtained
-
unlockWrite
public boolean unlockWrite(LockOwner owner)
Release write lock, and returntrueif successful.- Parameters:
owner- the lock owner to release the lock for- Returns:
trueif the lock was successfully released
-
lockRead
public boolean lockRead(LockOwner owner)
Attempt to obtain read lock, and returntrueif successful.- Parameters:
owner- the lock owner to obtain the lock for- Returns:
trueif the lock was successfully obtained
-
unlockRead
public boolean unlockRead(LockOwner owner)
Release read lock, and returntrueif successful.- Parameters:
owner- the lock owner to release the lock for- Returns:
trueif 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;
nullotherwise
-
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:
trueif 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:
trueif this holder was modified
-
readExternal
public void readExternal(DataInput in) throws IOException
- Specified by:
readExternalin interfacecom.tangosol.io.ExternalizableLite- Throws:
IOException
-
writeExternal
public void writeExternal(DataOutput out) throws IOException
- Specified by:
writeExternalin interfacecom.tangosol.io.ExternalizableLite- Throws:
IOException
-
readExternal
public void readExternal(com.tangosol.io.pof.PofReader in) throws IOException- Specified by:
readExternalin interfacecom.tangosol.io.pof.PortableObject- Throws:
IOException
-
writeExternal
public void writeExternal(com.tangosol.io.pof.PofWriter out) throws IOException- Specified by:
writeExternalin interfacecom.tangosol.io.pof.PortableObject- Throws:
IOException
-
-