EDU.oswego.cs.dl.util.concurrent

Class BoundedBuffer

public class BoundedBuffer extends Object implements BoundedChannel

Efficient array-based bounded buffer class. Adapted from CPJ, chapter 8, which describes design.

[ Introduction to this package. ]

Field Summary
protected Object[]array_
protected intemptySlots_
protected ObjectputMonitor_
Helper monitor to handle puts.
protected intputPtr_
protected inttakePtr_
protected intusedSlots_
Constructor Summary
BoundedBuffer(int capacity)
Create a BoundedBuffer with the given capacity.
BoundedBuffer()
Create a buffer with the current default capacity
Method Summary
intcapacity()
protected Objectextract()
protected voidincEmptySlots()
protected voidincUsedSlots()
protected voidinsert(Object x)
booleanoffer(Object x, long msecs)
Objectpeek()
Objectpoll(long msecs)
voidput(Object x)
intsize()
Return the number of elements in the buffer.
Objecttake()

Field Detail

array_

protected final Object[] array_

emptySlots_

protected int emptySlots_

putMonitor_

protected final Object putMonitor_
Helper monitor to handle puts.

putPtr_

protected int putPtr_

takePtr_

protected int takePtr_

usedSlots_

protected int usedSlots_

Constructor Detail

BoundedBuffer

public BoundedBuffer(int capacity)
Create a BoundedBuffer with the given capacity.

Throws: IllegalArgumentException if capacity less or equal to zero

BoundedBuffer

public BoundedBuffer()
Create a buffer with the current default capacity

Method Detail

capacity

public int capacity()

extract

protected final Object extract()

incEmptySlots

protected void incEmptySlots()

incUsedSlots

protected void incUsedSlots()

insert

protected final void insert(Object x)

offer

public boolean offer(Object x, long msecs)

peek

public Object peek()

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()