com.newisys.dv
Class Mailbox<T>

java.lang.Object
  extended by com.newisys.dv.Mailbox<T>
Type Parameters:
T - the type of object contained by this mailbox

public final class Mailbox<T>
extends Object

Implements an unlimited size, blocking FIFO using a SimulationManager.


Constructor Summary
Mailbox(SimulationManager simManager)
          Constructs a new mailbox with a generated name using the given simulation manager.
Mailbox(SimulationManager simManager, String name)
          Constructs a new mailbox with the given name using the given simulation manager.
 
Method Summary
 T getNoWait()
          Returns the first item in the mailbox.
 T getWait()
          Returns the first item in the mailbox.
 T peekNoWait()
          Returns the first item in the mailbox.
 T peekWait()
          Returns the first item in the mailbox.
 void put(T item)
          Puts the item into the mailbox in the last position.
 int size()
          Returns the number of items in the mailbox.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Mailbox

public Mailbox(SimulationManager simManager,
               String name)
Constructs a new mailbox with the given name using the given simulation manager.

Parameters:
simManager - the simulation manager coordinating this mailbox
name - the name of this mailbox (for debugging purposes)

Mailbox

public Mailbox(SimulationManager simManager)
Constructs a new mailbox with a generated name using the given simulation manager.

Parameters:
simManager - the simulation manager coordinating this mailbox
Method Detail

put

public void put(T item)
Puts the item into the mailbox in the last position.

Parameters:
item - an item to put in the mailbox

getWait

public T getWait()
Returns the first item in the mailbox. If the mailbox is empty, waits until something is placed in the mailbox. Dequeues the item from the mailbox. If more than one thread is in the getWait call and only one item is placed in the mailbox, only one thread gets the item and all other threads continue to wait.

Returns:
the first item in the mailbox

getNoWait

public T getNoWait()
Returns the first item in the mailbox. If the mailbox is empty, it returns null. Dequeues the item from the mailbox.

Returns:
the first item in the mailbox, or null

peekWait

public T peekWait()
Returns the first item in the mailbox. If the mailbox is empty, waits until something is placed in the mailbox. Does not dequeue the item from the mailbox. If more than one thread is in the peekWait call and only one item is placed in the mailbox, all the thread will get a reference to the item.

Returns:
the first item in the mailbox

peekNoWait

public T peekNoWait()
Returns the first item in the mailbox. If the mailbox is empty, it returns null. Does not dequeue the item from the mailbox.

Returns:
the first item in the mailbox, or null

size

public int size()
Returns the number of items in the mailbox.

Returns:
the number of items in the mailbox

toString

public String toString()
Overrides:
toString in class Object