org.eigenbase.runtime
Class ExclusivePipe

java.lang.Object
  extended by org.eigenbase.runtime.Interlock
      extended by org.eigenbase.runtime.ExclusivePipe

public class ExclusivePipe
extends Interlock

A synchronization primitive which allows producer and a consumer to use the same Buffer without treading on each other's feet.

This class is synchronous: only one of the producer and consumer has access at a time. There is only one buffer, and data is not copied.

The byte buffer is fixed in size. The producer writes up to the maximum number of bytes into the buffer, then yields. The consumer must read all of the data in the buffer before yielding back to the producer.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/runtime/ExclusivePipe.java#8 $
Author:
jhyde
"JUnit testcase:"

Field Summary
private  ByteBuffer buf
           
 
Constructor Summary
ExclusivePipe(ByteBuffer buf)
           
 
Method Summary
 void beginReading()
          Acquires the buffer, in preparation for reading.
 void beginWriting()
          Acquires the buffer, in preparation for writing.
 ByteBuffer getBuffer()
          Returns the buffer.
 
Methods inherited from class org.eigenbase.runtime.Interlock
endReading, endWriting
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

private final ByteBuffer buf
Constructor Detail

ExclusivePipe

public ExclusivePipe(ByteBuffer buf)
Method Detail

getBuffer

public ByteBuffer getBuffer()
Returns the buffer.


beginWriting

public void beginWriting()
Description copied from class: Interlock
Acquires the buffer, in preparation for writing.

The producer should call this method. After this call completes, the consumer's call to Interlock.beginReading() will block until the producer has called Interlock.endWriting().

Overrides:
beginWriting in class Interlock

beginReading

public void beginReading()
Description copied from class: Interlock
Acquires the buffer, in preparation for reading.

After this call completes, the producer's call to Interlock.beginWriting() will block until the consumer has called Interlock.endReading().

Overrides:
beginReading in class Interlock