pt.ua.concurrent
Class FixedBarrier

java.lang.Object
  extended by pt.ua.concurrent.CObject
      extended by pt.ua.concurrent.FixedBarrier
All Implemented Interfaces:
Barrier, InterruptibleAwaitingThreads, SyncCV

public class FixedBarrier
extends CObject
implements Barrier

A fixed sized thread barrier class.

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

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

Constructor Summary
FixedBarrier(int size)
          Constructs a new fixed size barrier for size threads registering waiting threads.
FixedBarrier(int size, boolean registerAwaitingThreads)
          Constructs a new fixed size barrier for size threads.
 
Method Summary
 void await()
          Object's wait replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException;
- supports the registration of waiting threads for interrupt purposes.
 int numberWaitingThreads()
          Number of threads currently waiting on the barrier.
 void setSize(int size)
          Define a new size for the barrier.
 int size()
          Number of threads defined for the barrier.
 
Methods inherited from class pt.ua.concurrent.CObject
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

FixedBarrier

public FixedBarrier(int size)
Constructs a new fixed size barrier for size threads registering waiting threads.

Precondition:
size > 0

Parameters:
size - barrier's number of threads

FixedBarrier

public FixedBarrier(int size,
                    boolean registerAwaitingThreads)
Constructs a new fixed size barrier for size threads.

Precondition:
size > 0

Parameters:
size - barrier's number of threads
registerAwaitingThreads - if true, threads are registered when waiting
Method Detail

setSize

public void setSize(int size)
Define a new size for the barrier. This operation may release the barrier (if waiting equal or exceed size).

Precondition:
size > 0

Parameters:
size - barrier's number of threads

size

public int size()
Description copied from interface: Barrier
Number of threads defined for the barrier.

Specified by:
size in interface Barrier
Returns:
barrier size

numberWaitingThreads

public int numberWaitingThreads()
Description copied from interface: Barrier
Number of threads currently waiting on the barrier.

Specified by:
numberWaitingThreads in interface Barrier
Returns:
number of threads

await

public void await()
           throws ThreadInterruptedException
Description copied from class: CObject
Object's wait replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException;
- supports the registration of waiting threads for interrupt purposes.

Precondition:
syncronizedLockIsMine() - native lock owned by me

Specified by:
await in interface Barrier
Specified by:
await in interface SyncCV
Overrides:
await in class CObject
Throws:
ThreadInterruptedException