public class TestProcessingTimeService extends ProcessingTimeService
ProcessingTimeService
used strictly for testing the
processing time functionality.Constructor and Description |
---|
TestProcessingTimeService() |
Modifier and Type | Method and Description |
---|---|
void |
awaitPendingAfterQuiesce()
This method can be used after calling
ProcessingTimeService.quiesce() , and awaits the completion
of currently executing timers. |
Set<Long> |
getActiveTimerTimestamps() |
long |
getCurrentProcessingTime()
Returns the current processing time.
|
int |
getNumActiveTimers() |
boolean |
isTerminated()
Returns true if the service has been shut down, false otherwise.
|
void |
quiesce()
This method puts the service into a state where it does not register new timers, but
returns for each call to
ProcessingTimeService.registerTimer(long, ProcessingTimeCallback) only a "mock" future. |
ScheduledFuture<?> |
registerTimer(long timestamp,
ProcessingTimeCallback target)
Registers a task to be executed when (processing) time is
timestamp . |
ScheduledFuture<?> |
scheduleAtFixedRate(ProcessingTimeCallback callback,
long initialDelay,
long period)
Registers a task to be executed repeatedly at a fixed rate.
|
void |
setCurrentTime(long timestamp) |
boolean |
shutdownAndAwaitPending(long time,
TimeUnit timeUnit)
Shuts down and clean up the timer service provider hard and immediately.
|
void |
shutdownService()
Shuts down and clean up the timer service provider hard and immediately.
|
boolean |
shutdownServiceUninterruptible(long timeoutMs)
Shuts down and clean up the timer service provider hard and immediately.
|
public long getCurrentProcessingTime()
ProcessingTimeService
getCurrentProcessingTime
in class ProcessingTimeService
public ScheduledFuture<?> registerTimer(long timestamp, ProcessingTimeCallback target)
ProcessingTimeService
timestamp
.registerTimer
in class ProcessingTimeService
timestamp
- Time when the task is to be executed (in processing time)target
- The task to be executedpublic ScheduledFuture<?> scheduleAtFixedRate(ProcessingTimeCallback callback, long initialDelay, long period)
ProcessingTimeService
scheduleAtFixedRate
in class ProcessingTimeService
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 boolean isTerminated()
ProcessingTimeService
isTerminated
in class ProcessingTimeService
public void quiesce()
ProcessingTimeService
ProcessingTimeService.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.
quiesce
in class ProcessingTimeService
public void awaitPendingAfterQuiesce() throws InterruptedException
ProcessingTimeService
ProcessingTimeService.quiesce()
, and awaits the completion
of currently executing timers.awaitPendingAfterQuiesce
in class ProcessingTimeService
InterruptedException
public void shutdownService()
ProcessingTimeService
ProcessingTimeService.registerTimer(long, ProcessingTimeCallback)
will result in a hard exception.shutdownService
in class ProcessingTimeService
public boolean shutdownServiceUninterruptible(long timeoutMs)
ProcessingTimeService
ProcessingTimeService.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.shutdownServiceUninterruptible
in class ProcessingTimeService
timeoutMs
- timeout for blocking on the service shutdown in milliseconds.public boolean shutdownAndAwaitPending(long time, TimeUnit timeUnit) throws InterruptedException
ProcessingTimeService
ProcessingTimeService.registerTimer(long, ProcessingTimeCallback)
will result in a hard exception after calling this method.shutdownAndAwaitPending
in class ProcessingTimeService
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
public int getNumActiveTimers()
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.