org.metasyntactic.thread.concurrent
Interface Takable

All Known Subinterfaces:
BoundedChannel, Channel
All Known Implementing Classes:
BoundedBuffer, LinkedQueue

public interface Takable

This interface exists to enable stricter type checking for channels. A method argument or instance variable in a consumer object can be declared as only a Takable rather than a Channel, in which case a Java compiler will disallow put operations.

Full method descriptions appear in the Channel interface.

See Also:
Channel, Puttable

Method Summary
 java.lang.Object poll(long msecs)
          Return and remove an item from channel only if one is available within msecs milliseconds.
 java.lang.Object take()
          Return and remove an item from channel, possibly waiting indefinitely until such an item exists.
 

Method Detail

take

public java.lang.Object take()
                      throws java.lang.InterruptedException
Return and remove an item from channel, possibly waiting indefinitely until such an item exists.

Returns:
some item from the channel. Different implementations may guarantee various properties (such as FIFO) about that item
Throws:
java.lang.InterruptedException - if the current thread has been interrupted at a point at which interruption is detected, in which case state of the channel is unchanged.

poll

public java.lang.Object poll(long msecs)
                      throws java.lang.InterruptedException
Return and remove an item from channel only if one is available within msecs milliseconds. The time bound is interpreted in a coarse grained, best-effort fashion.

Parameters:
msecs - the number of milliseconds to wait. If less than or equal to zero, the operation does not perform any timed waits, but might still require access to a synchronization lock, which can impose unbounded delay if there is a lot of contention for the channel.
Returns:
some item, or null if the channel is empty.
Throws:
java.lang.InterruptedException - if the current thread has been interrupted at a point at which interruption is detected, in which case state of the channel is unchanged (i.e., equivalent to a false return).