org.d_haven.event.impl

Class DefaultPipe

public class DefaultPipe extends AbstractPipe

The default queue implementation is a variable size queue. This queue is thread safe, however the overhead in synchronization costs a few extra milliseconds.

Author: Berin Loritsch

Nested Class Summary
static classDefaultPipe.DefaultPreparedEnqueue
Field Summary
Listm_elements
protected intm_reserve
The number of reserve items.
Constructor Summary
DefaultPipe()
Create an unbounded DefaultPipe.
DefaultPipe(int size)
Construct a new DefaultPipe with the specified number of elements. if the number of elements is greater than zero, then the Pipe is bounded by that number.
DefaultPipe(EnqueuePredicate predicate)
Construct a new DefaultPipe with the supplied EnqueuePredicate.
Method Summary
protected Object[]doDequeue(int numElements)
protected ObjectdoDequeue()
protected Object[]doDequeueAll()
protected voiddoEnqueue(Object[] elements)
protected voiddoEnqueue(Object element)
protected PreparedEnqueuedoPrepareEnqueue(Object[] elements)
static Object[]retrieveElements(List buf, int count)
Removes the given number of elements from the given buf and returns them in an array.
intsize()
Return the number of elements currently in the Pipe.
StringtoString()
Get the string representation of this Pipe.

Field Detail

m_elements

private final List m_elements

m_reserve

protected int m_reserve
The number of reserve items. The reserve items are items that are held in a PreparedEnqueue object, but have not been committed yet.

Constructor Detail

DefaultPipe

public DefaultPipe()
Create an unbounded DefaultPipe.

DefaultPipe

public DefaultPipe(int size)
Construct a new DefaultPipe with the specified number of elements. if the number of elements is greater than zero, then the Pipe is bounded by that number. Otherwise, the Pipe is not bounded at all.

Parameters: size The maximum number of elements in the Pipe. Any number less than 1 means there is no limit.

DefaultPipe

public DefaultPipe(EnqueuePredicate predicate)
Construct a new DefaultPipe with the supplied EnqueuePredicate.

Parameters: predicate the EnqueuePredicate to use

Method Detail

doDequeue

protected Object[] doDequeue(int numElements)

doDequeue

protected Object doDequeue()

doDequeueAll

protected Object[] doDequeueAll()

doEnqueue

protected void doEnqueue(Object[] elements)

doEnqueue

protected void doEnqueue(Object element)

doPrepareEnqueue

protected PreparedEnqueue doPrepareEnqueue(Object[] elements)

retrieveElements

private static Object[] retrieveElements(List buf, int count)
Removes the given number of elements from the given buf and returns them in an array. Trusts the caller to pass in a buffer full of Objects and with at least count elements available.

Parameters: buf to remove elements from, the caller is responsible for synchronizing access count number of elements to remove/return

Returns: requested number of elements

size

public int size()
Return the number of elements currently in the Pipe.

Returns: int representing the number of elements (including the reserved ones).

toString

public String toString()
Get the string representation of this Pipe.

Returns: the string message