public abstract class DaemonBase extends SingletonBase implements Daemon
The base implementation of Daemon
Daemon.State
Destroyable.Util
logger
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
|
instance
addSubResource, destroy, isDestroyed, reload, scope
debug, debug, error, error, fatal, fatal, info, info, isDebugEnabled, isTraceEnabled, trace, trace, warn, warn
public final void restart()
Daemon
public final void start()
Daemon
Start this daemon
public final void stop()
Daemon
Stop this daemon
public final void run()
run
in interface java.lang.Runnable
protected abstract void doJob() throws java.lang.Exception
Execute the main logic
java.lang.Exception
public Daemon.State state()
Daemon
Returns the state
of this daemon
public org.joda.time.DateTime timestamp()
Daemon
Returns the timestamp when last state transfer happening
protected void setup() throws java.lang.Exception
java.lang.Exception
protected void teardown() throws java.lang.Exception
java.lang.Exception
protected void releaseResources()
releaseResources
in class DestroyableBase
public 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()
Daemon
Returns last error
public org.joda.time.DateTime errorTimestamp()
Daemon
Returns the timestamp when last error happening
errorTimestamp
in interface Daemon
public void setAttribute(java.lang.String key, java.lang.Object value)
Daemon
Set an attribute to the daemon
setAttribute
in interface Daemon
key
- the attribute keyvalue
- attribute valuepublic void removeAttribute(java.lang.String key)
Daemon
Remove an attribute from a daemon
removeAttribute
in interface Daemon
key
- the attribute keypublic <T> T getAttribute(java.lang.String key)
Daemon
Return the attribute set to the daemon
getAttribute
in interface Daemon
T
- the gneric type of the attribute valuekey
- the attribute keypublic java.util.Map<java.lang.String,java.lang.Object> getAttributes()
Daemon
Returns all attributes set on this daemon
getAttributes
in interface Daemon
protected 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.