pt.ua.concurrent
Class BoundedSemaphore

java.lang.Object
  extended by pt.ua.concurrent.CObject
      extended by pt.ua.concurrent.Semaphore
          extended by pt.ua.concurrent.BoundedSemaphore
All Implemented Interfaces:
InterruptibleAwaitingThreads, SyncCV
Direct Known Subclasses:
BinarySemaphore

public class BoundedSemaphore
extends Semaphore

Bounded semaphore class (a semaphore that cannot exceed a given value).

This class follows DbC(tm) methodology (Wikipedia). Where possible, contracts are implement with native's Java assert.

Version:
0.5, November 2011
Author:
Miguel Oliveira e Silva (mos@ua.pt)

Constructor Summary
BoundedSemaphore(int maxCount)
          Creates a semaphore bounded by a maximum value of maxCount
BoundedSemaphore(int maxCount, int initialCount)
          Creates a semaphore bounded by a maximum value of maxCount and starting with value initialCount
 
Method Summary
 int maxCount()
          Bound value.
 void release()
          Releases the semaphore.
 
Methods inherited from class pt.ua.concurrent.Semaphore
aquire
 
Methods inherited from class pt.ua.concurrent.CObject
await, await, await, broadcast, interruptWaitingThreads, lockIsMine, registerAwaitingThreads, signal, syncronizedLockIsMine
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundedSemaphore

public BoundedSemaphore(int maxCount)
Creates a semaphore bounded by a maximum value of maxCount

Precondition:
maxCount > 0 - positive bound

Parameters:
maxCount - bound value

BoundedSemaphore

public BoundedSemaphore(int maxCount,
                        int initialCount)
Creates a semaphore bounded by a maximum value of maxCount and starting with value initialCount

Precondition:
maxCount > 0 - positive bound
initialCount >= 0 && initialCount <= maxCount - valid count

Parameters:
maxCount - bound value
initialCount - initial value
Method Detail

release

public void release()
Releases the semaphore.

Precondition:
count < maxCount - counter within bound limits

Overrides:
release in class Semaphore

maxCount

public int maxCount()
Bound value.

Returns:
the value