public class DelayLine extends BackgroundLoop implements MetricProvider
Provides a background queue, which is checked about every 500ms. All tasks, which delay is expired will be invoked in the given executor.
Note that this should not be used with large delays, but rather for short durations (e.g. less than 60 seconds, although this depends heavily on the use case, as there is no inherent limit other than tasks won't survive a system restart).
Constructor and Description |
---|
DelayLine() |
Modifier and Type | Method and Description |
---|---|
void |
callDelayed(String executor,
long delayInSeconds,
Runnable task)
Queues the given task to be called after roughly the number of seconds given here.
|
protected void |
doWork()
Executes the actual work.
|
void |
forkDelayed(String executor,
long delayInSeconds,
Runnable task)
Queues the given task to be called after roughly the number of seconds given here.
|
void |
gather(MetricsCollector collector)
Invoked roughly every minute to collect all available metrics.
|
String |
getName()
Returns the name of the loop.
|
protected double |
maxCallFrequency()
Determines the maximal call frequency of
BackgroundLoop.doWork() in Hertz (ticks per second). |
determineExecutor, getExecutionInfo, loop, toString
public void callDelayed(@Nonnull String executor, long delayInSeconds, @Nonnull Runnable task)
executor
- the executor to execute the task in. Use Tasks.DEFAULT
is no other appropriate
pool
is available.delayInSeconds
- the number to wait in seconds. Note that the delay can be a bit longer, depending on the
system load.task
- the task to execute. Note that the CallContext
isn't transferred to the task being
invoked. Use forkDelayed(String, long, Runnable)
if you need the context.public void forkDelayed(@Nonnull String executor, long delayInSeconds, @Nonnull Runnable task)
In contrast to callDelayed(String, long, Runnable)
, this will preserve the CallContext
when
invoking the task.
executor
- the executor to execute the task in. Use Tasks.DEFAULT
is no other appropriate
pool
is available.delayInSeconds
- the number to wait in seconds. Note that the delay can be a bit longer, depending on the
system load.task
- the task to execute@Nonnull public String getName()
BackgroundLoop
getName
in class BackgroundLoop
protected double maxCallFrequency()
BackgroundLoop
BackgroundLoop.doWork()
in Hertz (ticks per second).maxCallFrequency
in class BackgroundLoop
protected void doWork() throws Exception
BackgroundLoop
doWork
in class BackgroundLoop
Exception
- in case of any error. The outer loop has a catch all rule to log exceptions.public void gather(MetricsCollector collector)
MetricProvider
gather
in interface MetricProvider
collector
- the interface used to provide metricsCopyright © 2018. All rights reserved.