Class SemaphoreStatus
- java.lang.Object
-
- com.oracle.coherence.concurrent.internal.SemaphoreStatus
-
- All Implemented Interfaces:
com.tangosol.io.ExternalizableLite,com.tangosol.io.pof.PortableObject,Serializable
public class SemaphoreStatus extends Object implements com.tangosol.io.ExternalizableLite, com.tangosol.io.pof.PortableObject
A data structure that encapsulates server-side semaphore logic.- Since:
- 21.12
- Author:
- Vaso Putica 2021.11.30
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSemaphoreStatus.RemovePermitsAn EntryProcessor that will remove acquired permits for the provided member ID, or all the permits for the members that are not in the cluster any longer.
-
Constructor Summary
Constructors Constructor Description SemaphoreStatus()Default constructor (necessary for serialization).SemaphoreStatus(int initialState)Create an instance ofSemaphoreStatus.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacquire(PermitAcquirer acquirer, int permits)Acquires the given number of permits for specified acquirer.intdrainPermits(PermitAcquirer acquirer)intgetInitialPermits()Returns number of permits that were used to initialise this semaphore.com.tangosol.util.UUIDgetMember()Returns the identity of member who most recently updated the semaphore.intgetPermits()Returns the current number of permits available.Map<PermitAcquirer,Integer>getPermitsMap()Returns an immutable map of acquirers and permits that they acquired.booleanisAcquiredBy(PermitAcquirer acquirer)Returntrueif this semaphore is currently acquired by the specifiedPermitAcquirer.voidreadExternal(com.tangosol.io.pof.PofReader in)voidreadExternal(DataInput in)intreducePermits(PermitAcquirer acquirer, int reductions)booleanrelease(PermitAcquirer acquirer, int releases)Releases the given number of permits, returning them to the semaphore.protected booleanremovePermitsFor(com.tangosol.util.UUID memberId)Remove all the permits that are acquired by a specified member.protected booleanretainPermitsFor(Set<com.tangosol.util.UUID> setMemberIds)Remove all the permits that are not acquired by one of the specified members.voidsetMember(com.tangosol.util.UUID member)Sets the identity of member who most recently updated the semaphore.voidsetPermits(int permits)Sets the number of permits available.StringtoString()voidwriteExternal(com.tangosol.io.pof.PofWriter out)voidwriteExternal(DataOutput out)
-
-
-
Method Detail
-
acquire
public boolean acquire(PermitAcquirer acquirer, int permits)
Acquires the given number of permits for specified acquirer.- Parameters:
acquirer- identity of the acquirerpermits- the number of permits to acquire- Returns:
- true if permits were acquired; otherwise returns false
-
release
public boolean release(PermitAcquirer acquirer, int releases)
Releases the given number of permits, returning them to the semaphore.- Parameters:
acquirer- identity of the acquirerreleases- the number of permits to release- Returns:
- true if permits were released; otherwise returns false
-
drainPermits
public int drainPermits(PermitAcquirer acquirer)
-
reducePermits
public int reducePermits(PermitAcquirer acquirer, int reductions)
-
getPermits
public int getPermits()
Returns the current number of permits available.- Returns:
- the number of permits available
-
setPermits
public void setPermits(int permits)
Sets the number of permits available.- Parameters:
permits- the number of permits available
-
getMember
public com.tangosol.util.UUID getMember()
Returns the identity of member who most recently updated the semaphore.- Returns:
- the identity of member who most recently updated the semaphore.
-
setMember
public void setMember(com.tangosol.util.UUID member)
Sets the identity of member who most recently updated the semaphore.- Parameters:
member- the identity of member who most recently updated the semaphore
-
isAcquiredBy
public boolean isAcquiredBy(PermitAcquirer acquirer)
Returntrueif this semaphore is currently acquired by the specifiedPermitAcquirer.- Returns:
trueif this semaphore is currently acquired by the specifiedPermitAcquirer
-
retainPermitsFor
protected boolean retainPermitsFor(Set<com.tangosol.util.UUID> setMemberIds)
Remove all the permits that are not acquired by one of the specified members.- Parameters:
setMemberIds- the UUIDs of the member to retain the permits for- Returns:
trueif this semaphore was modified
-
removePermitsFor
protected boolean removePermitsFor(com.tangosol.util.UUID memberId)
Remove all the permits that are acquired by a specified member.- Parameters:
memberId- the UUID of a member to remove the permits for- Returns:
trueif this holder was modified
-
getInitialPermits
public int getInitialPermits()
Returns number of permits that were used to initialise this semaphore.- Returns:
- initial number of permits that were used to initialise this semaphore.
-
getPermitsMap
public Map<PermitAcquirer,Integer> getPermitsMap()
Returns an immutable map of acquirers and permits that they acquired.- Returns:
- an immutable map of acquirers and permits that they acquired
-
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
-
-