Holger's
Java API

com.antelmann.util
Class Monitor

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

public class Monitor
extends 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.

Author:
Holger Antelmann

Field Summary
 boolean test
           
 Stopwatch timer
          initialized as running during instanciation
 
Constructor Summary
Monitor()
           
Monitor(boolean enable, int size, 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)
           
 
Method Summary
 void disable()
           
 boolean disabled()
           
 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 can only be reversed through reInitialize()
 void enable()
          enable() sets the Monitor to be enabled() and also interrupts threads scheduled through disableLater()
 boolean enabled()
           
 int getMax()
           
 String getMessage()
           
 int getMin()
           
 int getNumber()
           
 int getNumber(int i)
           
 Object getObject()
           
 Object getObject(int i)
           
 int getSize()
          returns the length of the monitor's arrays initialized by the constructor or reInitialize()
 Runnable getTask()
           
 Stopwatch getTimer(int i)
           
 void increment()
           
 void increment(int i)
           
 boolean isDone()
           
 void reInitialize(boolean enable, int size, 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)
           
 void setMessage(String msg)
           
 void setMin(int min)
           
 void setNumber(int number)
           
 void setNumber(int i, int number)
           
 void setObject(int i, Object obj)
           
 void setObject(Object obj)
           
 void setTask(Runnable task)
           
 boolean test(int i)
           
 void test(int i, boolean t)
           
 
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
Constructor Detail

Monitor

public Monitor()

Monitor

public Monitor(int size)

Monitor

public Monitor(boolean enable,
               int size,
               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,
                         Runnable task)
all objects and arrays are re-initialized as if newly constructed; only the timer is maintained


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.


enable

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


disable

public void disable()

enabled

public boolean enabled()

disabled

public boolean disabled()

isDone

public boolean isDone()

done

public void done()
the effect can only be reversed through reInitialize()


increment

public void increment()

increment

public void increment(int i)
               throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException

getNumber

public int getNumber()

getNumber

public int getNumber(int i)
              throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException

getMin

public int getMin()

getMax

public int getMax()

setMin

public void setMin(int min)

setMax

public void setMax(int max)

setNumber

public void setNumber(int number)

setNumber

public void setNumber(int i,
                      int number)
               throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException

setObject

public void setObject(Object obj)

setObject

public void setObject(int i,
                      Object obj)
               throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException

setMessage

public void setMessage(String msg)

getObject

public Object getObject()

getObject

public Object getObject(int i)
                 throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException

getMessage

public String getMessage()

getTimer

public Stopwatch getTimer(int i)
                   throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException

setTask

public void setTask(Runnable task)

getTask

public Runnable getTask()

test

public void test(int i,
                 boolean t)
          throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException

test

public boolean test(int i)
             throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException

getSize

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


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.



(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads