Class SemaphoreStatus

    • Constructor Detail

      • SemaphoreStatus

        public SemaphoreStatus()
        Default constructor (necessary for the ExternalizableLite interface).
      • 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 UID 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​(UID 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)
      • retainPermitsFor

        protected boolean retainPermitsFor​(Set<UID> setMemberIds)
        Remove all the permits that are not acquired by one of the specified members.
        Parameters:
        setMemberIds - theUIDs of the member to retain the locks for
        Returns:
        true if this semaphore was modified
      • removePermitsFor

        protected boolean removePermitsFor​(UID memberId)
        Remove all the permits that are acquired by a specified member.
        Parameters:
        memberId - the UID 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.