public OtpErlangFun(OtpErlangPid pid, String module, long index, long uniq, OtpErlangObject[] freeVars) { this.pid = pid; this.module = module; arity = -1; md5 = null; this.index = index; old_index = 0; this.uniq = uniq; this.freeVars = freeVars; }
public OtpErlangFun(OtpInputStream buf) { OtpErlangFun f = buf.read_fun(); pid = f.pid; module = f.module; arity = f.arity; md5 = f.md5; index = f.index; old_index = f.old_index; uniq = f.uniq; freeVars = f.freeVars; }
public OtpErlangFun(OtpErlangPid pid, String module, int arity, byte[] md5, int index, long old_index, long uniq, OtpErlangObject[] freeVars) { this.pid = pid; this.module = module; this.arity = arity; this.md5 = md5; this.index = index; this.old_index = old_index; this.uniq = uniq; this.freeVars = freeVars; }
public void addLink(OtpErlangPid local, OtpErlangPid remote) { lock (this) { if (find(local, remote) == -1) { if (count >= links.Length) { Link[] tmp = new Link[count * 2]; Array.Copy(links, 0, tmp, 0, count); links = tmp; } links[count++] = new Link(local, remote); } } }
/** * Send a message to a process on a remote node. * * @param dest * the Erlang PID of the remote process. * @param msg * the message to send. * * @exception java.io.IOException * if the connection is not active or a communication * error occurs. */ public void send(OtpErlangPid dest, OtpErlangObject msg) { // encode and send the message base.sendBuf(self.Pid, dest, new OtpOutputStream(msg)); }
/** * Send an exit signal to a remote process. * * @param dest * the Erlang PID of the remote process. * @param reason * an Erlang term describing the exit reason. * * @exception java.io.IOException * if the connection is not active or a communication * error occurs. */ public void exit(OtpErlangPid dest, OtpErlangObject reason) { base.sendExit2(self.Pid, dest, reason); }
/** * <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(OtpErlangPid to) { links.removeLink(self, to); try { String node = to.Node; if (node.Equals(home.Node)) { home.deliver(new OtpMsg(OtpMsg.unlinkTag, self, to)); } else { OtpCookedConnection conn = home.getConnection(node); if (conn != null) { conn.unlink(self, to); } } } catch (Exception) { } }
public bool contains(OtpErlangPid pid) { return local.Equals(pid) || remote.Equals(pid); }
internal OtpActorMbox(OtpActorSched sched, OtpNode home, OtpErlangPid self, String name) : base(home, self, name) { this.sched = sched; }
private void sendExit(int tag, OtpErlangPid from, OtpErlangPid dest, OtpErlangObject reason) { if (!connected) { throw new IOException("Not connected"); } OtpOutputStream header = new OtpOutputStream(headerLen); // preamble: 4 byte length + "passthrough" tag header.write4BE(0); // reserve space for length header.write1(passThrough); header.write1(version); // header header.write_tuple_head(4); header.write_long(tag); header.write_any(from); header.write_any(dest); header.write_any(reason); // fix up length in preamble header.poke4BE(0, header.size() - 4); do_send(header); }
/** * Send a pre-encoded message to a process on a remote node. * * @param dest * the Erlang PID of the remote process. * @param msg * the encoded message to send. * * @exception java.io.IOException * if the connection is not active or a communication error * occurs. */ protected void sendBuf(OtpErlangPid from, OtpErlangPid dest, OtpOutputStream payload) { if (!connected) { throw new IOException("Not connected"); } OtpOutputStream header = new OtpOutputStream(headerLen); // preamble: 4 byte length + "passthrough" tag + version header.write4BE(0); // reserve space for length header.write1(passThrough); header.write1(version); // header info header.write_tuple_head(3); header.write_long(sendTag); if (sendCookie) { header.write_atom(self.Cookie); } else { header.write_atom(""); } header.write_any(dest); // version for payload header.write1(version); // fix up length in preamble header.poke4BE(0, header.size() + payload.size() - 4); do_send(header, payload); }
/* all remote pids get notified about failed pid */ public OtpErlangPid[] remotePids() { lock (this) { OtpErlangPid[] ret = null; if (count != 0) { ret = new OtpErlangPid[count]; for (int i = 0; i < count; i++) { ret[i] = links[i].Remote; } } return ret; } }
public void removeLink(OtpErlangPid local, OtpErlangPid remote) { lock (this) { int i; if ((i = find(local, remote)) != -1) { count--; links[i] = links[count]; links[count] = null; } } }
public int find(OtpErlangPid local, OtpErlangPid remote) { lock (this) { for (int i = 0; i < count; i++) { if (links[i].equals(local, remote)) { return i; } } return -1; } }
public bool exists(OtpErlangPid local, OtpErlangPid remote) { lock (this) { return find(local, remote) != -1; } }
internal OtpActorMbox(OtpActorSched sched, OtpNode home, OtpErlangPid self) : base(home, self, null) { this.sched = sched; }
/** * Send a pre-encoded message to a process on a remote node. * * @param dest * the Erlang PID of the remote process. * @param msg * the encoded message to send. * * @exception java.io.IOException * if the connection is not active or a communication * error occurs. */ public void sendBuf(OtpErlangPid dest, OtpOutputStream payload) { base.sendBuf(self.Pid, dest, payload); }
public void write_fun(OtpErlangPid pid, String module, long old_index, int arity, byte[] md5, long index, long uniq, OtpErlangObject[] freeVars) { if (arity == -1) { write1(OtpExternal.funTag); write4BE(freeVars.Length); pid.encode(this); write_atom(module); write_long(index); write_long(uniq); foreach (OtpErlangObject fv in freeVars) { fv.encode(this); } } else { write1(OtpExternal.newFunTag); int saveSizePos = getPos(); write4BE(0); // this is where we patch in the size write1(arity); writeN(md5); write4BE(index); write4BE(freeVars.Length); write_atom(module); write_long(old_index); write_long(uniq); pid.encode(this); foreach (OtpErlangObject fv in freeVars) { fv.encode(this); } poke4BE(saveSizePos, getPos() - saveSizePos); } }
/** * Remove a link between the local node and the specified process on the * remote node. This method deactivates links created with * {@link #link link()}. * * @param dest * the Erlang PID of the remote process. * * @exception java.io.IOException * if the connection is not active or a communication * error occurs. */ public void unlink(OtpErlangPid dest) { base.sendUnlink(self.Pid, dest); }
// this function used internally when "process" dies // since Erlang discerns between exit and exit/2. private void exit(int arity, OtpErlangPid to, OtpErlangObject reason) { try { String node = to.Node; if (node.Equals(home.Node)) { home.deliver(new OtpMsg(OtpMsg.exitTag, self, to, reason)); } else { 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 (Exception) { } }
/** * Send an exit signal to a remote process. * * @param dest * the Erlang PID of the remote process. * @param reason * an Erlang term describing the exit reason. * * @exception java.io.IOException * if the connection is not active or a communication error * occurs. */ protected void sendExit2(OtpErlangPid from, OtpErlangPid dest, OtpErlangObject reason) { sendExit(exit2Tag, from, dest, reason); }
/* * look up a mailbox based on its pid. If the mailbox has gone out of * scope we also remove the reference from the hashtable so we don't * find it again. */ public OtpMbox get(OtpErlangPid pid) { lock (this) { if (byPid.ContainsKey(pid)) { WeakReference wr = byPid[pid]; OtpMbox m = (OtpMbox)wr.Target; if (m != null) { return m; } byPid.Remove(pid); } return null; } }
/* * this one called explicitely by user code => use exit2 */ public void exit2(OtpErlangPid from, OtpErlangPid to, OtpErlangObject reason) { try { base.sendExit2(from, to, reason); } catch (Exception) { } }
public OtpSelf(String node, String cookie, int port) : base(node, cookie) { sock = new TcpListener(new IPEndPoint(IPAddress.Any, port)); sock.Start(); if (port != 0) { this.port = port; } else { this.port = ((IPEndPoint)sock.LocalEndpoint).Port; } pid = createPid(); }
/* * snoop for outgoing links and update own table */ public void link(OtpErlangPid from, OtpErlangPid to) { lock (this) { try { base.sendLink(from, to); links.addLink(from, to); } catch (IOException) { throw new OtpErlangExit("noproc", to); } } }
/* * send to remote name dest is recipient's registered name, the nodename is * implied by the choice of connection. */ public void send(OtpErlangPid from, String dest, OtpErlangObject msg) { // encode and send the message sendBuf(from, dest, new OtpOutputStream(msg)); }
public Link(OtpErlangPid local, OtpErlangPid remote) { this.local = local; this.remote = remote; }
/* * snoop for outgoing unlinks and update own table */ public void unlink(OtpErlangPid from, OtpErlangPid to) { lock (this) { links.removeLink(from, to); try { base.sendUnlink(from, to); } catch (IOException) { } } }
public bool equals(OtpErlangPid local, OtpErlangPid remote) { return this.local.Equals(local) && this.remote.Equals(remote) || this.local.Equals(remote) && this.remote.Equals(local); }
/** * 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(OtpErlangPid to, OtpErlangObject msg) { try { String node = to.Node; if (node.Equals(home.Node)) { home.deliver(new OtpMsg(to, (OtpErlangObject)msg.Clone())); } else { OtpCookedConnection conn = home.getConnection(node); if (conn == null) { return; } conn.send(self, to, msg); } } catch (Exception) { } }