sam.toolkit
Class Mailbox

java.lang.Object
  |
  +--sam.toolkit.Mailbox

public class Mailbox
extends java.lang.Object

This class implements an asynchronous mailbox.


Nested Class Summary
static interface Mailbox.Reader
          General type for mail readers
 
Constructor Summary
Mailbox()
          Builds a new Mailbox.
 
Method Summary
protected  void finalize()
          On destruction waits for all readers to finish reading any pending mail.
static void main(java.lang.String[] args)
          Sample mailbox test code.
 void post(java.lang.Object mail)
          Posts one more mail
 void start(Mailbox.Reader reader)
          Starts the event postmaster thread.
 void stop()
          Stops the mail postmaster thread.
 void terminate()
          Notifies the termination of the process.
 void waitForReaders()
          Waits for all readers to have read all pending mails.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mailbox

public Mailbox()
Builds a new Mailbox.

Method Detail

start

public void start(Mailbox.Reader reader)
Starts the event postmaster thread. Note that spawning multiple readers is allowed.


post

public void post(java.lang.Object mail)
Posts one more mail


waitForReaders

public void waitForReaders()
Waits for all readers to have read all pending mails. Note that this might be a blocking call.


stop

public void stop()
Stops the mail postmaster thread. This actually stops all if more than one was launched. Note that calling this several times is safe although of no use.


terminate

public void terminate()
Notifies the termination of the process. This is a blocking call that waits for all Mailbox to have been handled, and then stops all mail readers. Please understand that it is not equivalent to use to consecutives calls to mailbox.waitForReaders(); mailbox.stop() since this would release the lock between the two statements whereas it should not.


finalize

protected void finalize()
On destruction waits for all readers to finish reading any pending mail. Note that this implementation does not call Thread.stop()

Overrides:
finalize in class java.lang.Object

main

public static void main(java.lang.String[] args)
Sample mailbox test code. Posts all command-line arguments and spawns own reader.