Search in sources :

Example 1 with Strand

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

the class SupervisorActor method createStrandForActor.

private Strand createStrandForActor(Strand oldStrand, Actor actor) {
    final Strand strand;
    if (oldStrand != null)
        strand = Strand.clone(oldStrand, actor);
    else
        strand = new Fiber(actor);
    actor.setStrand(strand);
    return strand;
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Strand(co.paralleluniverse.strands.Strand)

Example 2 with Strand

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

the class SupervisorActor method start.

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());
}
Also used : ActorRef(co.paralleluniverse.actors.ActorRef) LocalActor(co.paralleluniverse.actors.LocalActor) Actor(co.paralleluniverse.actors.Actor) Strand(co.paralleluniverse.strands.Strand)

Example 3 with Strand

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

the class Actor method toString.

@Override
public String toString() {
    String className = getClass().getSimpleName();
    if (className.isEmpty())
        className = getClass().getName().substring(getClass().getPackage().getName().length() + 1);
    final Strand strand = runner.getStrand();
    // strand.getClass().getSimpleName() + '@' + strand.getId()
    final String strandName = (strand != null ? strand.getName() : "null");
    return className + "@" + (getName() != null ? getName() : Integer.toHexString(System.identityHashCode(this))) + "[owner: " + strandName + ']';
}
Also used : Strand(co.paralleluniverse.strands.Strand)

Example 4 with Strand

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

the class Actor method spawn.

/**
     * 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 ff the {@link FiberFactory 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();
}
Also used : Strand(co.paralleluniverse.strands.Strand)

Example 5 with Strand

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

the class Debug method exit.

@SuppressWarnings("CallToThreadDumpStack")
public static void exit(int code, Throwable t, String filename) {
    final Strand currentStrand = Strand.currentStrand();
    if (flightRecorder != null) {
        flightRecorder.record(1, "DEBUG EXIT REQUEST ON STRAND " + currentStrand + ": " + Arrays.toString(currentStrand.getStackTrace()));
        if (t != null)
            flightRecorder.record(1, "CAUSED BY " + t + ": " + Arrays.toString(currentStrand.getStackTrace()));
        flightRecorder.stop();
    }
    if (requestShutdown.compareAndSet(false, true)) {
        System.err.println("DEBUG EXIT REQUEST ON STRAND " + currentStrand + (currentStrand.isFiber() ? " (THREAD " + Thread.currentThread() + ")" : "") + ": SHUTTING DOWN THE JVM.");
        Thread.dumpStack();
        if (t != null) {
            System.err.println("CAUSED BY " + t);
            t.printStackTrace();
        }
        dumpRecorder(filename);
        if (// Calling System.exit() in gradle unit tests breaks gradle
        !isUnitTest())
            System.exit(code);
    }
}
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