tyrex.services
Class DaemonMaster

java.lang.Object
  extended byjava.lang.ThreadGroup
      extended bytyrex.services.DaemonMaster
All Implemented Interfaces:
java.lang.Runnable

public class DaemonMaster
extends java.lang.ThreadGroup
implements java.lang.Runnable

The daemon master is responsible for starting, terminating and restarting daemon thread.

A daemon thread is a thread that is kept live for the duration of the server's life and is only terminated when the server is stopped.

A sudden termination of a daemon thread is an unwelcome occurance in the life time of the system. The daemon master protects the system from the sudden and unexpected termination of daemons by automatically restarting them.

A daemon implements the Runnable interface which allows it to be executed on any given thread. The daemon master assigns a thread within the daemon master's thread group. If the daemon is suddently terminated, the daemon master will be informed and attempt to restart the daemon with a new thread.

The daemon master is thread-safe and consumes a single thread.

Version:
$Revision: 1.6 $
Author:
Assaf Arkin

Field Summary
 
Fields inherited from class java.lang.ThreadGroup
 
Method Summary
static void addDaemon(java.lang.Runnable runnable, java.lang.String name)
          Adds a daemon.
static void addDaemon(java.lang.Runnable runnable, java.lang.String name, int priority)
          Adds a daemon.
static void dump(java.io.PrintWriter writer)
           
static int getCount()
          Returns the number of daemons currently in the system.
static boolean removeDaemon(java.lang.Runnable runnable)
          Removes a daemon.
 void run()
           
 void uncaughtException(java.lang.Thread thread, java.lang.Throwable thrw)
           
 
Methods inherited from class java.lang.ThreadGroup
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getCount

public static int getCount()
Returns the number of daemons currently in the system.

Returns:
The number of daemons currently in the system

addDaemon

public static void addDaemon(java.lang.Runnable runnable,
                             java.lang.String name)
Adds a daemon. Once added, a daemon will be started asynchronously and managed by the daemon master. If the daemon thread accidentally terminates, the daemon master will attempt to restart the daemon in a different thread.

Parameters:
runnable - The runnable object
name - The daemon name

addDaemon

public static void addDaemon(java.lang.Runnable runnable,
                             java.lang.String name,
                             int priority)
Adds a daemon. Once added, a daemon will be started asynchronously and managed by the daemon master. If the daemon thread accidentally terminates, the daemon master will attempt to restart the daemon in a different thread.

Parameters:
runnable - The runnable object
name - The daemon name
priority - The thread priority

removeDaemon

public static boolean removeDaemon(java.lang.Runnable runnable)
Removes a daemon. Once removed, the daemon master will no longer attempt to restart the daemon. This method must be called before the thread has completed to prevent accidental restart. It will automatically interrupt the background thread.

Parameters:
runnable - The runnable object

dump

public static void dump(java.io.PrintWriter writer)

uncaughtException

public void uncaughtException(java.lang.Thread thread,
                              java.lang.Throwable thrw)

run

public void run()
Specified by:
run in interface java.lang.Runnable


Original code is Copyright (c) 1999-2001, Intalio, Inc. All Rights Reserved. Contributions by MetaBoss team are Copyright (c) 2003-2005, Softaris Pty. Ltd. All Rights Reserved.