EDU.oswego.cs.dl.util.concurrent

Class SemaphoreControlledChannel

public abstract class SemaphoreControlledChannel extends Object implements BoundedChannel

Abstract class for channels that use Semaphores to control puts and takes.

[ Introduction to this package. ]

Field Summary
protected intcapacity_
protected SemaphoreputGuard_
protected SemaphoretakeGuard_
Constructor Summary
SemaphoreControlledChannel(int capacity)
Create a channel with the given capacity and default semaphore implementation
SemaphoreControlledChannel(int capacity, Class semaphoreClass)
Create a channel with the given capacity and semaphore implementations instantiated from the supplied class
Method Summary
intcapacity()
protected abstract Objectextract()
Internal mechanics of take.
protected abstract voidinsert(Object x)
Internal mechanics of put.
booleanoffer(Object x, long msecs)
Objectpoll(long msecs)
voidput(Object x)
intsize()
Return the number of elements in the buffer.
Objecttake()

Field Detail

capacity_

protected int capacity_

putGuard_

protected final Semaphore putGuard_

takeGuard_

protected final Semaphore takeGuard_

Constructor Detail

SemaphoreControlledChannel

public SemaphoreControlledChannel(int capacity)
Create a channel with the given capacity and default semaphore implementation

Throws: IllegalArgumentException if capacity less or equal to zero

SemaphoreControlledChannel

public SemaphoreControlledChannel(int capacity, Class semaphoreClass)
Create a channel with the given capacity and semaphore implementations instantiated from the supplied class

Throws: IllegalArgumentException if capacity less or equal to zero. NoSuchMethodException If class does not have constructor that intializes permits SecurityException if constructor information not accessible InstantiationException if semaphore class is abstract IllegalAccessException if constructor cannot be called InvocationTargetException if semaphore constructor throws an exception

Method Detail

capacity

public int capacity()

extract

protected abstract Object extract()
Internal mechanics of take.

insert

protected abstract void insert(Object x)
Internal mechanics of put.

offer

public boolean offer(Object x, long msecs)

poll

public Object poll(long msecs)

put

public void put(Object x)

size

public int size()
Return the number of elements in the buffer. This is only a snapshot value, that may change immediately after returning.

take

public Object take()