Holger's Java API

## com.antelmann.util
Class Monitor

    java.lang.Object
      com.antelmann.util.Monitor

All Implemented Interfaces:
  Enabled, Task<RuntimeException>

Direct Known Subclasses:
  MonitorDelegate, Spider.SMonitor

    public class Monitor

extends Object
implements Task<RuntimeException>, Enabled

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

Fields inherited from interface com.antelmann.util.Enabled
`FILTER`

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()`
`boolean` `isEnabled()` determines whether this object is currently enabled
`void` `reInitialize()` calls reInitialize(true, 0, null)
`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` `setEnabled(boolean enabled)` allows to enable/disable this instance
`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()

  calls reInitialize(true, 0, null)

### 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()

### isEnabled

    public boolean isEnabled()

  Description copied from interface: `Enabled`
  determines whether this object is currently enabled

  Specified by:
    `isEnabled` in interface `Enabled`

### setEnabled

    public void setEnabled(boolean enabled)

  Description copied from interface: `Enabled`
  allows to enable/disable this instance

  Specified by:
    `setEnabled` in interface `Enabled`

### 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.

  Specified by:
    `runTask` in interface `Task<RuntimeException>`

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