org.activemath.util.checks
Class Checker

java.lang.Object
  extended by java.lang.Thread
      extended by org.activemath.util.checks.Checker
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
DummyChecker, MBaseRefChecker, UrlChecker

public abstract class Checker
extends Thread

Abstract class that performs one single check. (e.G. Maple, Omega, ...) It extends java.lang.Thread and performs its check regularily. It stores a Date object indicating when the last check was completed successfully.

Version:
0.1

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  boolean aborted
          inheriting class must leave their run() method if this variable is set true.
static int BAD_STATE
          value of getState() if last check was not successfully completed
static int BLOCKING_STATE
          value of getState() if checked thread is blocking unreasonably long
protected  boolean blockingPrepared
          true iff the checker is currently in a state that might block
protected  Date lastBlockingDate
          the last Date when the prepareForBlocking() method was called
protected  String lastBlockingDescription
          String indicating what operation the checking thread was about to perform before it blocked
protected  Date lastFailureDate
          the last Date when a check failed.
protected  String lastFailureDescription
          String indicating what went wrong when the tested failed the last time.
protected  Date lastSuccessDate
          the last Date when a check was successfull.
protected  long retryInterval
          number of seconds between two tests.
static int SANE_STATE
          value of getState() if last check was successfully completed
protected  Date shuttingDownSince
          stores the date when shutting down was initiated for the first time
static int UNEXPECTED_BLOCKING_STATE
          value of getState() if checked thread is unexcpectedly blocking unreasonably long.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Checker(Subconfiguration config)
          initializes the check.
 
Method Summary
protected  boolean computeBlocking(long secondsExpected)
          Computes the default way to test blocking with the number of seconds of the expected duration.
 int getCheckerState()
          returns the current state of the check whereas SANESTATE means that the last check was completed successfully BADSTATE means that the last check has failed BLOCKINGSTATE means that the checker thread was not updating for a unreasonably long time.
 Date getLastFailureDate()
          returns the time when the last test has failed
 String getLastFailureDescription()
          returns a verbose description of the last failure
 Date getLastSuccessDate()
          returns the time when the last test was successfully completed
 boolean isBlocking()
          returns true if the calling thread is blocking for a unreasonable long time.
protected  void prepareForBlocking(String desc)
          should be called before a check is about to call an (external) method which might block; in case it blocks, the given description will be part of a detailed failure description.
abstract  void run()
          runs the checks.
protected  void testComplete()
          handles things common to failing and successed test: unpreparation of blocking methods, later mightbe time measurements
protected  void testFails(String description)
          handles a failing test, i.E. stores the actual date as date of last failure and stores the given description as failure description
protected  void testSucceeds()
          handles a successing test, i.E. stores the actual date as date of last success, and calls testComplete
protected  void unprepareForBlocking()
          signals that the danger of blocking is over for now
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SANE_STATE

public static final int SANE_STATE
value of getState() if last check was successfully completed

See Also:
Constant Field Values

BAD_STATE

public static final int BAD_STATE
value of getState() if last check was not successfully completed

See Also:
Constant Field Values

BLOCKING_STATE

public static final int BLOCKING_STATE
value of getState() if checked thread is blocking unreasonably long

See Also:
Constant Field Values

UNEXPECTED_BLOCKING_STATE

public static final int UNEXPECTED_BLOCKING_STATE
value of getState() if checked thread is unexcpectedly blocking unreasonably long. Unexcpectedly in this context means that the thread is blocking, although there was no call to prepareForBlocking()

See Also:
Constant Field Values

lastSuccessDate

protected Date lastSuccessDate
the last Date when a check was successfull. Initialized to zero miliseconds after the time epoch.


lastFailureDate

protected Date lastFailureDate
the last Date when a check failed. Initialized to zero miliseconds after the time epoch.


lastBlockingDate

protected Date lastBlockingDate
the last Date when the prepareForBlocking() method was called


lastBlockingDescription

protected String lastBlockingDescription
String indicating what operation the checking thread was about to perform before it blocked


lastFailureDescription

protected String lastFailureDescription
String indicating what went wrong when the tested failed the last time.


blockingPrepared

protected boolean blockingPrepared
true iff the checker is currently in a state that might block


retryInterval

protected long retryInterval
number of seconds between two tests. It's long, because it will be used as multiplicator to get the value in ms, and then it's useful to have values greater than 26 days...


aborted

protected boolean aborted
inheriting class must leave their run() method if this variable is set true. This is part of a safer replacement of thread control. See http://java.sun.com/j2se/1.3/docs/guide/misc/threadPrimitiveDeprecation.html


shuttingDownSince

protected Date shuttingDownSince
stores the date when shutting down was initiated for the first time

Constructor Detail

Checker

public Checker(Subconfiguration config)
initializes the check. Starting should be done by inheritors, after initialization.

Parameters:
config - configuration to be used by subobjects
Method Detail

testComplete

protected void testComplete()
handles things common to failing and successed test: unpreparation of blocking methods, later mightbe time measurements


testSucceeds

protected void testSucceeds()
handles a successing test, i.E. stores the actual date as date of last success, and calls testComplete


prepareForBlocking

protected void prepareForBlocking(String desc)
should be called before a check is about to call an (external) method which might block; in case it blocks, the given description will be part of a detailed failure description. It is also useful during the first state

Parameters:
desc - String containing a short description of the blocking operation

unprepareForBlocking

protected void unprepareForBlocking()
signals that the danger of blocking is over for now


testFails

protected void testFails(String description)
handles a failing test, i.E. stores the actual date as date of last failure and stores the given description as failure description

Parameters:
description - String containing a description of the failure

getLastSuccessDate

public Date getLastSuccessDate()
returns the time when the last test was successfully completed

Returns:
Date of last success

getLastFailureDate

public Date getLastFailureDate()
returns the time when the last test has failed

Returns:
Date of last success

getLastFailureDescription

public String getLastFailureDescription()
returns a verbose description of the last failure

Returns:
Date of last success

isBlocking

public boolean isBlocking()
returns true if the calling thread is blocking for a unreasonable long time. This implementation assumes that blocking for longer than twice the retryInterval is unreasonable.


computeBlocking

protected boolean computeBlocking(long secondsExpected)
Computes the default way to test blocking with the number of seconds of the expected duration.


getCheckerState

public int getCheckerState()
returns the current state of the check whereas Bad states are always negative; the worse a state is, the more negative it must be (so that the ,,minimal State'' of different checkers expresses the worst State.


run

public abstract void run()
runs the checks. Between the checks, the thread sleeps for retryInterval seconds. Implementing methods must update either lastFailureDate or lastSuccessDate after every check

Specified by:
run in interface Runnable
Overrides:
run in class Thread