public class GCUBEScheduledHandler<HANDLED> extends GCUBEHandler<HANDLED> implements Lifetime<HANDLED>
GCUBEComplexHandler which schedules the execution
of a single GCUBEHandler, the scheduled handler, at regular time intervals.
The execution of the scheduled handler occurs in accordance with either one of the two modes
enumerated by GCUBEScheduledHandler.Mode. In Mode.EAGER, the first execution of the scheduled handler
occurs immediately. In Mode.LAZY, it occurs after the first elapse of the time interval.
A GCUBEScheduledHandler may be halted in between iteration of the schedule, either explicitly, by
invoking stop(), or implicitly, by overriding repeat(Exception, int) to implement arbitrary
halting conditions.
| Modifier and Type | Class and Description |
|---|---|
static class |
GCUBEScheduledHandler.Mode
Possible modes of execution.
|
| Modifier and Type | Field and Description |
|---|---|
protected Exception |
exception
The last exception raised during the schedule.
|
protected int |
exceptionCount
The number of exceptions raised at any point of the schedule.
|
protected long |
interval
Time interval.
|
protected boolean |
repeat
Stop flag.
|
handled, logger, producer| Constructor and Description |
|---|
GCUBEScheduledHandler()
Creates an instance.
|
GCUBEScheduledHandler(long interval,
GCUBEScheduledHandler.Mode mode,
GCUBEHandler<HANDLED>... handler)
Creates an instance with a given execution mode, time interval, and scheduled handler.
|
| Modifier and Type | Method and Description |
|---|---|
long |
getInterval()
Returns the interval of the schedule.
|
GCUBEScheduledHandler.Mode |
getMode()
Returns the execution mode of the
ScheduledHandler. |
GCUBEHandler<HANDLED> |
getScheduled()
Returns the scheduled handler.
|
protected boolean |
onIteration()
Used internally to perform an iteration of the schedule and to indicate whether it should continue.
|
protected boolean |
repeat(Exception exception,
int exceptionCount)
Indicates whether the scheduling should continue.
|
void |
run()
Executes the task implemented by the handler.
|
void |
setInterval(long interval)
Sets the interval of the schedule.
|
void |
setMode(GCUBEScheduledHandler.Mode mode)
Sets the execution mode of the
ScheduledHandler. |
void |
setScheduled(GCUBEHandler<HANDLED> scheduled)
Sets the scheduled handler.
|
void |
stop()
Stops the scheduling.
|
clearBlackboard, getBlackboard, getHandled, getId, getLogger, getName, getScopeManager, getSecurityManager, getState, notify, setBlackboard, setHandled, setLogger, setName, setScopeManager, setSecurityManager, setState, subscribe, undo, unsubscribeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclearBlackboard, getBlackboard, getHandled, getId, getLogger, getName, getScopeManager, getSecurityManager, setBlackboard, setHandled, setLogger, setName, setScopeManager, setSecurityManager, subscribe, undo, unsubscribeprotected long interval
protected boolean repeat
protected Exception exception
protected int exceptionCount
public GCUBEScheduledHandler()
public GCUBEScheduledHandler(long interval,
GCUBEScheduledHandler.Mode mode,
GCUBEHandler<HANDLED>... handler)
interval - the time interval in seconds.mode - the execution mode.handler - (optional) the scheduled handler.public long getInterval()
public void setInterval(long interval)
the - interval.public GCUBEHandler<HANDLED> getScheduled()
public void setScheduled(GCUBEHandler<HANDLED> scheduled)
scheduled - the scheduled handled.public GCUBEScheduledHandler.Mode getMode()
ScheduledHandler.public void setMode(GCUBEScheduledHandler.Mode mode)
ScheduledHandler.mode - the mode.public void run()
throws Exception
run in interface GCUBEIHandler<HANDLED>run in class GCUBEHandler<HANDLED>Exception - if the execution of the task does not complete normally.protected boolean onIteration()
true if the schedule should continue, false otherwise.public void stop()
protected boolean repeat(Exception exception, int exceptionCount)
true if no exception occurred during the iteration,
and false otherwise. Override to implement
specific conditions.exception - any exception which may have occurred during the iteration,
or null if the iteration completed successfully.exceptionCount - the number of exceptions which have occurred so far during the schedule.true if the scheduling should continue, false otherwise.Copyright © 2015. All Rights Reserved.