consciouscode.seedling.tasks
Class AbstractPeriodicTask

java.lang.Object
  extended by consciouscode.seedling.tree.GenericNode
      extended by consciouscode.seedling.tasks.AbstractPeriodicTask
All Implemented Interfaces:
LocatableNode, ServiceNode, PeriodicTask, Runnable
Direct Known Subclasses:
MemoryMonitorTask

public abstract class AbstractPeriodicTask
extends GenericNode
implements PeriodicTask, ServiceNode

Interface for tasks that can be scheduled for execution by a Clock. By default, instances of this class have periods of 60 seconds and are started immediately.


Field Summary
static int MILLIS_PER_MINUTE
           
static int MILLIS_PER_SECOND
           
 
Constructor Summary
AbstractPeriodicTask()
           
 
Method Summary
 Clock getClock()
           
 long getPeriodMillis()
          Get the amount of time, in milliseconds, between executions of this task.
 boolean isStartedImmediately()
          Determine whether this task should be started immediately when it's added to a clock.
 void setClock(Clock clock)
           
 void setPeriodMillis(long millis)
           
 void setPeriodMinutes(int minutes)
           
 void setPeriodSeconds(int seconds)
           
 void setStartedImmediately(boolean start)
           
 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
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

MILLIS_PER_SECOND

public static final int MILLIS_PER_SECOND
See Also:
Constant Field Values

MILLIS_PER_MINUTE

public static final int MILLIS_PER_MINUTE
See Also:
Constant Field Values
Constructor Detail

AbstractPeriodicTask

public AbstractPeriodicTask()
Method Detail

getPeriodMillis

public long getPeriodMillis()
Get the amount of time, in milliseconds, between executions of this task. Periods are measured from start-of-task to the next start-of-task. It is generally a bad idea to use a period that is shorter than the expected task duraion.

Specified by:
getPeriodMillis in interface PeriodicTask

setPeriodMillis

public void setPeriodMillis(long millis)

setPeriodSeconds

public void setPeriodSeconds(int seconds)

setPeriodMinutes

public void setPeriodMinutes(int minutes)

isStartedImmediately

public boolean isStartedImmediately()
Determine whether this task should be started immediately when it's added to a clock.

Specified by:
isStartedImmediately in interface PeriodicTask

setStartedImmediately

public void setStartedImmediately(boolean start)

getClock

public Clock getClock()

setClock

public void setClock(Clock clock)

startService

public void startService()
Description copied from interface: ServiceNode
Starts a Seedling service. This is called by the Seedling runtime after the node has been installed and all properties have been set to their configured values. Any exceptions thrown by an implementation of this method are handled by the Seedling. Instances of RuntimeException are propagated to the application, but any other kind of exception is wrapped in a ServiceException and rethrown.

Specified by:
startService in interface ServiceNode

stopService

public void stopService()
Description copied from interface: ServiceNode
Stops a Seedling service. This is called by the Seedling runtime as the node is uninstalled, either explicitly or by the Seedling itself being stopped.

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.

Specified by:
stopService in interface ServiceNode
See Also:
Runtime.addShutdownHook(java.lang.Thread)


Copyright © 2001–2012 Todd V. Jonker. All Rights Reserved.