@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; } }
strandFactory.newStrand(SuspendableUtils.runnableToCallable(new SuspendableRunnable() { @Override public void run() throws SuspendExecution, InterruptedException { strandFactory.newStrand(SuspendableUtils.runnableToCallable(new SuspendableRunnable() { @Override public void run() throws SuspendExecution, InterruptedException { final Strand collector = strandFactory.newStrand(SuspendableUtils.runnableToCallable(new SuspendableRunnable() { @Override public void run() throws SuspendExecution, InterruptedException {
/** * 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(); }
@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();