Search in sources :

Example 56 with Fiber

use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.

the class FiniteStateMachineTest method spawnActor.

private <T extends Actor<Message, V>, Message, V> T spawnActor(T actor) {
    Fiber fiber = new Fiber(actor);
    fiber.setUncaughtExceptionHandler(new Strand.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Strand s, Throwable e) {
            e.printStackTrace();
            throw Exceptions.rethrow(e);
        }
    });
    fiber.start();
    return actor;
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Strand(co.paralleluniverse.strands.Strand)

Example 57 with Fiber

use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.

the class ProxyServerTest method spawnActor.

private <T extends Actor<Message, V>, Message, V> T spawnActor(T actor) {
    Fiber fiber = new Fiber(scheduler, actor);
    fiber.setUncaughtExceptionHandler(new Strand.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Strand s, Throwable e) {
            e.printStackTrace();
            throw Exceptions.rethrow(e);
        }
    });
    fiber.start();
    return actor;
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Strand(co.paralleluniverse.strands.Strand)

Example 58 with Fiber

use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.

the class ServerTest method spawnActor.

private <T extends Actor<Message, V>, Message, V> T spawnActor(T actor) {
    Fiber fiber = new Fiber(scheduler, actor);
    fiber.setUncaughtExceptionHandler(new Strand.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Strand s, Throwable e) {
            e.printStackTrace();
            throw Exceptions.rethrow(e);
        }
    });
    fiber.start();
    return actor;
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Strand(co.paralleluniverse.strands.Strand)

Example 59 with Fiber

use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.

the class ActorTest method spawnActor.

private <Message, V> Actor<Message, V> spawnActor(Actor<Message, V> actor) {
    Fiber fiber = new Fiber("actor", scheduler, actor);
    fiber.setUncaughtExceptionHandler(new Strand.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Strand s, Throwable e) {
            e.printStackTrace();
            throw Exceptions.rethrow(e);
        }
    });
    fiber.start();
    return actor;
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Strand(co.paralleluniverse.strands.Strand)

Example 60 with Fiber

use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.

the class ChannelTest method sendMessageFromFiberToThread.

@Test
public void sendMessageFromFiberToThread() throws Exception {
    final Channel<String> ch = newChannel();
    Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {

        @Override
        public void run() throws SuspendExecution, InterruptedException {
            Fiber.sleep(100);
            ch.send("a message");
        }
    }).start();
    String m = ch.receive();
    assertThat(m, equalTo("a message"));
    fib.join();
}
Also used : SuspendableRunnable(co.paralleluniverse.strands.SuspendableRunnable) Fiber(co.paralleluniverse.fibers.Fiber) Test(org.junit.Test)

Aggregations

Fiber (co.paralleluniverse.fibers.Fiber)105 Test (org.junit.Test)88 SuspendableRunnable (co.paralleluniverse.strands.SuspendableRunnable)73 SuspendExecution (co.paralleluniverse.fibers.SuspendExecution)20 Strand (co.paralleluniverse.strands.Strand)8 IntChannel (co.paralleluniverse.strands.channels.IntChannel)4 QueueCapacityExceededException (co.paralleluniverse.strands.queues.QueueCapacityExceededException)4 ExecutionException (java.util.concurrent.ExecutionException)3 Ignore (org.junit.Ignore)3 Timeout (co.paralleluniverse.strands.Timeout)2 Channel (co.paralleluniverse.strands.channels.Channel)2 ReceivePort (co.paralleluniverse.strands.channels.ReceivePort)2 TimeoutException (java.util.concurrent.TimeoutException)2 ActorRef (co.paralleluniverse.actors.ActorRef)1 AbstractServerHandler (co.paralleluniverse.actors.behaviors.AbstractServerHandler)1 ServerActor (co.paralleluniverse.actors.behaviors.ServerActor)1 Function2 (co.paralleluniverse.common.util.Function2)1 Pair (co.paralleluniverse.common.util.Pair)1 FiberScheduler (co.paralleluniverse.fibers.FiberScheduler)1 FiberWriter (co.paralleluniverse.fibers.FiberWriter)1