- java.lang.Object
-
- com.pervasive.datarush.cal.ExecutionUtil
-
public final class ExecutionUtil extends Object
Miscellaneous utilities related toDistributedExecutorServiceand its subordinate classes.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancancel(List<? extends Future<?>> futures, boolean mayInterruptIfRunning)Cancels all of the provided futuresstatic <T> List<T>flatten(List<List<T>> lists)Flattens a list of lists into a single list.static <T> List<T>getResults(List<? extends Future<T>> futures)InvokesFuture.get()on each element in the provided list of futures, returning a list of results or throwing an exception if there are any failures.static <T> List<T>getResults(List<? extends Future<T>> futures, long timeout, TimeUnit timeunit)InvokesFuture.get()orFuture.get(long, TimeUnit)on each element in the provided list of futures, returning a list of results or throwing an exception if there are any failures.static <S> List<S>getStatus(List<? extends MonitoredFuture<S>> futures)InvokesMonitoredFuture.getStatus()on each element in the provided list of futures, returning a list of results or throwing an exception if there are any failures.static booleanisCancelled(List<? extends Future<?>> futures)Returns true if all of the futures are cancelled, false otherwise.static booleanisDone(List<? extends Future<?>> futures)Returns true if all of the futures are done, false otherwise.
-
-
-
Method Detail
-
flatten
public static <T> List<T> flatten(List<List<T>> lists)
Flattens a list of lists into a single list.- Type Parameters:
T- the element type of the lists- Parameters:
lists- the list of lists- Returns:
- a single list
-
getResults
public static <T> List<T> getResults(List<? extends Future<T>> futures) throws DistributedExecutionException, InterruptedException
InvokesFuture.get()on each element in the provided list of futures, returning a list of results or throwing an exception if there are any failures.- Type Parameters:
T- the result type- Parameters:
futures- the list of futures- Returns:
- a list of results
- Throws:
DistributedExecutionException- containing all of the errors. AnyBatchExecutionException's will be flattened.InterruptedException- if interrupted while waitingCancellationException- if any were canceled
-
isCancelled
public static boolean isCancelled(List<? extends Future<?>> futures)
Returns true if all of the futures are cancelled, false otherwise.- Parameters:
futures- the futures- Returns:
- whether all were cancelled
-
isDone
public static boolean isDone(List<? extends Future<?>> futures)
Returns true if all of the futures are done, false otherwise.- Parameters:
futures- the futures- Returns:
- whether all are done
-
cancel
public static boolean cancel(List<? extends Future<?>> futures, boolean mayInterruptIfRunning)
Cancels all of the provided futures- Parameters:
futures- the futuresmayInterruptIfRunning- whether we can interrupt a future that has already started running- Returns:
- true iff all were cancelled
-
getResults
public static <T> List<T> getResults(List<? extends Future<T>> futures, long timeout, TimeUnit timeunit) throws DistributedExecutionException, TimeoutException, InterruptedException, CancellationException
InvokesFuture.get()orFuture.get(long, TimeUnit)on each element in the provided list of futures, returning a list of results or throwing an exception if there are any failures.- Type Parameters:
T- the result type- Parameters:
futures- the list of futurestimeout- the timeout; ignored if timeunit is nulltimeunit- the timeunit or null for no timeout- Returns:
- a list of results
- Throws:
DistributedExecutionException- containing all of the errors. AnyBatchExecutionException's will be flattened.TimeoutException- if a timeout occurs. Will only be thrown if timeunit is non-null.InterruptedException- if interrupted while waitingCancellationException- if any were canceled
-
getStatus
public static <S> List<S> getStatus(List<? extends MonitoredFuture<S>> futures) throws DistributedExecutionException, InterruptedException
InvokesMonitoredFuture.getStatus()on each element in the provided list of futures, returning a list of results or throwing an exception if there are any failures.- Type Parameters:
S- the result type- Parameters:
futures- the list of futures- Returns:
- a list of statuses
- Throws:
DistributedExecutionException- containing all of the errors. AnyBatchExecutionException's will be flattened.InterruptedException- if interrupted while waitingCancellationException- if any were canceled
-
-