Java源码示例:co.paralleluniverse.strands.SuspendableCallable
示例1
@RequestMapping("/quasar-scenario")
@ResponseBody
public String testcase() throws Exception {
Fiber fiber = new Fiber("fiber", new SuspendableCallable() {
@Override
public Object run() {
try {
call("http://localhost:8080/quasar-scenario/case/ping");
} catch (Exception e) {
logger.error("quasar error:", e);
}
return null;
}
}
);
fiber.start();
return SUCCESS;
}
示例2
public static <V> Fiber<V> create(Fiber fiber, SuspendableCallable<V> target) {
return new Fiber<>(fiber, target);
}
示例3
public static <V> Fiber<V> create(Fiber fiber, FiberScheduler scheduler, SuspendableCallable<V> target) {
return new Fiber<>(fiber, scheduler, target);
}
示例4
public static <V> Fiber<V> start(Fiber fiber, SuspendableCallable<V> target) {
return create(fiber, target).start();
}
示例5
public static <V> Fiber<V> start(Fiber fiber, FiberScheduler scheduler, SuspendableCallable<V> target) {
return create(fiber, scheduler, target).start();
}
示例6
public static Strand clone(Strand strand, final SuspendableCallable<?> target) {
return Strand.clone(strand, target);
}
示例7
/**
* Runs an action in a new fiber, awaits the fiber's termination, and returns its result.
* The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}.
*
* @param <V>
* @param target the operation
* @return the operations return value
* @throws ExecutionException
* @throws InterruptedException
*/
public static <V> V runInFiber(SuspendableCallable<V> target) throws ExecutionException, InterruptedException {
return FiberUtil.runInFiber(target);
}
示例8
/**
* Runs an action in a new fiber, awaits the fiber's termination, and returns its result.
*
* @param <V>
* @param scheduler the {@link FiberScheduler} to use when scheduling the fiber.
* @param target the operation
* @return the operations return value
* @throws ExecutionException
* @throws InterruptedException
*/
public static <V> V runInFiber(FiberScheduler scheduler, SuspendableCallable<V> target) throws ExecutionException, InterruptedException {
return FiberUtil.runInFiber(scheduler, target);
}
示例9
/**
* Runs an action in a new fiber, awaits the fiber's termination, and returns its result.
* Unlike {@link #runInFiber(SuspendableCallable) runInFiber} this method does not throw {@link ExecutionException}, but wraps
* any checked exception thrown by the operation in a {@link RuntimeException}.
* The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}.
*
* @param <V>
* @param target the operation
* @return the operations return value
* @throws InterruptedException
*/
public static <V> V runInFiberRuntime(SuspendableCallable<V> target) throws InterruptedException {
return FiberUtil.runInFiberRuntime(target);
}
示例10
/**
* Runs an action in a new fiber, awaits the fiber's termination, and returns its result.
* Unlike {@link #runInFiber(FiberScheduler, SuspendableCallable) runInFiber} this method does not throw {@link ExecutionException}, but wraps
* any checked exception thrown by the operation in a {@link RuntimeException}.
*
* @param <V>
* @param scheduler the {@link FiberScheduler} to use when scheduling the fiber.
* @param target the operation
* @return the operations return value
* @throws InterruptedException
*/
public static <V> V runInFiberRuntime(FiberScheduler scheduler, SuspendableCallable<V> target) throws InterruptedException {
return FiberUtil.runInFiberRuntime(scheduler, target);
}
示例11
/**
* Runs an action in a new fiber, awaits the fiber's termination, and returns its result.
* Unlike {@link #runInFiber(SuspendableCallable) runInFiber} this method does not throw {@link ExecutionException}, but wraps
* any checked exception thrown by the operation in a {@link RuntimeException}.
* The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}.
*
* @param <V>
* @param target the operation
* @return the operations return value
* @throws InterruptedException
*/
public static <V, X extends Exception> V runInFiberChecked(SuspendableCallable<V> target, Class<X> exceptionType) throws X, InterruptedException {
return FiberUtil.runInFiberChecked(target, exceptionType);
}
示例12
/**
* Runs an action in a new fiber, awaits the fiber's termination, and returns its result.
* Unlike {@link #runInFiber(FiberScheduler, SuspendableCallable) runInFiber} this method does not throw {@link ExecutionException}, but wraps
* any checked exception thrown by the operation in a {@link RuntimeException}, unless it is of the given {@code exception type}, in
* which case the checked exception is thrown as-is.
*
* @param <V>
* @param scheduler the {@link FiberScheduler} to use when scheduling the fiber.
* @param target the operation
* @param exceptionType a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is.
* @return the operations return value
* @throws InterruptedException
*/
public static <V, X extends Exception> V runInFiberChecked(FiberScheduler scheduler, SuspendableCallable<V> target, Class<X> exceptionType) throws X, InterruptedException {
return FiberUtil.runInFiberChecked(scheduler, target, exceptionType);
}
示例13
/**
* Creates a new Fiber from the given {@link SuspendableCallable}.
* The new fiber uses the default initial stack size.
*
* @param name The name of the fiber (may be null)
* @param scheduler The scheduler pool in which the fiber should run.
* @param target the SuspendableCallable for the Fiber.
* @throws NullPointerException when proto is null
* @throws IllegalArgumentException when stackSize is <= 0
*/
public static <V> Fiber<V> create(String name, FiberScheduler scheduler, SuspendableCallable<V> target) {
return new Fiber<>(name, scheduler, target);
}
示例14
/**
* Creates a new Fiber from the given {@link SuspendableCallable}.
* The new fiber has no name, and uses the default initial stack size.
*
* @param scheduler The scheduler pool in which the fiber should run.
* @param target the SuspendableRunnable for the Fiber.
* @throws NullPointerException when proto is null
* @throws IllegalArgumentException when stackSize is <= 0
*/
public static <V> Fiber<V> create(FiberScheduler scheduler, SuspendableCallable<V> target) {
return new Fiber<>(scheduler, target);
}
示例15
/**
* Creates a new child Fiber from the given {@link SuspendableCallable}.
* This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber.
* The new fiber uses the default initial stack size.
*
* @param name The name of the fiber (may be null)
* @param target the SuspendableRunnable for the Fiber.
* @throws IllegalArgumentException when stackSize is <= 0
*/
public static <V> Fiber<V> create(String name, SuspendableCallable<V> target) {
return new Fiber<>(name, target);
}
示例16
/**
* Creates a new child Fiber from the given {@link SuspendableCallable}.
* This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber.
* The new fiber has no name, and uses the default initial stack size.
*
* @param target the SuspendableRunnable for the Fiber.
* @throws IllegalArgumentException when stackSize is <= 0
*/
public static <V> Fiber<V> create(SuspendableCallable<V> target) {
return new Fiber<>(target);
}
示例17
/**
* Creates a new Fiber from the given {@link SuspendableCallable}.
* The new fiber uses the default initial stack size.
*
* @param name The name of the fiber (may be null)
* @param scheduler The scheduler pool in which the fiber should run.
* @param target the SuspendableCallable for the Fiber.
* @throws NullPointerException when proto is null
* @throws IllegalArgumentException when stackSize is <= 0
*/
public static <V> Fiber<V> start(String name, FiberScheduler scheduler, SuspendableCallable<V> target) {
return create(name, scheduler, target).start();
}
示例18
/**
* Creates a new Fiber from the given {@link SuspendableCallable}.
* The new fiber has no name, and uses the default initial stack size.
*
* @param scheduler The scheduler pool in which the fiber should run.
* @param target the SuspendableRunnable for the Fiber.
* @throws NullPointerException when proto is null
* @throws IllegalArgumentException when stackSize is <= 0
*/
public static <V> Fiber<V> start(FiberScheduler scheduler, SuspendableCallable<V> target) {
return create(scheduler, target).start();
}
示例19
/**
* Creates a new child Fiber from the given {@link SuspendableCallable}.
* This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber.
* The new fiber uses the default initial stack size.
*
* @param name The name of the fiber (may be null)
* @param target the SuspendableRunnable for the Fiber.
* @throws IllegalArgumentException when stackSize is <= 0
*/
public static <V> Fiber<V> start(String name, SuspendableCallable<V> target) {
return create(name, target).start();
}
示例20
/**
* Creates a new child Fiber from the given {@link SuspendableCallable}.
* This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber.
* The new fiber has no name, and uses the default initial stack size.
*
* @param target the SuspendableRunnable for the Fiber.
* @throws IllegalArgumentException when stackSize is <= 0
*/
public static <V> Fiber<V> start(SuspendableCallable<V> target) {
return create(target).start();
}
示例21
/**
* A utility method that converts a {@link SuspendableCallable} to a {@link Runnable} so that it could run
* as the target of a thread. The return value of the callable is ignored.
*/
public static Runnable toRunnable(final SuspendableCallable<?> callable) {
return Strand.toRunnable(callable);
}