Inheritance: OtpErlangObject
示例#1
0
 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;
 }
示例#2
0
 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;
 }
示例#3
0
 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;
 }
示例#4
0
 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);
         }
     }
 }
示例#5
0
 /**
  * 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));
 }
示例#6
0
 /**
  * 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);
 }
示例#7
0
        /**
         * <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)
            {
            }
        }
示例#8
0
 public bool contains(OtpErlangPid pid)
 {
     return local.Equals(pid) || remote.Equals(pid);
 }
示例#9
0
 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);
        }
示例#12
0
 /* 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;
     }
 }
示例#13
0
        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;
                }
            }
        }
示例#14
0
 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;
     }
 }
示例#15
0
 public bool exists(OtpErlangPid local, OtpErlangPid remote)
 {
     lock (this)
     {
         return find(local, remote) != -1;
     }
 }
示例#16
0
 internal OtpActorMbox(OtpActorSched sched, OtpNode home, OtpErlangPid self)
     : base(home, self, null)
 {
     this.sched = sched;
 }
示例#17
0
 /**
  * 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);
 }
示例#18
0
 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);
     }
 }
示例#19
0
 /**
  * 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);
 }
示例#20
0
        // 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);
 }
示例#22
0
            /*
             * 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)
     {
     }
 }
示例#24
0
        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));
 }
示例#27
0
 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)
         {
         }
     }
 }
示例#29
0
 public bool equals(OtpErlangPid local, OtpErlangPid remote)
 {
     return this.local.Equals(local) && this.remote.Equals(remote)
     || this.local.Equals(remote) && this.remote.Equals(local);
 }
示例#30
0
 /**
  * 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)
     {
     }
 }