jarol
Class PortEnhanced

java.lang.Object
  extended by jarol.PortEnhanced

public class PortEnhanced
extends java.lang.Object

PortEnhanced is a data transfer point that provides concurrent access for a single-reader and a single-writer with enhanced semantics that will never block the writer. The internal buffer is a pushing buffer, thus the oldest value is replaced with the newest value iff the buffer is full. There is no support for multiple readers or writers. All items that are put and taken from the buffer are cloned, also all items must implement the MessageInterface to provide cloning.

Version:
0.1
Author:
Bernhard Kast, Christoph Kirsch

Constructor Summary
PortEnhanced()
          Constructs an enhanced port with the standard buffer size.
PortEnhanced(int size)
          Creates an enhanced port with a specified buffer size.
 
Method Summary
 int getBufferSize()
          Returns the buffer size.
 MessageInterface read()
          Reads the oldest element from the buffer without blocking.
 void write(MessageInterface item)
          Writes an item into the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PortEnhanced

public PortEnhanced()
Constructs an enhanced port with the standard buffer size.


PortEnhanced

public PortEnhanced(int size)
Creates an enhanced port with a specified buffer size.

Parameters:
size - indicates the size of the buffer
Method Detail

getBufferSize

public int getBufferSize()
Returns the buffer size.

Returns:
buffer size

read

public MessageInterface read()
Reads the oldest element from the buffer without blocking. If the buffer is empty null is returned.

Returns:
oldest element of the buffer

write

public void write(MessageInterface item)
Writes an item into the buffer. When the buffer is already full, the oldest element of the buffer is overwritten with item.

Parameters:
item - - The element to be added into the buffer.