Package co.paralleluniverse.fibers
Class FiberUtil
- java.lang.Object
-
- co.paralleluniverse.fibers.FiberUtil
-
public final class FiberUtil extends java.lang.ObjectStatic utility methods for working with fibers.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V> java.util.List<V>get(long time, java.util.concurrent.TimeUnit unit, Fiber<V>... fibers)Blocks on the input fibers and creates a new list from the results.static <V> java.util.List<V>get(long timeout, java.util.concurrent.TimeUnit unit, java.util.List<Fiber<V>> fibers)Blocks on the input fibers and creates a new list from the results.static <V> java.util.List<V>get(Fiber<V>... fibers)Blocks on the input fibers and creates a new list from the results.static <V> java.util.List<V>get(java.util.List<Fiber<V>> fibers)Blocks on the input fibers and creates a new list from the results.static <V> VrunInFiber(FiberScheduler scheduler, SuspendableCallable<V> target)Runs an action in a new fiber, awaits the fiber's termination, and returns its result.static voidrunInFiber(FiberScheduler scheduler, SuspendableRunnable target)Runs an action in a new fiber and awaits the fiber's termination.static <V> VrunInFiber(SuspendableCallable<V> target)Runs an action in a new fiber, awaits the fiber's termination, and returns its result.static voidrunInFiber(SuspendableRunnable target)Runs an action in a new fiber and awaits the fiber's termination.static <V,X extends java.lang.Exception>
VrunInFiberChecked(FiberScheduler scheduler, SuspendableCallable<V> target, java.lang.Class<X> exceptionType)Runs an action in a new fiber, awaits the fiber's termination, and returns its result.static <X extends java.lang.Exception>
voidrunInFiberChecked(FiberScheduler scheduler, SuspendableRunnable target, java.lang.Class<X> exceptionType)Runs an action in a new fiber and awaits the fiber's termination.static <V,X extends java.lang.Exception>
VrunInFiberChecked(SuspendableCallable<V> target, java.lang.Class<X> exceptionType)Runs an action in a new fiber, awaits the fiber's termination, and returns its result.static <X extends java.lang.Exception>
voidrunInFiberChecked(SuspendableRunnable target, java.lang.Class<X> exceptionType)Runs an action in a new fiber and awaits the fiber's termination.static <V> VrunInFiberRuntime(FiberScheduler scheduler, SuspendableCallable<V> target)Runs an action in a new fiber, awaits the fiber's termination, and returns its result.static voidrunInFiberRuntime(FiberScheduler scheduler, SuspendableRunnable target)Runs an action in a new fiber and awaits the fiber's termination.static <V> VrunInFiberRuntime(SuspendableCallable<V> target)Runs an action in a new fiber, awaits the fiber's termination, and returns its result.static voidrunInFiberRuntime(SuspendableRunnable target)Runs an action in a new fiber and awaits the fiber's termination.static <V> java.util.concurrent.Future<V>toFuture(Fiber<V> fiber)Turns a fiber into aFuture.
-
-
-
Method Detail
-
toFuture
public static <V> java.util.concurrent.Future<V> toFuture(Fiber<V> fiber)
Turns a fiber into aFuture.- Type Parameters:
V-- Parameters:
fiber- the fiber- Returns:
- a
Futurerepresenting the fiber.
-
runInFiber
public static <V> V runInFiber(SuspendableCallable<V> target) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Runs an action in a new fiber, awaits the fiber's termination, and returns its result. The new fiber is scheduled by thedefault scheduler.- Type Parameters:
V-- Parameters:
target- the operation- Returns:
- the operations return value
- Throws:
java.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-
runInFiber
public static <V> V runInFiber(FiberScheduler scheduler, SuspendableCallable<V> target) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Runs an action in a new fiber, awaits the fiber's termination, and returns its result.- Type Parameters:
V-- Parameters:
scheduler- theFiberSchedulerto use when scheduling the fiber.target- the operation- Returns:
- the operations return value
- Throws:
java.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-
runInFiber
public static void runInFiber(SuspendableRunnable target) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Runs an action in a new fiber and awaits the fiber's termination. The new fiber is scheduled by thedefault scheduler. .- Parameters:
target- the operation- Throws:
java.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-
runInFiber
public static void runInFiber(FiberScheduler scheduler, SuspendableRunnable target) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Runs an action in a new fiber and awaits the fiber's termination.- Parameters:
scheduler- theFiberSchedulerto use when scheduling the fiber.target- the operation- Throws:
java.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-
runInFiberRuntime
public static <V> V runInFiberRuntime(SuspendableCallable<V> target) throws java.lang.InterruptedException
Runs an action in a new fiber, awaits the fiber's termination, and returns its result. UnlikerunInFiberthis method does not throwExecutionException, but wraps any checked exception thrown by the operation in aRuntimeException. The new fiber is scheduled by thedefault scheduler.- Type Parameters:
V-- Parameters:
target- the operation- Returns:
- the operations return value
- Throws:
java.lang.InterruptedException
-
runInFiberRuntime
public static <V> V runInFiberRuntime(FiberScheduler scheduler, SuspendableCallable<V> target) throws java.lang.InterruptedException
Runs an action in a new fiber, awaits the fiber's termination, and returns its result. UnlikerunInFiberthis method does not throwExecutionException, but wraps any checked exception thrown by the operation in aRuntimeException.- Type Parameters:
V-- Parameters:
scheduler- theFiberSchedulerto use when scheduling the fiber.target- the operation- Returns:
- the operations return value
- Throws:
java.lang.InterruptedException
-
runInFiberRuntime
public static void runInFiberRuntime(SuspendableRunnable target) throws java.lang.InterruptedException
Runs an action in a new fiber and awaits the fiber's termination. UnlikerunInFiberthis method does not throwExecutionException, but wraps any checked exception thrown by the operation in aRuntimeException. The new fiber is scheduled by thedefault scheduler.- Parameters:
target- the operation- Throws:
java.lang.InterruptedException
-
runInFiberRuntime
public static void runInFiberRuntime(FiberScheduler scheduler, SuspendableRunnable target) throws java.lang.InterruptedException
Runs an action in a new fiber and awaits the fiber's termination. UnlikerunInFiberthis method does not throwExecutionException, but wraps any checked exception thrown by the operation in aRuntimeException.- Parameters:
scheduler- theFiberSchedulerto use when scheduling the fiber.target- the operation- Throws:
java.lang.InterruptedException
-
runInFiberChecked
public static <V,X extends java.lang.Exception> V runInFiberChecked(SuspendableCallable<V> target, java.lang.Class<X> exceptionType) throws X extends java.lang.Exception, java.lang.InterruptedException
Runs an action in a new fiber, awaits the fiber's termination, and returns its result. UnlikerunInFiberthis method does not throwExecutionException, but wraps any checked exception thrown by the operation in aRuntimeException. The new fiber is scheduled by thedefault scheduler.- Type Parameters:
V-- Parameters:
target- the operation- Returns:
- the operations return value
- Throws:
java.lang.InterruptedExceptionX extends java.lang.Exception
-
runInFiberChecked
public static <V,X extends java.lang.Exception> V runInFiberChecked(FiberScheduler scheduler, SuspendableCallable<V> target, java.lang.Class<X> exceptionType) throws X extends java.lang.Exception, java.lang.InterruptedException
Runs an action in a new fiber, awaits the fiber's termination, and returns its result. UnlikerunInFiberthis method does not throwExecutionException, but wraps any checked exception thrown by the operation in aRuntimeException, unless it is of the givenexception type, in which case the checked exception is thrown as-is.- Type Parameters:
V-- Parameters:
scheduler- theFiberSchedulerto use when scheduling the fiber.target- the operationexceptionType- a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is.- Returns:
- the operations return value
- Throws:
java.lang.InterruptedExceptionX extends java.lang.Exception
-
runInFiberChecked
public static <X extends java.lang.Exception> void runInFiberChecked(SuspendableRunnable target, java.lang.Class<X> exceptionType) throws X extends java.lang.Exception, java.lang.InterruptedException
Runs an action in a new fiber and awaits the fiber's termination. UnlikerunInFiberthis method does not throwExecutionException, but wraps any checked exception thrown by the operation in aRuntimeException, unless it is of the givenexception type, in which case the checked exception is thrown as-is. The new fiber is scheduled by thedefault scheduler.- Parameters:
target- the operationexceptionType- a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is.- Throws:
java.lang.InterruptedExceptionX extends java.lang.Exception
-
runInFiberChecked
public static <X extends java.lang.Exception> void runInFiberChecked(FiberScheduler scheduler, SuspendableRunnable target, java.lang.Class<X> exceptionType) throws X extends java.lang.Exception, java.lang.InterruptedException
Runs an action in a new fiber and awaits the fiber's termination. UnlikerunInFiberthis method does not throwExecutionException, but wraps any checked exception thrown by the operation in aRuntimeException, unless it is of the givenexception type, in which case the checked exception is thrown as-is.- Parameters:
scheduler- theFiberSchedulerto use when scheduling the fiber.target- the operationexceptionType- a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is.- Throws:
java.lang.InterruptedExceptionX extends java.lang.Exception
-
get
public static <V> java.util.List<V> get(java.util.List<Fiber<V>> fibers) throws java.lang.InterruptedException
Blocks on the input fibers and creates a new list from the results. The result list is the same order as the input list.- Parameters:
fibers- to combine- Throws:
java.lang.InterruptedException
-
get
public static <V> java.util.List<V> get(Fiber<V>... fibers) throws java.lang.InterruptedException
Blocks on the input fibers and creates a new list from the results. The result list is the same order as the input list.- Parameters:
fibers- to combine- Throws:
java.lang.InterruptedException
-
get
public static <V> java.util.List<V> get(long timeout, java.util.concurrent.TimeUnit unit, java.util.List<Fiber<V>> fibers) throws java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionBlocks on the input fibers and creates a new list from the results. The result list is the same order as the input list.- Parameters:
timeout- to wait for all requests to completeunit- the time is infibers- to combine- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.TimeoutException
-
get
public static <V> java.util.List<V> get(long time, java.util.concurrent.TimeUnit unit, Fiber<V>... fibers) throws java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionBlocks on the input fibers and creates a new list from the results. The result list is the same order as the input list.- Parameters:
time- to wait for all requests to completeunit- the time is infibers- to combine- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.TimeoutException
-
-