protected void onExec() { if (Debug.isDebug()) record("doExec", "executing %s", this); }
protected void onParked(boolean yield) { if (Debug.isDebug()) record("doExec", "parked " + (yield ? "(yield)" : "(park)") + " %s", this); }
protected void onExec() { if (Debug.isDebug()) record("doExec", "executing %s", this); }
protected void onExec() { if (Debug.isDebug()) record("doExec", "executing %s", this); }
protected void onParked(boolean yield) { if (Debug.isDebug()) record("doExec", "parked " + (yield ? "(yield)" : "(park)") + " %s", this); }
private static void dumpRecorder() { if (isDebug()) { final String fileName = getDumpFile(); if (fileName != null && !fileName.trim().equals("")) { if (fileDumped.compareAndSet(false, true)) dumpRecorder(fileName); } else System.err.println("NO ERROR LOG FILE SPECIFIED."); } }
@Override public void failed(Throwable e, Description desc) { System.out.println("FAILED TEST " + desc.getMethodName() + ": " + e.getMessage()); e.printStackTrace(System.err); if (Debug.isDebug() && !(e instanceof OutOfMemoryError)) { Debug.record(0, "EXCEPTION IN THREAD " + Thread.currentThread().getName() + ": " + e + " - " + Arrays.toString(e.getStackTrace())); Debug.dumpRecorder("quasar." + desc.getClassName() + "." + desc.getMethodName() + ".dump"); } }
protected void onParked(boolean yield) { if (Debug.isDebug()) record("doExec", "parked " + (yield ? "(yield)" : "(park)") + " %s", this); fiber.onParked(); }
public Actor(String name, int mailboxSize) { this.name = name; this.mailbox = Mailbox.create(mailboxSize); if (Debug.isDebug()) this.flightRecorder = Debug.getGlobalFlightRecorder(); else this.flightRecorder = null; }
protected final boolean isRecordingLevel(int level) { if (!Debug.isDebug()) return false; final FlightRecorder.ThreadRecorder recorder = flightRecorder != null ? flightRecorder.get() : null; if (recorder == null) return false; return recorder.recordsLevel(level); }
protected ActorImpl(String name, SendPort<Object> mailbox, ActorRef<Message> ref) { this.name = name; this.mailbox = mailbox; this.flightRecorder = Debug.isDebug() ? Debug.getGlobalFlightRecorder() : null; this.ref = ref != null ? ref : new ActorRef<>(this); }
@Override protected void starting(Description desc) { if (Debug.isDebug()) { System.out.println("STARTING TEST " + desc.getMethodName()); Debug.record(0, "STARTING TEST " + desc.getMethodName()); } }
public static void record(int level, Object... payload) { if (!isDebug()) return; if (getGlobalFlightRecorder() == null) return; getGlobalFlightRecorder().record(level, payload); }
public static void record(int level, Object payload) { if (!isDebug()) return; if (getGlobalFlightRecorder() == null) return; getGlobalFlightRecorder().record(level, payload); }
protected boolean park(Object blocker, boolean exclusive) throws Exception { int newState; int _state; do { _state = getState(); switch (_state) { case LEASED: newState = RUNNABLE; break; case RUNNABLE: newState = PARKING; break; case PARKING: case PARKED: throw new AssertionError("Unexpected task state (fiber parking or parked has no chance to to call `park`): " + _state); default: throw new AssertionError("Unknown task state: " + _state); } } while (!compareAndSetState(_state, newState)); if (Debug.isDebug()) record("park", "current: %s - %s -> %s (blocker: %s)", this, _state, newState, blocker); if (newState == PARKING) { this.blocker = blocker; this.parkExclusive = exclusive; parking(false); throwPark(false); return true; } else return false; }
if (Debug.isDebug()) record("park", "current: %s - %s -> %s (blocker: %s)", this, _state, newState, blocker); if (newState == PARKING) {
@Override protected void internalSendNonSuspendable(Object message) { record(1, "Actor", "send", "Sending %s -> %s", message, this); if (Debug.isDebug() && flightRecorder != null && flightRecorder.get().recordsLevel(2)) record(2, "Actor", "send", "%s queue %s", this, getQueueLength()); if (mailbox().isOwnerAlive()) mailbox().sendNonSuspendable(message); else record(1, "Actor", "send", "Message dropped. Owner not alive."); }
@Override protected final void sendSync(Message message) throws SuspendExecution { record(1, "Actor", "sendSync", "Sending sync %s -> %s", message, this); if (Debug.isDebug() && flightRecorder != null && flightRecorder.get().recordsLevel(2)) record(2, "Actor", "sendSync", "%s queue %s", this, getQueueLength()); if (mailbox().isOwnerAlive()) mailbox().sendSync(message); else record(1, "Actor", "sendSync", "Message dropped. Owner not alive."); }
@Override protected final boolean trySend(Message message) { record(1, "Actor", "trySend", "Sending %s -> %s", message, this); if (Debug.isDebug() && flightRecorder != null && flightRecorder.get().recordsLevel(2)) record(2, "Actor", "trySend", "%s queue %s", this, getQueueLength()); if (mailbox().isOwnerAlive()) { if (mailbox().trySend(message)) return true; record(1, "Actor", "trySend", "Message not sent. Mailbox is not ready."); return false; } record(1, "Actor", "trySend", "Message dropped. Owner not alive."); return true; }
/** * Returns the next message from the mailbox. If no message is currently available, this method blocks until a message arrives. * * @return a message sent to this actor. * @throws InterruptedException */ @Override public final Message receive() throws SuspendExecution, InterruptedException { try { for (;;) { checkThrownIn0(); record(1, "Actor", "receive", "%s waiting for a message", this); final Object m = mailbox().receive(); record(1, "Actor", "receive", "Received %s <- %s", this, m); if (Debug.isDebug() && flightRecorder != null && flightRecorder.get().recordsLevel(2)) record(2, "Actor", "receive", "%s queue %s", this, getQueueLength()); monitorAddMessage(); Message msg = filterMessage(m); if (msg != null) return msg; } } catch (InterruptedException e) { checkThrownIn0(); throw e; } }