/** * Create an Erlang {@link OtpErlangPid pid}. Erlang pids are based upon * some node specific information; this method creates a pid using the * information in this node. Each call to this method produces a unique pid. * * @return an Erlang pid. */ public synchronized OtpErlangPid createPid() { final OtpErlangPid p = new OtpErlangPid(node, pidCount, serial, creation); pidCount++; if (pidCount > 0x7fff) { pidCount = 0; serial++; if (serial > 0x1fff) { /* 13 bits */ serial = 0; } } return p; }
/** * Create an Erlang PID from a stream containing a PID encoded in Erlang * external format. * * @param buf * the stream containing the encoded PID. * * @exception OtpErlangDecodeException * if the buffer does not contain a valid external * representation of an Erlang PID. */ public OtpErlangPid(final OtpInputStream buf) throws OtpErlangDecodeException { final OtpErlangPid p = buf.read_pid(); node = p.node(); id = p.id(); serial = p.serial(); creation = p.creation(); }
/** * Send a message to a remote {@link OtpErlangPid pid}, representing either * another {@link OtpMbox mailbox} or an Erlang process. * * @param to * the {@link OtpErlangPid pid} identifying the intended * recipient of the message. * * @param msg * the body of the message to send. * */ public void send(final OtpErlangPid to, final OtpErlangObject msg) { try { final String node = to.node(); if (node.equals(home.node())) { home.deliver(new OtpMsg(to, (OtpErlangObject) msg.clone())); } else { final OtpCookedConnection conn = home.getConnection(node); if (conn == null) { return; } conn.send(self, to, msg); } } catch (final Exception e) { } }
@Override public int hashCode() { return self.hashCode(); }
public static String extractPid(OtpErlangObject value) { return ((OtpErlangPid)value).toString(); }
private void exit(final int arity, final OtpErlangPid to, final OtpErlangObject reason) { try { final String node = to.node(); if (node.equals(home.node())) { home.deliver(new OtpMsg(OtpMsg.exitTag, self, to, reason)); } else { final OtpCookedConnection conn = home.getConnection(node); if (conn == null) { return; } switch (arity) { case 1: conn.exit(self, to, reason); break; case 2: conn.exit2(self, to, reason); break; } } } catch (final Exception e) { } }
return ((OtpErlangString) erlangObject).stringValue(); } else if (erlangObject instanceof OtpErlangPid) { return ((OtpErlangPid) erlangObject).toString(); } else { throw new ErlangConversionException(
/** * Determine if two mailboxes are equal. * * @return true if both Objects are mailboxes with the same identifying * {@link OtpErlangPid pids}. */ @Override public boolean equals(final Object o) { if (!(o instanceof OtpMbox)) { return false; } final OtpMbox m = (OtpMbox) o; return m.self.equals(self); }
/** * <p> * Remove a link to a remote mailbox or Erlang process. This method removes * a link created with {@link #link link()}. Links are idempotent; calling * this method once will remove all links between this mailbox and the * remote {@link OtpErlangPid pid}. * </p> * * @param to * the {@link OtpErlangPid pid} representing the object to unlink * from. * */ public void unlink(final OtpErlangPid to) { links.removeLink(self, to); try { final String node = to.node(); if (node.equals(home.node())) { home.deliver(new OtpMsg(OtpMsg.unlinkTag, self, to)); } else { final OtpCookedConnection conn = home.getConnection(node); if (conn != null) { conn.unlink(self, to); } } } catch (final Exception e) { } }
@Override protected int doHashCode() { final OtpErlangObject.Hash hash = new OtpErlangObject.Hash(1); hash.combine(pid.hashCode(), module.hashCode()); hash.combine(arity); if (md5 != null) { hash.combine(md5); } hash.combine(index); hash.combine(uniq); if (freeVars != null) { for (final OtpErlangObject o : freeVars) { hash.combine(o.hashCode(), 1); } } return hash.valueOf(); }
/** * Read an Erlang PID from the stream. * * @return the value of the PID. * * @exception OtpErlangDecodeException * if the next term in the stream is not an Erlang PID. */ public OtpErlangPid read_pid() throws OtpErlangDecodeException { String node; int id; int serial; int creation; int tag; tag = read1skip_version(); if (tag != OtpExternal.pidTag) { throw new OtpErlangDecodeException( "Wrong tag encountered, expected " + OtpExternal.pidTag + ", got " + tag); } node = read_atom(); id = read4BE() & 0x7fff; // 15 bits serial = read4BE() & 0x1fff; // 13 bits creation = read1() & 0x03; // 2 bits return new OtpErlangPid(node, id, serial, creation); }
final String node = to.node(); if (node.equals(home.node())) { if (!home.deliver(new OtpMsg(OtpMsg.linkTag, self, to))) {
return new OtpErlangPid(this);
@Override public boolean equals(final Object o) { if (!(o instanceof OtpErlangFun)) { return false; } final OtpErlangFun f = (OtpErlangFun) o; if (!pid.equals(f.pid) || !module.equals(f.module) || arity != f.arity) { return false; } if (md5 == null) { if (f.md5 != null) { return false; } } else { if (!Arrays.equals(md5, f.md5)) { return false; } } if (index != f.index || uniq != f.uniq) { return false; } if (freeVars == null) { return f.freeVars == null; } return Arrays.equals(freeVars, f.freeVars); }