@Override public Strand start() { fiber.start(); return this; }
@Override public Strand start() { fiber.start(); return this; }
/** * Creates a new child Fiber from the given {@link SuspendableRunnable}. * 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 NullPointerException when proto is null * @throws IllegalArgumentException when stackSize is <= 0 */ public static <V> Fiber<V> start(SuspendableRunnable target) { return Fibers.<V>create(target).start(); }
/** * Creates a new Fiber subclassing the Fiber class and overriding the {@link Fiber#run() run} method. * 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. * @throws NullPointerException when proto is null * @throws IllegalArgumentException when stackSize is <= 0 */ public static <V> Fiber<V> start(String name, FiberScheduler scheduler) { return Fibers.<V>create(name, scheduler).start(); }
/** * Creates a new Fiber subclassing the Fiber class and overriding the {@link Fiber#run() run} method. * * @param name The name of the fiber (may be null) * @param scheduler The scheduler pool in which the fiber should run. * @param stackSize the initial size of the data stack. * @throws NullPointerException when proto is null * @throws IllegalArgumentException when stackSize is <= 0 */ public static <V> Fiber<V> start(String name, FiberScheduler scheduler, int stackSize) { return Fibers.<V>create(name, scheduler, stackSize).start(); }
/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * Creates a new child Fiber subclassing the Fiber class and overriding the {@link Fiber#run() run} method. * 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) * @throws NullPointerException when proto is null * @throws IllegalArgumentException when stackSize is <= 0 */ public static <V> Fiber<V> start(String name) { return Fibers.<V>create(name).start(); }
/** * 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(); }
@Override public void start(Future<Void> startFuture) throws Exception { instanceScheduler = Sync.getContextScheduler(); new Fiber<Void>(instanceScheduler, () -> { try { SyncVerticle.this.start(); startFuture.complete(); } catch (Throwable t) { startFuture.fail(t); } }).start(); }
@Override public void stop(Future<Void> stopFuture) throws Exception { new Fiber<Void>(instanceScheduler, () -> { try { SyncVerticle.this.stop(); stopFuture.complete(); } catch (Throwable t) { stopFuture.fail(t); } finally { Sync.removeContextScheduler(); } }).start(); }
/** * Runs an action in a new fiber and awaits the fiber's termination. * * @param scheduler the {@link FiberScheduler} to use when scheduling the fiber. * @param target the operation * @throws ExecutionException * @throws InterruptedException */ public static void runInFiber(FiberScheduler scheduler, SuspendableRunnable target) throws ExecutionException, InterruptedException { new Fiber<Void>(scheduler, target).start().join(); }
/** * 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 new Fiber<V>(scheduler, target).start().get(); }
private static class RequestExecOutcome<Res> { final long execTime; final Res response; final Exception exception; public RequestExecOutcome(final long execTime, final Res response, final Exception exception) { this.execTime = execTime; this.response = response; this.exception = exception; } }
@Override @Suspendable public void handle(T t) { new Fiber<Void>(fiberScheduler, () -> { try { channel.send(t); } catch (Exception e) { throw new VertxException(e); } }).start(); }
/** * Starts a new fiber and runs the actor in it. * The fiber's name will be set to this actor's name. * * @return This actors' ActorRef */ public ActorRef<Message> spawn() { checkReplacement(); final Fiber f = getName() != null ? new Fiber(getName(), runner) : new Fiber(runner); f.start(); return ref(); }
/** * Starts a new fiber using the given scheduler and runs the actor in it. * The fiber's name will be set to this actor's name. * * @param ff the {@link FiberFactory factory} (or {@link FiberScheduler scheduler}) that will be used to create the actor's fiber. * @return This actors' ActorRef */ public ActorRef<Message> spawn(FiberFactory ff) { if (ff == null) return spawn(); checkReplacement(); ff.newFiber(runner).setName(getName()).start(); return ref(); }
private void requests(Channel<Integer> requestCh, int count) { new Fiber<Void>(() -> { for (int i = 0; i < count; ++i) { requestCh.send(i); } requestCh.close(); }).start(); }