pt.ua.concurrent
Class Channel<T>

java.lang.Object
  extended by pt.ua.concurrent.Channel<T>

public class Channel<T>
extends java.lang.Object

A simple module support a (generic) 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
Channel()
          Creates a new channel registering waiting threads..
 
Method Summary
 void interruptWaitingThreads()
          Requests the interruption all threads blocked on current channel.
 void put(T obj)
          Put obj in channel.
 T take()
          Get obj from channel.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Channel

public Channel()
Creates a new channel registering waiting threads..

Method Detail

put

public void put(T obj)
Put obj in channel.

Parameters:
obj - reference to the object to be transmitted

take

public T take()
Get obj from channel.

Returns:
reference to the object received

interruptWaitingThreads

public void interruptWaitingThreads()
                             throws ThreadInterruptedException
Requests the interruption all threads blocked on current channel.

Throws:
ThreadInterruptedException