Package de.mhus.lib.core.schedule
Class SchedulerJob
- java.lang.Object
-
- java.util.TimerTask
-
- de.mhus.lib.core.MTimerTask
-
- de.mhus.lib.core.schedule.SchedulerJob
-
- All Implemented Interfaces:
de.mhus.lib.basics.Named,ITimerTask,Operation,MNlsProvider,Nls,Runnable
- Direct Known Subclasses:
CronJob,IntervalJob,IntervalWithStartTimeJob,OnceJob,SchedulerJobProxy
public abstract class SchedulerJob extends MTimerTask implements Operation
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classSchedulerJob.MyTaskContext
-
Field Summary
Fields Modifier and Type Field Description static longCALCULATE_NEXTprotected SchedulerJob.MyTaskContextcontextstatic longDISABLED_TIMEprotected static Loglogstatic longREMOVE_TIME-
Fields inherited from class de.mhus.lib.core.MTimerTask
CANCELLED, environment, EXECUTED, SCHEDULED, UNKNOWN, VIRGIN
-
-
Constructor Summary
Constructors Constructor Description SchedulerJob(ITimerTask task)SchedulerJob(String name, ITimerTask task)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancanExecute(TaskContext context)protected abstract voiddoCaclulateNextExecution()Calculate the next executionTime and store it into nextExecutionTimeprotected voiddoError(Throwable t)OperationResultdoExecute(TaskContext context)protected OperationResultdoExecute2(TaskContext context)voiddoit()protected voiddoReschedule(Scheduler scheduler, long time)protected voiddoSchedule(Scheduler scheduler)voiddoTick(boolean forced)Call this method to fire ticks to the scheduler.voiddoTimeoutReached()If you have defined a timeout, the event will be called every minute.OperationDescriptiongetDescription()StringgetInfo()TimerTaskInterceptergetIntercepter()longgetLastExecutionStart()longgetLastExecutionStop()StringgetLogTrailConfig()longgetNextExecutionTime()MNlsgetNls()ObjectgetOwner()longgetScheduledTime()ITimerTaskgetTask()ThreadgetThread()longgetTimeoutInMinutes()UUIDgetUuid()booleanhasAccess()booleanisBusy()booleanisDone()protected booleanisExecutionTimeReached()By default the function will compare the nextExecutionTime with the current time.Stringnls(String text)booleanreleaseBusy(Object owner)booleansetBusy(Object owner)protected voidsetDone(boolean done)voidsetInfo(String info)voidsetIntercepter(TimerTaskIntercepter intercepter)voidsetLogTrailConfig(String logTrailConfig)voidsetNextExecutionTime(long nextExecutionTime)protected voidsetScheduledTime(long scheduledTime)protected voidsetTask(ITimerTask task)voidsetTimeoutInMinutes(long timeoutInMinutes)StringtoString()-
Methods inherited from class de.mhus.lib.core.MTimerTask
cancel, getName, getStatus, isCanceled, onError, onFinal, run, run, setCanceled, setName
-
Methods inherited from class java.util.TimerTask
scheduledExecutionTime
-
-
-
-
Field Detail
-
CALCULATE_NEXT
public static final long CALCULATE_NEXT
- See Also:
- Constant Field Values
-
DISABLED_TIME
public static final long DISABLED_TIME
- See Also:
- Constant Field Values
-
REMOVE_TIME
public static final long REMOVE_TIME
- See Also:
- Constant Field Values
-
log
protected static Log log
-
context
protected SchedulerJob.MyTaskContext context
-
-
Constructor Detail
-
SchedulerJob
public SchedulerJob(ITimerTask task)
-
SchedulerJob
public SchedulerJob(String name, ITimerTask task)
-
-
Method Detail
-
doTick
public void doTick(boolean forced)
Call this method to fire ticks to the scheduler. If the time is come the scheduler will execute the operation and set 'done' to true.- Parameters:
forced-
-
doCaclulateNextExecution
protected abstract void doCaclulateNextExecution()
Calculate the next executionTime and store it into nextExecutionTime
-
doExecute
public final OperationResult doExecute(TaskContext context) throws Exception
-
doExecute2
protected OperationResult doExecute2(TaskContext context) throws Exception
- Throws:
Exception
-
releaseBusy
public boolean releaseBusy(Object owner)
- Specified by:
releaseBusyin interfaceOperation
-
getOwner
public Object getOwner()
-
isExecutionTimeReached
protected boolean isExecutionTimeReached()
By default the function will compare the nextExecutionTime with the current time. If the time is come it will return true. If nextExecutionTime is 0 or less it will return false in every case.- Returns:
-
isDone
public boolean isDone()
-
setDone
protected void setDone(boolean done)
-
canExecute
public boolean canExecute(TaskContext context)
- Specified by:
canExecutein interfaceOperation
-
getDescription
public OperationDescription getDescription()
- Specified by:
getDescriptionin interfaceOperation
-
getTask
public ITimerTask getTask()
-
setTask
protected void setTask(ITimerTask task)
-
doit
public void doit() throws Exception- Specified by:
doitin classMTimerTask- Throws:
Exception
-
getNextExecutionTime
public long getNextExecutionTime()
-
doError
protected void doError(Throwable t)
-
doSchedule
protected void doSchedule(Scheduler scheduler)
-
doReschedule
protected void doReschedule(Scheduler scheduler, long time)
-
getLastExecutionStart
public long getLastExecutionStart()
-
getLastExecutionStop
public long getLastExecutionStop()
-
getScheduledTime
public long getScheduledTime()
-
setScheduledTime
protected void setScheduledTime(long scheduledTime)
-
getTimeoutInMinutes
public long getTimeoutInMinutes()
-
setTimeoutInMinutes
public void setTimeoutInMinutes(long timeoutInMinutes)
-
doTimeoutReached
public void doTimeoutReached()
If you have defined a timeout, the event will be called every minute. Be carefully with the execution time of this event, it can hem the hole scheduler.
-
getThread
public Thread getThread()
-
setNextExecutionTime
public void setNextExecutionTime(long nextExecutionTime)
-
getNls
public MNls getNls()
- Specified by:
getNlsin interfaceMNlsProvider
-
getInfo
public String getInfo()
-
setInfo
public void setInfo(String info)
-
getIntercepter
public TimerTaskIntercepter getIntercepter()
-
setIntercepter
public void setIntercepter(TimerTaskIntercepter intercepter)
-
getLogTrailConfig
public String getLogTrailConfig()
-
setLogTrailConfig
public void setLogTrailConfig(String logTrailConfig)
-
-