use of co.paralleluniverse.fibers.SuspendExecution in project quasar by puniverse.
the class InstrumentationOptimizerTest method testDontSkipForwardsWithLoop.
@Test
public void testDontSkipForwardsWithLoop() throws InterruptedException, SuspendExecution, ExecutionException {
new Fiber(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
dontSkipForwardsWithLoop();
}
}).start().join();
assertFalse(isOptimized("skipForwardsWithLoop"));
}
use of co.paralleluniverse.fibers.SuspendExecution in project quasar by puniverse.
the class InstrumentationOptimizerTest method testSkipForwardsWithMethodAfter.
@Test
public void testSkipForwardsWithMethodAfter() throws InterruptedException, SuspendExecution, ExecutionException {
new Fiber(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
skipForwardsWithMethodAfter();
}
}).start().join();
assertTrue(isOptimized("skipForwardsWithMethodAfter"));
}
use of co.paralleluniverse.fibers.SuspendExecution in project quasar by puniverse.
the class InstrumentationOptimizerTest method testSkipForwardsToSuspendableInt.
@Test
public void testSkipForwardsToSuspendableInt() throws InterruptedException, SuspendExecution, ExecutionException {
new Fiber(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
skipForwardsToSuspendableInt();
}
}).start().join();
assertTrue(isOptimized("skipForwardsToSuspendableInt"));
}
use of co.paralleluniverse.fibers.SuspendExecution in project quasar by puniverse.
the class InstrumentationOptimizerTest method testDontSkipForwardsWithTryCatch.
@Test
public void testDontSkipForwardsWithTryCatch() throws InterruptedException, SuspendExecution, ExecutionException {
new Fiber(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
dontSkipForwardsWithTryCatch();
}
}).start().join();
assertFalse(isOptimized("skipForwardsWithTryCatch"));
}
use of co.paralleluniverse.fibers.SuspendExecution in project quasar by puniverse.
the class Pipeline method parallelTransfer.
private void parallelTransfer() throws SuspendExecution, InterruptedException {
// 1) Fire workers
for (int i = 0; i < parallelism; i++) {
strandFactory.newStrand(SuspendableUtils.runnableToCallable(new SuspendableRunnable() {
@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();
}
// 2) Send jobs asynchronously
strandFactory.newStrand(SuspendableUtils.runnableToCallable(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
// Get first input
S s = from.receive();
while (s != null) {
final Channel<Channel<T>> resultWrapper = Channels.newChannel(1, Channels.OverflowPolicy.BLOCK, true, true);
jobs.send(new Pair<>(s, resultWrapper));
results.send(resultWrapper);
// Get next input
s = from.receive();
}
// No more inputs, close jobs channel and quit
jobs.close();
}
})).start();
// 3) Collect and transfer results asynchronously
try {
final Strand collector = strandFactory.newStrand(SuspendableUtils.runnableToCallable(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
// Get first result
Channel<Channel<T>> resWrapper = results.receive();
while (resWrapper != null) {
// Get wrapper
Channel<T> res = resWrapper.receive();
// Get first actual result
T out = res.receive();
while (out != null) {
// Send to output channel
to.send(out);
// Increment counter
transferred.incrementAndGet();
// Get next result
out = res.receive();
}
resWrapper = results.receive();
}
// No more results, quit
}
})).start();
// TODO solve nasty instrumentation problems on Strand.join()
if (collector.isFiber()) {
Fiber f = (Fiber) collector.getUnderlying();
f.join();
} else
collector.join();
} catch (ExecutionException ee) {
throw new AssertionError(ee);
}
}
Aggregations