org.flexiblepower.context
public interface FlexiblePowerContext
FlexiblePowerContext
is a service for runtime system utilities. It can determine the current time (using
the currentTime()
and currentTimeMillis()
methods) and it can run jobs (using the submit and
schedule methods).
The runtime should provide exactly one implementation of the FlexiblePowerContext
that is used by the other
components.Modifier and Type | Method and Description |
---|---|
java.util.Date |
currentTime() |
long |
currentTimeMillis()
Returns the current time in milliseconds.
|
<V> java.util.concurrent.ScheduledFuture<V> |
schedule(java.util.concurrent.Callable<V> callable,
Measurable<Duration> delay)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.
|
java.util.concurrent.ScheduledFuture<?> |
schedule(java.lang.Runnable command,
Measurable<Duration> delay)
Creates and executes a one-shot action that becomes enabled after the given delay.
|
java.util.concurrent.ScheduledFuture<?> |
scheduleAtFixedRate(java.lang.Runnable command,
Measurable<Duration> initialDelay,
Measurable<Duration> period)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently
with the given period; that is executions will commence after
initialDelay then
initialDelay+period , then initialDelay + 2 * period , and so on. |
java.util.concurrent.ScheduledFuture<?> |
scheduleWithFixedDelay(java.lang.Runnable command,
Measurable<Duration> initialDelay,
Measurable<Duration> delay)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently
with the given delay between the termination of one execution and the commencement of the next.
|
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task)
Submits a value-returning task for execution and returns a Future representing the pending results of the task.
|
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task)
Submits a Runnable task for execution and returns a Future representing that task.
|
<T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable task,
T result)
Submits a Runnable task for execution and returns a Future representing that task.
|
long currentTimeMillis()
Date
for a discussion of slight discrepancies that may arise
between "computer time" and coordinated universal time (UTC).java.util.Date currentTime()
Date
object that represents the current time. When calling the Date.getTime()
method, this should always be the same as calling currentTimeMillis()
directly.<T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
get
method will return the task's result upon successful completion.
If you would like to immediately block waiting for a task, you can use constructions of the form
result = exec.submit(aCallable).get();
Note: The Executors
class includes a set of methods that can convert some other common closure-like
objects, for example, PrivilegedAction
to Callable
form so they can be submitted.
T
- the type of the task's resulttask
- the task to submitjava.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if the task is null<T> java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result)
get
method will return the given result upon successful completion.T
- the type of the resulttask
- the task to submitresult
- the result to returnjava.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if the task is nulljava.util.concurrent.Future<?> submit(java.lang.Runnable task)
get
method will return null
upon successful completion.task
- the task to submitjava.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if the task is nulljava.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command, Measurable<Duration> delay)
command
- the task to executedelay
- the time from now to delay executionget()
method will return
null
upon completionjava.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command is null<V> java.util.concurrent.ScheduledFuture<V> schedule(java.util.concurrent.Callable<V> callable, Measurable<Duration> delay)
V
- the type of the callable's resultcallable
- the function to executedelay
- the time from now to delay executionjava.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if callable is nulljava.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command, Measurable<Duration> initialDelay, Measurable<Duration> period)
initialDelay
then
initialDelay+period
, then initialDelay + 2 * period
, and so on. If any execution of the task
encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via
cancellation or termination of the executor. If any execution of this task takes longer than its period, then
subsequent executions may start late, but will not concurrently execute.command
- the task to executeinitialDelay
- the time to delay first executionperiod
- the period between successive executionsget()
method will throw
an exception upon cancellationjava.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command is nulljava.lang.IllegalArgumentException
- if period less than or equal to zerojava.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command, Measurable<Duration> initialDelay, Measurable<Duration> delay)
command
- the task to executeinitialDelay
- the time to delay first executiondelay
- the delay between the termination of one execution and the commencement of the nextget()
method will throw
an exception upon cancellationjava.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command is nulljava.lang.IllegalArgumentException
- if delay less than or equal to zero