jarol
Class Port

java.lang.Object
  extended by jarol.Port

public class Port
extends java.lang.Object

Port is a data transfer point that provides concurrent access for a single-reader and a single-writer. 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
Port()
          Constructs a port with the standard buffer size.
Port(int size)
          Creates a 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.
 boolean 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

Port

public Port()
Constructs a port with the standard buffer size.


Port

public Port(int size)
Creates a port with a specified buffer size.

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

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 boolean write(MessageInterface item)
Writes an item into the buffer. When the buffer is already full, false is returned and the buffer is unchanged.

Parameters:
item - - The element to be added into the buffer.
Returns:
true - if the item was successfully copied into the buffer, false - if the buffer is full

getBufferSize

public int getBufferSize()
Returns the buffer size.

Returns:
buffer size