public abstract class DaemonBase extends SingletonBase implements Daemon
The base implementation of Daemon
Daemon.StateDestroyable.Utillogger| Constructor and Description |
|---|
DaemonBase() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
doJob()
Execute the main logic
|
org.joda.time.DateTime |
errorTimestamp()
Returns the timestamp when last error happening
|
<T> T |
getAttribute(java.lang.String key)
Return the attribute set to the daemon
|
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes()
Returns all attributes set on this daemon
|
java.lang.String |
id()
Returns the full class name of this daemon.
|
protected boolean |
isFatal(java.lang.Exception e) |
java.lang.Exception |
lastError()
Returns last error
|
protected void |
onException(java.lang.Exception e,
java.lang.String message,
java.lang.Object... args) |
protected void |
releaseResources() |
void |
removeAttribute(java.lang.String key)
Remove an attribute from a daemon
|
void |
restart()
|
void |
run() |
void |
setAttribute(java.lang.String key,
java.lang.Object value)
Set an attribute to the daemon
|
protected void |
setLastError(java.lang.Exception e)
Set last error without updating the state and logging the message
|
protected void |
setup() |
void |
start()
Start this daemon
|
Daemon.State |
state()
Returns the
state of this daemon |
void |
stop()
Stop this daemon
|
protected void |
teardown() |
org.joda.time.DateTime |
timestamp()
Returns the timestamp when last state transfer happening
|
instanceaddSubResource, destroy, isDestroyed, reload, scopedebug, debug, error, error, fatal, fatal, info, info, isDebugEnabled, isTraceEnabled, trace, trace, warn, warnpublic final void restart()
Daemonpublic final void start()
DaemonStart this daemon
public final void stop()
DaemonStop this daemon
public final void run()
run in interface java.lang.Runnableprotected abstract void doJob()
throws java.lang.Exception
Execute the main logic
java.lang.Exceptionpublic Daemon.State state()
DaemonReturns the state of this daemon
public org.joda.time.DateTime timestamp()
DaemonReturns the timestamp when last state transfer happening
protected void setup()
throws java.lang.Exception
java.lang.Exceptionprotected void teardown()
throws java.lang.Exception
java.lang.Exceptionprotected void releaseResources()
releaseResources in class DestroyableBasepublic java.lang.String id()
Returns the full class name of this daemon.
Sub class can override this method to provide short version
public java.lang.Exception lastError()
DaemonReturns last error
public org.joda.time.DateTime errorTimestamp()
DaemonReturns the timestamp when last error happening
errorTimestamp in interface Daemonpublic void setAttribute(java.lang.String key,
java.lang.Object value)
DaemonSet an attribute to the daemon
setAttribute in interface Daemonkey - the attribute keyvalue - attribute valuepublic void removeAttribute(java.lang.String key)
DaemonRemove an attribute from a daemon
removeAttribute in interface Daemonkey - the attribute keypublic <T> T getAttribute(java.lang.String key)
DaemonReturn the attribute set to the daemon
getAttribute in interface DaemonT - the gneric type of the attribute valuekey - the attribute keypublic java.util.Map<java.lang.String,java.lang.Object> getAttributes()
DaemonReturns all attributes set on this daemon
getAttributes in interface Daemonprotected void onException(java.lang.Exception e,
java.lang.String message,
java.lang.Object... args)
protected boolean isFatal(java.lang.Exception e)
protected void setLastError(java.lang.Exception e)
Set last error without updating the state and logging the message
e - the errorCopyright © 2014–2017 ActFramework. All rights reserved.