|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectconsciouscode.seedling.tree.GenericNode
consciouscode.seedling.tree.ShutdownNode
public class ShutdownNode
A seedling node that handles clean shutdown of the JVM and of the Seedling itself.
Nodes that need special shutdown handling can register themselves with the ShutdownNode. This is cleaner and safer than using a standard shutdown hook, since the handlers will be called before JVM shutdown if the seedling is stopped programmatically.
Constructor Summary | |
---|---|
ShutdownNode()
|
Method Summary | |
---|---|
void |
addShutdownHandler(Runnable handler)
Add a handler to be run at shutdown. |
void |
removeShutdownHandler(Runnable handler)
Remove a shutdown handler. |
void |
runShutdownHandlers()
Run the registered shutdown handlers, but do not exit the JVM. |
void |
shutdown(int exitCode)
Run the registered shutdown handlers, then exit the JVM. |
void |
startService()
Starts a Seedling service. |
void |
stopService()
Stops a Seedling service. |
Methods inherited from class consciouscode.seedling.tree.GenericNode |
---|
getLocalRoot, getLog, getNodeLocation, getNodeName, getParentBranch, isLoggingDebug, nodeInstalled, setLog, setLoggingDebug |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ShutdownNode()
Method Detail |
---|
public void addShutdownHandler(Runnable handler)
If the registered handlers are currently running in another thread, this method will block until they have run to completion.
handler
- the item to add to the internal handler list. If
the handler is already in the list, this method does nothing.public void removeShutdownHandler(Runnable handler)
If the registered handlers are currently running in another thread, this method will block until they have run to completion.
handler
- the item to remove from the internal handler list. If
the handler is not in the list, this method does nothing.public void shutdown(int exitCode)
exitCode
- the value passed to System.exit(int)
.
IllegalStateException
- if this method is called from a running
handler.public void runShutdownHandlers()
If the registered handlers are currently running in another thread, this method will block until they have run to completion.
If the registered handlers are currently running in thisthread, this method will do nothing.
public void startService()
ServiceNode
RuntimeException
are propagated
to the application, but any other kind of exception is wrapped in a
ServiceException
and rethrown.
startService
in interface ServiceNode
public void stopService()
ServiceNode
Implementations of this method must not do anything that may change
the state of the parent Seedling. In particular, it cannot call
any overload of the following methods:
BranchNode.getNode(java.lang.String)
,
BranchNode.getChild(java.lang.String)
, GrowingBranch.installChild(java.lang.String, java.lang.Object)
,
GrowingBranch.uninstallChild(java.lang.String)
.
Furthermore, this method may be called from within a JVM shutdown hook, which implies that it must work promptly and carefully.
stopService
in interface ServiceNode
Runtime.addShutdownHook(java.lang.Thread)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |