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;
}
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());
}
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 + ']';
}
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();
}
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);
}
}
Aggregations