tyrex.services

Class DaemonMaster

public class DaemonMaster extends ThreadGroup implements 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

Method Summary
static voidaddDaemon(Runnable runnable, String name)
Adds a daemon.
static voidaddDaemon(Runnable runnable, String name, int priority)
Adds a daemon.
static voiddump(PrintWriter writer)
static intgetCount()
Returns the number of daemons currently in the system.
static booleanremoveDaemon(Runnable runnable)
Removes a daemon.
voidrun()
voiduncaughtException(Thread thread, Throwable thrw)

Method Detail

addDaemon

public static void addDaemon(Runnable runnable, 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(Runnable runnable, 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

dump

public static void dump(PrintWriter writer)

getCount

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

Returns: The number of daemons currently in the system

removeDaemon

public static boolean removeDaemon(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

run

public void run()

uncaughtException

public void uncaughtException(Thread thread, Throwable thrw)
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.