예제 #1
0
파일: ERT.java 프로젝트: trifork/erjang
  /** 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;
    }
  }
예제 #2
0
파일: ERT.java 프로젝트: trifork/erjang
  @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);
      }
    }
  }
예제 #3
0
파일: ERT.java 프로젝트: trifork/erjang
  /**
   * @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;
  }
예제 #4
0
파일: ERT.java 프로젝트: trifork/erjang
 public static void check_exit(EProc p) {
   p.check_exit();
 }