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
 /** Shuts down currently running OTP */
 public static void shutdown() {
   EObject init_proc = whereis(am_init);
   ETuple tup = ETuple.make(am_stop, am_stop);
   EPID init_pid;
   if ((init_pid = init_proc.testPID()) != null) {
     init_pid.sendb(tup);
   }
 }
Example #4
0
  public static void do_trace(EProc proc, EAtom what, EObject info, EObject message)
      throws Pausable {

    EPID pid = proc.get_trace_flags().tracer;

    EObject msg = ETuple.make(am_trace, proc.self_handle(), what, info, message);

    pid.send(proc.self_handle(), msg);
  }
Example #5
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;
  }
Example #6
0
 public static ETuple1 cast(ETuple value) {
   if (value.arity() == 1) return (ETuple1) value;
   return null;
 }
Example #7
0
 public static EObject try_case_end(EObject val) {
   throw new ErlangError(ETuple.make(am_try_case_clause, val));
 }
Example #8
0
  /**
   * Read an arbitrary Erlang term from the stream.
   *
   * @return the Erlang term.
   * @exception IOException if the stream does not contain a known Erlang type at the next position.
   */
  public EObject read_any() throws IOException {
    // calls one of the above functions, depending on o
    final int tag = peek1skip_version();

    switch (tag) {
      case EExternal.smallIntTag:
      case EExternal.intTag:
      case EExternal.smallBigTag:
      case EExternal.largeBigTag:
        return EInteger.read(this);

      case EExternal.atomCacheRef:
      case EExternal.atomTag:
      case EExternal.smallAtomTag:
        return EAtom.read(this);

      case EExternal.floatTag:
      case EExternal.newFloatTag:
        return EDouble.read(this);

      case EExternal.refTag:
      case EExternal.newRefTag:
        return ERef.read(this);

      case EExternal.portTag:
        return EPort.read(this);

      case EExternal.pidTag:
        return EPID.read(this);

      case EExternal.stringTag:
        return EString.read(this);

      case EExternal.listTag:
      case EExternal.nilTag:
        if ((flags & DECODE_INT_LISTS_AS_STRINGS) != 0) {
          final int savePos = getPos();
          try {
            return EString.read(this);
          } catch (final IOException e) {
          }
          setPos(savePos);
        }
        return EList.read(this);

      case EExternal.smallTupleTag:
      case EExternal.largeTupleTag:
        return ETuple.read(this);

      case EExternal.binTag:
        return EBinary.read(this);

      case EExternal.bitBinTag:
        return EBitString.read(this);

      case EExternal.compressedTag:
        return read_compressed();

      case EExternal.newFunTag:
      case EExternal.funTag:
        return EFun.read(this);

      case EExternal.externalFunTag:
        return read_external_fun();

      default:
        throw new IOException("Unknown data type: " + tag + " at position " + getPos());
    }
  }