@Nullable public static OtpErlangPid whereis(OtpMbox localMbox, OtpNode localNode, String remoteName, String remoteNode, int timeout) throws OtpErlangExit, OtpErlangDecodeException { OtpErlangObject response = RPC.INSTANCE.unmonitoredCall( remoteNode, localMbox, localNode, timeout, new OtpErlangAtom("Elixir.Process"), new OtpErlangAtom("whereis"), new OtpErlangAtom(remoteName) ); OtpErlangPid pid; if (response instanceof OtpErlangAtom) { if (response.equals(NIL)) { pid = null; } else { throw new NotImplementedException("Expected atoms to be nil, but got" + response); } } else { pid = (OtpErlangPid) response; } return pid; } }
@Nullable private static String structType(OtpErlangMap map) { OtpErlangObject structValue = map.get(new OtpErlangAtom("__struct__")); if (structValue instanceof OtpErlangAtom) { return ElixirModulesUtil.INSTANCE.erlangModuleNameToElixir(((OtpErlangAtom) structValue).atomValue()); } else { return null; } }
/** * <p> * Equivalent to <code>OtpErlangExit(new * OtpErlangAtom(reason)</code>. * </p> * * @param reason * the reason this exit signal has been sent. * * @see #OtpErlangExit(OtpErlangObject) */ public OtpErlangExit(final String reason) { this(new OtpErlangAtom(reason)); }
OtpMsg(final int tag, final OtpErlangPid from, final OtpErlangPid to, final String reason) { this.tag = tag; this.from = from; this.to = to; paybuf = null; payload = new OtpErlangAtom(reason); }
/** * <p> * Equivalent to <code>OtpErlangExit(new OtpErlangAtom(reason), * pid)</code>. * </p> * * @param reason * the reason this exit signal has been sent. * * @param pid * the pid that sent this exit. * * @see #OtpErlangExit(OtpErlangObject, OtpErlangPid) */ public OtpErlangExit(final String reason, final OtpErlangPid pid) { this(new OtpErlangAtom(reason), pid); }
/** * Equivalent to <code>exit(new OtpErlangAtom(reason))</code>. * * @see #exit(OtpErlangObject) */ public void exit(final String reason) { exit(new OtpErlangAtom(reason)); }
/** * <p> * Equivalent to <code>exit(to, new * OtpErlangAtom(reason))</code>. * </p> * * @see #exit(OtpErlangPid, OtpErlangObject) */ public void exit(final OtpErlangPid to, final String reason) { exit(to, new OtpErlangAtom(reason)); }
/** * Close the specified mailbox with reason 'normal'. * * @param mbox * the mailbox to close. * * <p> * After this operation, the mailbox will no longer be able to * receive messages. Any delivered but as yet unretrieved * messages can still be retrieved however. * </p> * * <p> * If there are links from the mailbox to other * {@link OtpErlangPid pids}, they will be broken when this * method is called and exit signals with reason 'normal' will be * sent. * </p> * */ public void closeMbox(final OtpMbox mbox) { closeMbox(mbox, new OtpErlangAtom("normal")); }
private OtpErlangTuple getPingTuple(final OtpMbox mbox) { final OtpErlangObject[] ping = new OtpErlangObject[3]; final OtpErlangObject[] pid = new OtpErlangObject[2]; final OtpErlangObject[] anode = new OtpErlangObject[2]; pid[0] = mbox.self(); pid[1] = createRef(); anode[0] = new OtpErlangAtom("is_auth"); anode[1] = new OtpErlangAtom(node()); ping[0] = new OtpErlangAtom("$gen_call"); ping[1] = new OtpErlangTuple(pid); ping[2] = new OtpErlangTuple(anode); return new OtpErlangTuple(ping); }
call[0] = new OtpErlangAtom("call"); call[1] = new OtpErlangAtom(mod); call[2] = new OtpErlangAtom(fun); call[3] = args; call[4] = new OtpErlangAtom("user");
synchronized void breakLinks() { if (links != null) { final Link[] l = links.clearLinks(); if (l != null) { final int len = l.length; for (int i = 0; i < len; i++) { // send exit "from" remote pids to local ones self.deliver(new OtpMsg(OtpMsg.exitTag, l[i].remote(), l[i] .local(), new OtpErlangAtom("noconnection"))); } } } } }
private boolean netKernel(final OtpMsg m) { OtpMbox mbox = null; try { final OtpErlangTuple t = (OtpErlangTuple) m.getMsg(); final OtpErlangTuple req = (OtpErlangTuple) t.elementAt(1); // actual // request final OtpErlangPid pid = (OtpErlangPid) req.elementAt(0); // originating // pid final OtpErlangObject[] pong = new OtpErlangObject[2]; pong[0] = req.elementAt(1); // his #Ref pong[1] = new OtpErlangAtom("yes"); mbox = createMbox(); mbox.send(pid, new OtpErlangTuple(pong)); return true; } catch (final Exception e) { } finally { closeMbox(mbox); } return false; }
@Override public void deliver(final OtpMsg msg) { final boolean delivered = self.deliver(msg); switch (msg.type()) { case OtpMsg.linkTag: if (delivered) { links.addLink(msg.getRecipientPid(), msg.getSenderPid()); } else { try { // no such pid - send exit to sender super.sendExit(msg.getRecipientPid(), msg.getSenderPid(), new OtpErlangAtom("noproc")); } catch (final IOException e) { } } break; case OtpMsg.unlinkTag: case OtpMsg.exitTag: links.removeLink(msg.getRecipientPid(), msg.getSenderPid()); break; case OtpMsg.exit2Tag: break; } return; }
final OtpErlangObject[] msgbody = new OtpErlangObject[3]; msgbody[0] = new OtpErlangAtom("print"); msgbody[1] = new OtpErlangString("~n** Bad cookie sent to " + local + " **~n"); msg[0] = new OtpErlangAtom("$gen_cast"); msg[1] = new OtpErlangTuple(msgbody);
case OtpExternal.smallAtomUtf8Tag: case OtpExternal.atomUtf8Tag: return new OtpErlangAtom(this);