Class 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
    • Constructor Detail

      • SemaphoreStatus

        public SemaphoreStatus()
        Default constructor (necessary for serialization).
      • SemaphoreStatus

        public SemaphoreStatus​(int initialState)
        Create an instance of SemaphoreStatus.
        Parameters:
        initialState - the initial number of permits available
    • Method Detail

      • acquire

        public boolean acquire​(PermitAcquirer acquirer,
                               int permits)
        Acquires the given number of permits for specified acquirer.
        Parameters:
        acquirer - identity of the acquirer
        permits - 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 acquirer
        releases - the number of permits to release
        Returns:
        true if permits were released; otherwise returns false
      • 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)
        Return true if this semaphore is currently acquired by the specified PermitAcquirer.
        Returns:
        true if this semaphore is currently acquired by the specified PermitAcquirer
      • 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:
        true if 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:
        true if 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:
        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