Package org.cyclos.impl.utils.tasks
Class AbstractPollingTask
- java.lang.Object
-
- org.cyclos.impl.AbstractServerComponent
-
- org.cyclos.impl.AbstractGlobalServerComponent
-
- org.cyclos.impl.utils.tasks.AbstractTask
-
- org.cyclos.impl.utils.tasks.AbstractPollingTask
-
- All Implemented Interfaces:
Runnable,PollingTask
- Direct Known Subclasses:
BackgroundTaskExecutionPollingTask,EntityBatchPollingTask,SimplePollingTask
public abstract class AbstractPollingTask extends AbstractTask implements PollingTask
Base class for tasks which keeps looking for available data to be processed. When running in a cluster, it is guaranteed that only a single node runs the same polling task at the same time.
-
-
Field Summary
-
Fields inherited from class org.cyclos.impl.utils.tasks.AbstractTask
errorLogService, invokerHandler, loggingHandler
-
Fields inherited from class org.cyclos.impl.AbstractGlobalServerComponent
rawEntityManagerHandler
-
Fields inherited from class org.cyclos.impl.AbstractServerComponent
accountHandler, configurationHandler, dataTranslationHandler, notificationHandler, profileFieldHandler, transactionHandler, translationHandler
-
-
Constructor Summary
Constructors Constructor Description AbstractPollingTask()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected DatedateFromDelay(int seconds)protected abstract voiddoRun()Subclasses must implement this method to do the task.DategetFirstExecution()Returns the first execution time for this polling taskprotected IntegergetInitialSleepSeconds()The number of seconds before the first execution.DategetNextExecution()Returns the next time the task should be executedprotected intgetSecondsUntilNextDay()Returns the number of seconds until the next dayprotected intgetSecondsUntilNextHour()Returns the number of seconds until the next hourprotected intgetSleepSeconds()protected EntityBackedParameterStoragegetStorage()Returns a storage that subclasses may use to store data between executionsvoidinitialize()Perform the initialization lazily.booleanisExclusiveInCluster()By default, PollingTasks are exclusive in clustersvoidrun()-
Methods inherited from class org.cyclos.impl.utils.tasks.AbstractTask
getLogConfiguration, getName, logName, logTaskError, logTaskSuccess, shouldGenerateErrorLog, toString
-
Methods inherited from class org.cyclos.impl.AbstractGlobalServerComponent
getBaseEntityManagerHandler, getEntityManager
-
Methods inherited from class org.cyclos.impl.AbstractServerComponent
dataTranslationProxy, delete, detach, find, flush, from, getApplicationContext, getFormatter, getFormatter, getFormatter, getLogger, getRemoteAddress, getSessionData, mailContentBuilder, message, message, persist, processBatch, processBatch, refresh, remove, selectFrom, subQuery, update
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.cyclos.impl.utils.tasks.PollingTask
getName
-
-
-
-
Method Detail
-
getFirstExecution
public Date getFirstExecution()
Description copied from interface:PollingTaskReturns the first execution time for this polling task- Specified by:
getFirstExecutionin interfacePollingTask
-
getNextExecution
public Date getNextExecution()
Description copied from interface:PollingTaskReturns the next time the task should be executed- Specified by:
getNextExecutionin interfacePollingTask
-
initialize
public void initialize()
Description copied from interface:PollingTaskPerform the initialization lazily. Invoked before the polling task is executed for the first time- Specified by:
initializein interfacePollingTask
-
isExclusiveInCluster
public boolean isExclusiveInCluster()
By default, PollingTasks are exclusive in clusters- Specified by:
isExclusiveInClusterin interfacePollingTask
-
dateFromDelay
protected Date dateFromDelay(int seconds)
-
doRun
protected abstract void doRun()
Subclasses must implement this method to do the task.
-
getInitialSleepSeconds
protected Integer getInitialSleepSeconds()
The number of seconds before the first execution. By default is a random time between 0 andgetSleepSeconds(). If returns null, the polling task is disabled.
-
getSecondsUntilNextDay
protected int getSecondsUntilNextDay()
Returns the number of seconds until the next day
-
getSecondsUntilNextHour
protected int getSecondsUntilNextHour()
Returns the number of seconds until the next hour
-
getSleepSeconds
protected int getSleepSeconds()
-
getStorage
protected EntityBackedParameterStorage getStorage()
Returns a storage that subclasses may use to store data between executions
-
-