org.jscience.util
Class Monitor

java.lang.Object
  extended by org.jscience.util.Monitor
Direct Known Subclasses:
MonitorDelegator, Spider.SMonitor

public class Monitor
extends java.lang.Object

Monitor is a convenient class that is useful to communicate between threads by exchanging information through this Monitor. The Monitor contains several generically useful members which can be accessed thread-savely to provide for different needs. There is also the availability of a custom call-back function for several purposes.


Field Summary
 boolean test
          DOCUMENT ME!
 Stopwatch timer
          initialized as running during instanciation
 
Constructor Summary
Monitor()
          Creates a new Monitor object.
Monitor(boolean enable, int size, java.lang.Runnable task)
          initializes the arrays in this instance with n elements to store/exchange data; task's run() method can be called with runTask()
Monitor(int size)
          Creates a new Monitor object.
 
Method Summary
 void disable()
          DOCUMENT ME!
 boolean disabled()
          DOCUMENT ME!
 void disableLater(long milliseconds)
          This function starts a separate Thread that will disable this Monitor in the given time in milliseconds automatically.
 void done()
          the effect cannot be reversed
 void enable()
          enable() sets the Monitor to be enabled() and also interrupts threads scheduled through disableLater()
 boolean enabled()
          DOCUMENT ME!
 int getMax()
          DOCUMENT ME!
 java.lang.String getMessage()
          DOCUMENT ME!
 int getMin()
          DOCUMENT ME!
 int getNumber()
          DOCUMENT ME!
 int getNumber(int i)
          DOCUMENT ME!
 java.lang.Object getObject()
          DOCUMENT ME!
 java.lang.Object getObject(int i)
          DOCUMENT ME!
 int getSize()
          returns the length of the monitor's arrays initialized by the constructor or reInitialize()
 java.lang.Runnable getTask()
          DOCUMENT ME!
 Stopwatch getTimer(int i)
          DOCUMENT ME!
 void increment()
          DOCUMENT ME!
 void increment(int i)
          DOCUMENT ME!
 boolean isDone()
          DOCUMENT ME!
 void reInitialize(boolean enable, int size, java.lang.Runnable task)
          all objects and arrays are re-initialized as if newly constructed; only the timer is maintained
 void runTask()
          lets the Thread that uses the Monitor perform a synchronous custom task that completes before the current thread continues.
 void setMax(int max)
          DOCUMENT ME!
 void setMessage(java.lang.String msg)
          DOCUMENT ME!
 void setMin(int min)
          DOCUMENT ME!
 void setNumber(int number)
          DOCUMENT ME!
 void setNumber(int i, int number)
          DOCUMENT ME!
 void setObject(int i, java.lang.Object obj)
          DOCUMENT ME!
 void setObject(java.lang.Object obj)
          DOCUMENT ME!
 void setTask(java.lang.Runnable task)
          DOCUMENT ME!
 boolean test(int i)
          DOCUMENT ME!
 void test(int i, boolean t)
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timer

public final Stopwatch timer
initialized as running during instanciation


test

public volatile boolean test
DOCUMENT ME!

Constructor Detail

Monitor

public Monitor()
Creates a new Monitor object.


Monitor

public Monitor(int size)
Creates a new Monitor object.

Parameters:
size - DOCUMENT ME!

Monitor

public Monitor(boolean enable,
               int size,
               java.lang.Runnable task)
initializes the arrays in this instance with n elements to store/exchange data; task's run() method can be called with runTask()

See Also:
runTask()
Method Detail

reInitialize

public void reInitialize(boolean enable,
                         int size,
                         java.lang.Runnable task)
all objects and arrays are re-initialized as if newly constructed; only the timer is maintained

Parameters:
enable - DOCUMENT ME!
size - DOCUMENT ME!
task - DOCUMENT ME!

disableLater

public void disableLater(long milliseconds)
This function starts a separate Thread that will disable this Monitor in the given time in milliseconds automatically. If a previous Thread was scheduled to disable the monitor, that previous Thread will be interrupted.

Parameters:
milliseconds - DOCUMENT ME!

enable

public void enable()
enable() sets the Monitor to be enabled() and also interrupts threads scheduled through disableLater()


disable

public void disable()
DOCUMENT ME!


enabled

public boolean enabled()
DOCUMENT ME!

Returns:
DOCUMENT ME!

disabled

public boolean disabled()
DOCUMENT ME!

Returns:
DOCUMENT ME!

isDone

public boolean isDone()
DOCUMENT ME!

Returns:
DOCUMENT ME!

done

public void done()
the effect cannot be reversed


increment

public void increment()
DOCUMENT ME!


increment

public void increment(int i)
               throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
i - DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

getNumber

public int getNumber()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getNumber

public int getNumber(int i)
              throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

getMin

public int getMin()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getMax

public int getMax()
DOCUMENT ME!

Returns:
DOCUMENT ME!

setMin

public void setMin(int min)
DOCUMENT ME!

Parameters:
min - DOCUMENT ME!

setMax

public void setMax(int max)
DOCUMENT ME!

Parameters:
max - DOCUMENT ME!

setNumber

public void setNumber(int number)
DOCUMENT ME!

Parameters:
number - DOCUMENT ME!

setNumber

public void setNumber(int i,
                      int number)
               throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
i - DOCUMENT ME!
number - DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

setObject

public void setObject(java.lang.Object obj)
DOCUMENT ME!

Parameters:
obj - DOCUMENT ME!

setObject

public void setObject(int i,
                      java.lang.Object obj)
               throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
i - DOCUMENT ME!
obj - DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

setMessage

public void setMessage(java.lang.String msg)
DOCUMENT ME!

Parameters:
msg - DOCUMENT ME!

getObject

public java.lang.Object getObject()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getObject

public java.lang.Object getObject(int i)
                           throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

getMessage

public java.lang.String getMessage()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getTimer

public Stopwatch getTimer(int i)
                   throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

setTask

public void setTask(java.lang.Runnable task)
DOCUMENT ME!

Parameters:
task - DOCUMENT ME!

getTask

public java.lang.Runnable getTask()
DOCUMENT ME!

Returns:
DOCUMENT ME!

test

public void test(int i,
                 boolean t)
          throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
i - DOCUMENT ME!
t - DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

test

public boolean test(int i)
             throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

getSize

public int getSize()
returns the length of the monitor's arrays initialized by the constructor or reInitialize()

Returns:
DOCUMENT ME!

runTask

public void runTask()
lets the Thread that uses the Monitor perform a synchronous custom task that completes before the current thread continues. The task performed is the run() method of the Runnable task given. If the task is null, nothing happens.