|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.tangosol.util.Base
com.tangosol.util.Daemon
public abstract class Daemon
A abstract Daemon thread handler. A sub-class need only provide an implementation of the run() method. When the Daemon is told to start, it will create a Java thread, which means that the number of Daemon instances within a system must be limited to a reasonable number. If an arbitrarily large number of conceptual daemons are necessary, consider using a TaskDaemon, which allows arbitrary tasks to be queued for execution. If thread pooling is desired, consider using a WorkManager implementation.
| Nested Class Summary | |
|---|---|
class |
Daemon.DaemonWorker
The sub-class of Thread that this Daemon uses as the actual thread of execution. |
| Constructor Summary | |
|---|---|
Daemon()
Default constructor. |
|
Daemon(String sName)
Creates a Daemon with the specified name. |
|
Daemon(String sName,
int nPriority,
boolean fStart)
Creates a Daemon with a specified name and priority. |
|
| Method Summary | |
|---|---|
protected void |
changeState(int nState,
Daemon.DaemonWorker worker)
Change the state of the daemon. |
protected void |
configureWorker(Daemon.DaemonWorker worker)
Configure a worker to use as a daemon. |
protected String |
getConfiguredName()
Determine the configured name for the daemon. |
protected int |
getConfiguredPriority()
Determine the configured priority for the daemon. |
protected String |
getDescription()
Format the Daemon attributes into a String for inclusion in the String returned from the toString() method. |
protected int |
getState()
Obtain the state of the daemon. |
Thread |
getThread()
Accessor to obtain the Daemon thread object. |
ClassLoader |
getThreadContextClassLoader()
Determine the configured context ClassLoader for the daemon thread. |
Daemon.DaemonWorker |
getWorker()
Accessor to obtain the Daemon worker object. |
protected Daemon.DaemonWorker |
instantiateWorker()
Instantiate a DaemonWorker that will be used as a daemon. |
boolean |
isOnWorkerThread()
Indiciate if the current execution thread is a child of this daemon. |
boolean |
isRunning()
Check if the daemon is running (has started and has not stopped). |
boolean |
isStopping()
Check if the daemon is supposed to stop. |
abstract void |
run()
The daemon's implementation method. |
protected void |
setConfiguredName(String sName)
Configure the name for the daemon. |
protected void |
setConfiguredPriority(int nPriority)
Configure the priority for the daemon. |
void |
setThreadContextClassLoader(ClassLoader loader)
Configure the context ClassLoader for the daemon thread. |
void |
start()
Performs a synchronized start of the thread if the thread is not already started. |
void |
stop()
Request the daemon to stop. |
protected static String |
toStateString(int nState)
Convert a state value to a human-readable String. |
String |
toString()
Return a human-readable String representation of the Daemon. |
| Constructor Detail |
|---|
public Daemon()
public Daemon(String sName)
sName - the thread name (may be null)
public Daemon(String sName,
int nPriority,
boolean fStart)
sName - the thread name (may be null)nPriority - the thread priority, between Thread.MIN_PRIORITY and
Thread.MAX_PRIORITY inclusivefStart - pass true to auto-start the thread as part of its
construction| Method Detail |
|---|
public abstract void run()
An example implementation is:
while (!isStopping())
{
// do some processing
// ...
synchronized (this)
{
// wait for notification of more work
wait();
}
}
run in interface Runnablepublic Thread getThread()
public Daemon.DaemonWorker getWorker()
public void start()
public boolean isRunning()
public void stop()
isStopping().
public boolean isStopping()
public boolean isOnWorkerThread()
protected int getState()
protected void changeState(int nState,
Daemon.DaemonWorker worker)
nState - one of the STATE_ enumsworker - the new worker, if starting, otherwise the current
workerprotected void setConfiguredPriority(int nPriority)
nPriority - the thread priority for the daemonprotected int getConfiguredPriority()
protected void setConfiguredName(String sName)
sName - the thread name for the daemonprotected String getConfiguredName()
public void setThreadContextClassLoader(ClassLoader loader)
setContextClassLoader will be called on the daemon thread object
immediately as well as during subsequent restarts.
loader - the context ClassLoader for the daemon threadpublic ClassLoader getThreadContextClassLoader()
protected Daemon.DaemonWorker instantiateWorker()
protected void configureWorker(Daemon.DaemonWorker worker)
worker - the DaemonWorker to configurepublic String toString()
protected String getDescription()
toString() method.
protected static String toStateString(int nState)
nState - a Daemon state, one of the STATE_* enums
|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||