Actor<Message, V> start() { record(1, "Actor", "start", "Starting actor %s", this); strand.start(); return this; }
public final Actor<Message, V> start() { record(1, "Actor", "start", "Starting actor %s", this); runner.getStrand().start(); return this; }
@Override public void close(final Throwable t) { if (!closing.getAndSet(true)) { if (closedBeforeFirstSend.get()) { strandFactory.newStrand(SuspendableUtils.runnableToCallable(new SuspendableRunnable() { @Override public void run() throws SuspendExecution, InterruptedException { target.send(prev); superClose(t); } })).start(); } else { superClose(t); } } }
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; } }
/** * 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 sf the {@link StrandFactory factory} (or {@link FiberScheduler scheduler}) that will be used to create the actor's fiber. * @return This actors' ActorRef */ public ActorRef<Message> spawn(StrandFactory sf) { if (sf == null) return spawn(); checkReplacement(); final Strand s = sf.newStrand(runner); setStrand(s); if (getName() != null) s.setName(getName()); s.start(); return ref(); }
private ActorRef<?> start(ChildEntry child) throws SuspendExecution { final ActorRef old = child.actor; if (old != null && !LocalActor.isDone(old)) throw new IllegalStateException("Actor " + child.actor + " cannot be restarted because it is not dead"); final Actor actor = child.spec.builder.build(); if (actor.getName() == null && child.spec.id != null) actor.setName(child.spec.id); log().info("{} starting child {}", this, actor); if (old != null && actor.getMonitor() == null && isLocal(old) && LocalActor.getMonitor(old) != null) actor.setMonitor(LocalActor.getMonitor(old)); if (actor.getMonitor() != null) actor.getMonitor().addRestart(); final Strand strand; if (actor.getStrand() != null) strand = actor.getStrand(); else strand = createStrandForActor(child.actor != null && isLocal(child.actor) ? LocalActor.getStrand(child.actor) : null, actor); try { strand.start(); } catch (IllegalThreadStateException e) { log().info("Child {} has already been started.", actor); } return start(child, actor.ref()); }
@Override public void run() throws SuspendExecution, InterruptedException { // Get first job Pair<S, Channel<Channel<T>>> job = jobs.receive(); while(job != null) { // Build result channel final Channel<T> res = resultChannelBuilder.run(); // Process transformer.call(job.getFirst(), res); final Channel<Channel<T>> resWrapper = job.getSecond(); // Send result asynchronously strandFactory.newStrand(SuspendableUtils.runnableToCallable(new SuspendableRunnable() { @Override public void run() throws SuspendExecution, InterruptedException { resWrapper.send(res); } })).start(); // Get next job job = jobs.receive(); } // No more jobs, close results channel and quit worker results.close(); } })).start();