pt.ua.concurrent
Class Exchanger<T>

java.lang.Object
  extended by pt.ua.concurrent.CObject
      extended by pt.ua.concurrent.Exchanger<T>
All Implemented Interfaces:
InterruptibleAwaitingThreads, SyncCV

public class Exchanger<T>
extends CObject

A simple module support a (generic) exchanger (bidirectional) communication channel between two threads.

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

Author:
Miguel Oliveira e Silva (mos@ua.pt)

Constructor Summary
Exchanger()
          Constructs a new Exchanger registering waiting threads.
Exchanger(boolean registerAwaitingThreads)
          Constructs a new Exchanger.
 
Method Summary
 T exchange(T obj)
          Make the argument of a thread the result of the other (exchange values between two threads).
 
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

Exchanger

public Exchanger()
Constructs a new Exchanger registering waiting threads.


Exchanger

public Exchanger(boolean registerAwaitingThreads)
Constructs a new Exchanger.

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

exchange

public T exchange(T obj)
           throws ThreadInterruptedException
Make the argument of a thread the result of the other (exchange values between two threads).

Parameters:
obj - reference to the object to be exchanged (send)
Returns:
reference to the object exchanged (received)
Throws:
ThreadInterruptedException