hudson.model
Class AperiodicWork

java.lang.Object
  extended by java.util.TimerTask
      extended by hudson.triggers.SafeTimerTask
          extended by hudson.model.AperiodicWork
All Implemented Interfaces:
ExtensionPoint, Runnable
Direct Known Subclasses:
AsyncAperiodicWork

public abstract class AperiodicWork
extends SafeTimerTask
implements ExtensionPoint

Extension point which allows scheduling a task with variable interval. Interval in evaluated every time before next task is scheduled by calling getRecurrencePeriod(). Task to be scheduled is obtain by calling getNewInstance().

This class is similar to PeriodicWork. The main difference is in re-evaluating delay interval every time. See PeriodicWork for details. Analog of AsyncPeriodicWork is AsyncAperiodicWork.

Since:
1.410
Author:
vjuranek

Nested Class Summary
 
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
 
Field Summary
protected  Logger logger
           
 
Constructor Summary
AperiodicWork()
           
 
Method Summary
static ExtensionList<AperiodicWork> all()
          Returns all the registered AperiodicWorks.
protected abstract  void doAperiodicRun()
           
 void doRun()
           
 long getInitialDelay()
          Gets the number of milliseconds till the first execution.
abstract  AperiodicWork getNewInstance()
          Gets new instance of task to be executed.
abstract  long getRecurrencePeriod()
          Gets the number of milliseconds between successive executions.
 
Methods inherited from class hudson.triggers.SafeTimerTask
run
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Logger logger
Constructor Detail

AperiodicWork

public AperiodicWork()
Method Detail

getRecurrencePeriod

public abstract long getRecurrencePeriod()
Gets the number of milliseconds between successive executions.

Jenkins calls this method every time the timer task is scheduled.


getNewInstance

public abstract AperiodicWork getNewInstance()
Gets new instance of task to be executed. Method should return new instance each time, as there no check, if previously scheduled task already finished. Returning same instance could lead to throwing IllegalStateException (especially in case of AsyncAperiodicWork) and therefore scheduling of next tasks will be broken.

Returns:
AperiodicWork - timer task instance to be executed

getInitialDelay

public long getInitialDelay()
Gets the number of milliseconds till the first execution.

By default it chooses the value randomly between 0 and getRecurrencePeriod()


doRun

public final void doRun()
                 throws Exception
Specified by:
doRun in class SafeTimerTask
Throws:
Exception

doAperiodicRun

protected abstract void doAperiodicRun()

all

public static ExtensionList<AperiodicWork> all()
Returns all the registered AperiodicWorks.



Copyright © 2004-2013. All Rights Reserved.