pt.ua.concurrent
Class DynamicBarrier

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

public class DynamicBarrier
extends CObject
implements Barrier

A dynamically 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
DynamicBarrier()
          Constructs a new dynamic barrier registering waiting threads.
DynamicBarrier(boolean registerAwaitingThreads)
          Constructs a new dynamic barrier.
 
Method Summary
 void await()
          Caller will wait until all signed barrier threads are also waiting, situation in which all of them are awakened.
 boolean isSignIn()
          Is current thread registered in barrier?
 int numberWaitingThreads()
          Number of threads currently waiting on the barrier.
 void signIn()
          Add signature of current thread in the barrier.
 void signOut()
          Remove signature of current thread in 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

DynamicBarrier

public DynamicBarrier()
Constructs a new dynamic barrier registering waiting threads.


DynamicBarrier

public DynamicBarrier(boolean registerAwaitingThreads)
Constructs a new dynamic barrier.

Parameters:
registerAwaitingThreads - if true, threads are registered when waiting
Method Detail

isSignIn

public boolean isSignIn()
Is current thread registered in barrier?

Returns:
true, if thread is registered; false otherwise

signIn

public void signIn()
Add signature of current thread in the barrier.

Precondition:
!isSignIn()
Postcondition:
isSignIn()


signOut

public void signOut()
Remove signature of current thread in the barrier.

Precondition:
isSignIn()
Postcondition:
!isSignIn()


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
Caller will wait until all signed barrier threads are also waiting, situation in which all of them are awakened.

Precondition:
isSignIn()

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