/** wait for howlong, for one more message to be available */ public static boolean wait_timeout(EProc proc, EObject howlong) throws Pausable { try { proc.check_exit(); if (ipclog.isLoggable(Level.FINE)) ipclog.fine("WAIT| " + proc + " waits for messages for " + howlong + " ms"); if (howlong == am_infinity) { proc.mbox.untilHasMessages(proc.midx + 1); proc.check_exit(); if (ipclog.isLoggable(Level.FINE)) ipclog.fine("WAIT| " + proc + " wakes up on message"); return true; } else { long now = System.currentTimeMillis(); if (proc.midx == 0 || proc.timeout_start == 0L) { proc.timeout_start = now; } EInteger ei; if ((ei = howlong.testInteger()) == null) throw new ErlangError(EAtom.intern("timeout_value")); long end = proc.timeout_start + ei.longValue(); long left = end - now; if (left < 0) { return false; } if (!proc.in_receive) { Task.sleep(left); return false; } else { if (ipclog.isLoggable(Level.FINE)) ipclog.fine( "WAIT| " + proc + " waiting for " + left + "ms for msg #" + (proc.midx + 1)); boolean res = proc.mbox.untilHasMessages(proc.midx + 1, left); proc.check_exit(); if (ipclog.isLoggable(Level.FINE)) ipclog.fine("WAIT| " + proc + " wakes up " + (res ? "on message" : "after timeout")); return res; } } } finally { proc.in_receive = false; } }
/** message reception timed out, reset message index */ public static void timeout(EProc proc) { if (ipclog.isLoggable(Level.FINE)) ipclog.fine("WAIT| " + proc + " timed out"); proc.midx = 0; proc.timeout_start = 0L; proc.in_receive = false; }
/** remove current message, and reset message index */ public static void remove_message(EProc proc) { proc.mbox.remove(proc.midx); proc.midx = 0; proc.timeout_start = 0L; proc.in_receive = false; }