public abstract class ProcessingTimeService extends Object
The access to the time via getCurrentProcessingTime()
is always available, regardless of
whether the timer service has been shut down.
The registration of timers follows a life cycle of three phases:
quiesceAndAwaitPending()
, further calls to
registerTimer(long, ProcessingTimeCallback)
will not register any further timers, and will
return a "dummy" future as a result. This is used for clean shutdown, where currently firing
timers are waited for and no future timers can be scheduled, without causing hard exceptions.shutdownService()
, all calls to registerTimer(long, ProcessingTimeCallback)
will result in a hard exception.Constructor and Description |
---|
ProcessingTimeService() |
Modifier and Type | Method and Description |
---|---|
abstract long |
getCurrentProcessingTime()
Returns the current processing time.
|
abstract boolean |
isTerminated()
Returns true if the service has been shut down, false otherwise.
|
abstract void |
quiesceAndAwaitPending()
This method puts the service into a state where it does not register new timers, but
returns for each call to
registerTimer(long, ProcessingTimeCallback) only a "mock" future. |
abstract ScheduledFuture<?> |
registerTimer(long timestamp,
ProcessingTimeCallback target)
Registers a task to be executed when (processing) time is
timestamp . |
abstract ScheduledFuture<?> |
scheduleAtFixedRate(ProcessingTimeCallback callback,
long initialDelay,
long period)
Registers a task to be executed repeatedly at a fixed rate.
|
abstract void |
shutdownService()
Shuts down and clean up the timer service provider hard and immediately.
|
public abstract long getCurrentProcessingTime()
public abstract ScheduledFuture<?> registerTimer(long timestamp, ProcessingTimeCallback target)
timestamp
.timestamp
- Time when the task is to be executed (in processing time)target
- The task to be executedpublic abstract ScheduledFuture<?> scheduleAtFixedRate(ProcessingTimeCallback callback, long initialDelay, long period)
callback
- to be executed after the initial delay and then after each periodinitialDelay
- initial delay to start executing callbackperiod
- after the initial delay after which the callback is executedpublic abstract boolean isTerminated()
public abstract void quiesceAndAwaitPending() throws InterruptedException
registerTimer(long, ProcessingTimeCallback)
only a "mock" future.
Furthermore, the method clears all not yet started timers, and awaits the completion
of currently executing timers.
This method can be used to cleanly shut down the timer service. The using components will not notice that the service is shut down (as for example via exceptions when registering a new timer), but the service will simply not fire any timer any more.
InterruptedException
public abstract void shutdownService()
registerTimer(long, ProcessingTimeCallback)
will result in a hard exception.Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.