Search in sources :

Example 16 with Strand

use of co.paralleluniverse.strands.Strand in project quasar by puniverse.

the class EventSourceTest method spawnActor.

private <T extends Actor<Message, V>, Message, V> T spawnActor(T actor) {
    final 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 17 with Strand

use of co.paralleluniverse.strands.Strand 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 18 with Strand

use of co.paralleluniverse.strands.Strand 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 19 with Strand

use of co.paralleluniverse.strands.Strand 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 20 with Strand

use of co.paralleluniverse.strands.Strand in project quasar by puniverse.

the class Actor method run0.

//</editor-fold>
//<editor-fold desc="Lifecycle">
/////////// Lifecycle ///////////////////////////////////
final V run0() throws InterruptedException, SuspendExecution {
    JMXActorsMonitor.getInstance().actorStarted(ref);
    // runner might be nulled by running actor
    final Strand strand = runner.getStrand();
    if (!strand.isFiber())
        currentActor.set(this);
    try {
        if (this instanceof MigratingActor && globalId == null)
            this.globalId = MigrationService.registerMigratingActor();
        result = doRun();
        die(null);
        return result;
    } catch (ActorAbort abort) {
        throw abort;
    } catch (InterruptedException e) {
        if (this.exception != null) {
            die(exception);
            throw (RuntimeException) exception;
        }
        die(e);
        throw e;
    } catch (Throwable t) {
        if (t.getCause() instanceof InterruptedException) {
            InterruptedException ie = (InterruptedException) t.getCause();
            if (this.exception != null) {
                die(exception);
                throw (RuntimeException) exception;
            }
            die(ie);
            throw ie;
        }
        this.exception = t;
        die(t);
        throw t;
    } finally {
        record(1, "Actor", "die", "Actor %s is now dead of %s", this, getDeathCause());
        if (!strand.isFiber())
            currentActor.set(null);
        JMXActorsMonitor.getInstance().actorTerminated(ref, strand);
    }
}
Also used : Strand(co.paralleluniverse.strands.Strand)

Aggregations

Strand (co.paralleluniverse.strands.Strand)27 Fiber (co.paralleluniverse.fibers.Fiber)8 SuspendableRunnable (co.paralleluniverse.strands.SuspendableRunnable)4 SuspendExecution (co.paralleluniverse.fibers.SuspendExecution)3 Test (org.junit.Test)2 Actor (co.paralleluniverse.actors.Actor)1 ActorRef (co.paralleluniverse.actors.ActorRef)1 LocalActor (co.paralleluniverse.actors.LocalActor)1 FlightRecorderMessage (co.paralleluniverse.common.monitoring.FlightRecorderMessage)1 Pair (co.paralleluniverse.common.util.Pair)1 StrandFactoryBuilder (co.paralleluniverse.strands.StrandFactoryBuilder)1 Channel (co.paralleluniverse.strands.channels.Channel)1 ReceivePort (co.paralleluniverse.strands.channels.ReceivePort)1 SendPort (co.paralleluniverse.strands.channels.SendPort)1 ExecutionException (java.util.concurrent.ExecutionException)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Publisher (org.reactivestreams.Publisher)1