Beispiel #1
0
  /** 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;
    }
  }
Beispiel #2
0
  @BIF
  public static EObject send(EProc proc, final EObject pid, final EObject msg, EObject options)
      throws Pausable {
    // TODO handle ports also?
    proc.check_exit();

    // log.log(Level.FINER, "ignored options to send: " + options);

    EHandle handle;
    EAtom reg_name;
    if ((handle = pid.testHandle()) != null) {
      send_to_handle(proc, handle, msg);
      return am_ok;
    } else if ((reg_name = pid.testAtom()) != null) {
      boolean ok = send_to_locally_registered(proc, reg_name, msg);
      if (ok) return am_ok;
      else throw badarg(pid, msg);
    } else {
      ETuple t;
      EAtom node_name;
      if ((t = pid.testTuple()) != null
          && t.arity() == 2
          && (reg_name = t.elm(1).testAtom()) != null
          && (node_name = t.elm(2).testAtom()) != null) {
        return send_to_remote(proc, t, node_name, reg_name, msg, options);
      } else { // PID was of a bad type.
        ipclog.info("trying to send message to " + pid + " failed.");
        throw badarg(pid, msg);
      }
    }
  }
Beispiel #3
0
  /**
   * @param owner
   * @param make
   * @throws Pausable
   */
  @BIF(name = "!")
  public static EObject send(EProc proc, EObject pid, EObject msg) throws Pausable {
    // TODO handle ports also?
    proc.check_exit();

    // log.log(Level.FINER, "ignored options to send: " + options);

    EHandle p;
    EAtom reg_name;
    if ((p = pid.testHandle()) != null) {
      send_to_handle(proc, p, msg);
    } else if ((reg_name = pid.testAtom()) != null) {
      send_to_locally_registered(proc, reg_name, msg);
    } else {
      ETuple t;
      EAtom node_name;
      if ((t = pid.testTuple()) != null
          && t.arity() == 2
          && (reg_name = t.elm(1).testAtom()) != null
          && (node_name = t.elm(2).testAtom()) != null) {
        send_to_remote(proc, t, node_name, reg_name, msg, null);
      } else { // PID was of a bad type.
        ipclog.info("trying to send message to " + pid + " failed.");
        throw badarg(pid, msg);
      }
    }
    // Arguments were of valid types; return the message:
    return msg;
  }
Beispiel #4
0
 public static void check_exit(EProc p) {
   p.check_exit();
 }