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:
quiesce()
, 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 void |
awaitPendingAfterQuiesce()
This method can be used after calling
quiesce() , and awaits the completion
of currently executing timers. |
abstract long |
getCurrentProcessingTime()
Returns the current processing time.
|
abstract boolean |
isTerminated()
Returns true if the service has been shut down, false otherwise.
|
abstract void |
quiesce()
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 boolean |
shutdownAndAwaitPending(long time,
TimeUnit timeUnit)
Shuts down and clean up the timer service provider hard and immediately.
|
abstract void |
shutdownService()
Shuts down and clean up the timer service provider hard and immediately.
|
abstract boolean |
shutdownServiceUninterruptible(long timeoutMs)
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 quiesce() throws InterruptedException
registerTimer(long, ProcessingTimeCallback)
only a "mock" future.
Furthermore, the method clears all not yet started 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 awaitPendingAfterQuiesce() throws InterruptedException
quiesce()
, and awaits the completion
of currently executing timers.InterruptedException
public abstract void shutdownService()
registerTimer(long, ProcessingTimeCallback)
will result in a hard exception.public abstract boolean shutdownServiceUninterruptible(long timeoutMs)
registerTimer(long, ProcessingTimeCallback)
will result in a hard exception. This call cannot be interrupted and will block until the shutdown is completed
or the timeout is exceeded.timeoutMs
- timeout for blocking on the service shutdown in milliseconds.public abstract boolean shutdownAndAwaitPending(long time, TimeUnit timeUnit) throws InterruptedException
registerTimer(long, ProcessingTimeCallback)
will result in a hard exception after calling this method.time
- time to wait for termination.timeUnit
- time unit of parameter time.true
if this timer service and all pending timers are terminated and
false
if the timeout elapsed before this happened.InterruptedException
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.