public class WatchdogCache
extends java.lang.Object
Watchdog
instances. Because the timeout for
Watchdog
is set in the constructor Watchdog.Watchdog(long, boolean)
, you can
use this class to be more flexible and set the timeout at the time of watching the future.Constructor and Description |
---|
WatchdogCache(boolean sendInterruptOnFutureCancel)
Constructs a new
WatchdogCache . |
WatchdogCache(SubmitterScheduler scheduler,
boolean sendInterruptOnFutureCancel)
Constructs a new
WatchdogCache with a scheduler of your choosing. |
Modifier and Type | Method and Description |
---|---|
void |
watch(ListenableFuture<?> future,
long timeoutInMillis)
Watch a given
ListenableFuture to ensure that it completes within the provided
time limit. |
public WatchdogCache(boolean sendInterruptOnFutureCancel)
WatchdogCache
. This constructor will use a default static scheduler
(which is lazily constructed). This should be fine in most cases, but you can provide your
own scheduler if you want to avoid the thread creation (which is shared among all instances
that were constructed with this constructor or Watchdog.Watchdog(long, boolean)
}.sendInterruptOnFutureCancel
- If true
, and a thread is provided with the future,
an interrupt will be sent on timeoutpublic WatchdogCache(SubmitterScheduler scheduler, boolean sendInterruptOnFutureCancel)
WatchdogCache
with a scheduler of your choosing. It is critical
that this scheduler has a free thread available to inspect futures which may not have
completed in the given timeout. You may want to use a org.threadly.concurrent.limiter to
ensure that there are threads available.scheduler
- Scheduler to schedule task to look for expired futuressendInterruptOnFutureCancel
- If true
, and a thread is provided with the future,
an interrupt will be sent on timeoutpublic void watch(ListenableFuture<?> future, long timeoutInMillis)
ListenableFuture
to ensure that it completes within the provided
time limit. If the future is not marked as done by the time limit then it will be
completed by invoking Future.cancel(boolean)
. Weather a true
or
false
will be provided to interrupt the running thread is dependent on how this
WatchdogCache
was constructed.future
- Future to inspect to ensure completiontimeoutInMillis
- Time in milliseconds that future should be completed within