Example #1
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);
      }
    }
  }
Example #2
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;
  }
Example #3
0
  public static EFun resolve_fun(EObject mod, EObject fun, int arity) {
    EAtom f = fun.testAtom();
    if (f == null) {
      throw ERT.badarg(mod, fun, ESmall.make(arity));
    }

    JavaObject jo;
    if ((jo = mod.testJavaObject()) != null) {
      return jo.resolve_fun(f, arity);
    }

    EAtom m = mod.testAtom();

    if (m == null) {
      final ETuple tup;
      EAtom pmod;
      if ((tup = mod.testTuple()) != null
          && tup.arity() > 0
          && (pmod = tup.elm(1).testAtom()) != null) {

        final EFun pfun = EModuleManager.resolve(new FunID(pmod, f, arity + 1));

        return EFunCG.get_fun_with_handler(
            pmod.getName(),
            f.getName(),
            arity,
            new EFunHandler() {
              @Override
              public EObject invoke(EProc proc, EObject[] args) throws Pausable {
                EObject[] real_args = new EObject[args.length + 1];
                System.arraycopy(args, 0, real_args, 0, args.length);
                real_args[args.length] = tup;
                return pfun.invoke(proc, real_args);
              }
            },
            ERT.class.getClassLoader());
      }

      throw ERT.badarg(mod, fun, ESmall.make(arity));
    }
    EFun efun = EModuleManager.resolve(new FunID(m, f, arity));

    return efun;
  }