EDU.oswego.cs.dl.util.concurrent

Class BoundedBuffer

Implemented Interfaces:
BoundedChannel, Channel, Puttable, Takable

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 int
emptySlots_
protected Object
putMonitor_
Helper monitor to handle puts.
protected int
putPtr_
protected int
takePtr_
protected int
usedSlots_

Constructor Summary

BoundedBuffer()
Create a buffer with the current default capacity
BoundedBuffer(int capacity)
Create a BoundedBuffer with the given capacity.

Method Summary

int
capacity()
protected Object
extract()
protected void
incEmptySlots()
protected void
incUsedSlots()
protected void
insert(Object x)
boolean
offer(Object x, long msecs)
Object
peek()
Object
poll(long msecs)
void
put(Object x)
int
size()
Return the number of elements in the buffer.
Object
take()

Field Details

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 Details

BoundedBuffer

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


BoundedBuffer

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

Method Details

capacity

public int capacity()
Specified by:
capacity in interface BoundedChannel


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)
            throws InterruptedException
Specified by:
offer in interface Channel
offer in interface Puttable


peek

public Object peek()
Specified by:
peek in interface Channel


poll

public Object poll(long msecs)
            throws InterruptedException
Specified by:
poll in interface Channel
poll in interface Takable


put

public void put(Object x)
            throws InterruptedException
Specified by:
put in interface Channel
put in interface Puttable


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()
            throws InterruptedException
Specified by:
take in interface Channel
take in interface Takable