Exemplo n.º 1
0
 private void removeConnection(OtpCookedConnection conn)
 {
     if (conn != null && conn.Name != null)
     {
         connections.Remove(conn.Name);
     }
 }
Exemplo n.º 2
0
 /**
  * Send a message to a named mailbox created from another node.
  *
  * @param name
  *                the registered name of recipient mailbox.
  *
  * @param node
  *                the name of the remote node where the recipient mailbox is
  *                registered.
  *
  * @param msg
  *                the body of the message to send.
  *
  */
 public void send(String name, String node, OtpErlangObject msg)
 {
     try
     {
         String currentNode = home.Node;
         if (node.Equals(currentNode))
         {
             send(name, msg);
         }
         else if (node.IndexOf('@', 0) < 0 && node.Equals(currentNode.Substring(0, currentNode.IndexOf('@', 0))))
         {
             send(name, msg);
         }
         else
         {
             // other node
             OtpCookedConnection conn = home.getConnection(node);
             if (conn == null)
             {
                 return;
             }
             conn.send(self, name, msg);
         }
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 3
0
        /**
         * Link to a remote mailbox or Erlang process. Links are idempotent, calling
         * this method multiple times will not result in more than one link being
         * created.
         *
         * If the remote process subsequently exits or the mailbox is closed, a
         * subsequent attempt to retrieve a message through this mailbox will cause
         * an {@link OtpErlangExit OtpErlangExit} exception to be raised. Similarly,
         * if the sending mailbox is closed, the linked mailbox or process will
         * receive an exit signal.
         *
         * If the remote process cannot be reached in order to set the link, the
         * exception is raised immediately.
         */
        public void Link(OtpErlangPid to)
        {
            try
            {
                string node = to.Node;
                if (node.Equals(home.Node))
                {
                    if (!home.Deliver(new OtpMsg(OtpMsg.linkTag, Self, to)))
                    {
                        throw new OtpExit("noproc", to);
                    }
                }
                else
                {
                    OtpCookedConnection conn = home.GetConnection(node);
                    if (conn == null)
                    {
                        throw new OtpExit("noproc", to);
                    }
                    conn.Link(Self, to);
                }
            }
            catch (Exception) { }

            links.AddLink(Self, to);
        }
Exemplo n.º 4
0
        /**
         * <p>
         * Link to a remote mailbox or Erlang process. Links are idempotent, calling
         * this method multiple times will not result in more than one link being
         * created.
         * </p>
         *
         * <p>
         * If the remote process subsequently exits or the mailbox is closed, a
         * subsequent attempt to retrieve a message through this mailbox will cause
         * an {@link OtpErlangExit OtpErlangExit} exception to be raised. Similarly,
         * if the sending mailbox is closed, the linked mailbox or process will
         * receive an exit signal.
         * </p>
         *
         * <p>
         * If the remote process cannot be reached in order to set the link, the
         * exception is raised immediately.
         * </p>
         *
         * @param to
         *                the {@link OtpErlangPid pid} representing the object to
         *                link to.
         *
         * @exception OtpErlangExit
         *                    if the {@link OtpErlangPid pid} referred to does not
         *                    exist or could not be reached.
         *
         */
        public void link(OtpErlangPid to)
        {
            try
            {
                String node = to.Node;
                if (node.Equals(home.Node))
                {
                    if (!home.deliver(new OtpMsg(OtpMsg.linkTag, self, to)))
                    {
                        throw new OtpErlangExit("noproc", to);
                    }
                }
                else
                {
                    OtpCookedConnection conn = home.getConnection(node);
                    if (conn != null)
                    {
                        conn.link(self, to);
                    }
                    else
                    {
                        throw new OtpErlangExit("noproc", to);
                    }
                }
            }
            catch (OtpErlangExit e)
            {
                throw e;
            }
            catch (Exception)
            {
            }

            links.addLink(self, to);
        }
Exemplo n.º 5
0
        // this function used internally when "process" dies
        // since Erlang discerns between exit and exit/2.
        private void Exit(int arity, OtpErlangPid to, IOtpErlangObject reason)
        {
            try
            {
                string node = to.Node;
                if (node.Equals(home.Node))
                {
                    home.Deliver(new OtpMsg(OtpMsg.exitTag, Self, to, reason));
                    return;
                }

                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) { }
        }
Exemplo n.º 6
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)
            {
            }
        }
Exemplo n.º 7
0
        /**
         * Close the node. Unpublish the node from Epmd (preventing new connections)
         * and close all existing connections.
         */
        public void close()
        {
            lock (this)
            {
                acceptor.quit();

                mboxes.clear();

                lock (connections)
                {
                    OtpCookedConnection[] conns = new OtpCookedConnection[connections.Count];
                    int i = 0;
                    foreach (OtpCookedConnection conn in connections.Values)
                    {
                        conns[i++] = conn;
                    }
                    connections.Clear();
                    foreach (OtpCookedConnection conn in conns)
                    {
                        conn.close();
                    }
                    initDone = false;
                }
            }
        }
Exemplo n.º 8
0
 void addConnection(OtpCookedConnection conn)
 {
     if (conn != null && conn.Name != null)
     {
         connections.Add(conn.Name, conn);
         remoteStatus(conn.Name, true, null);
     }
 }
Exemplo n.º 9
0
        /**
         * Send a message to a named mailbox created from another node.
         */
        public void Send(string node, string name, IOtpErlangObject msg)
        {
            // this node?
            if (node.Equals(home.Node) || node.Equals(home.Alive))
            {
                Send(name, msg);
                return;
            }

            // other node
            OtpCookedConnection conn = home.GetConnection(node);

            if (conn == null)
            {
                return;
            }

            conn.Send(Self, name, msg);
        }
Exemplo n.º 10
0
        /**
         * Send a message to a remote {@link OtpErlangPid pid}, representing either
         * another {@link OtpMbox mailbox} or an Erlang process.
         */
        public void Send(OtpErlangPid to, IOtpErlangObject msg)
        {
            string node = to.Node;

            if (node.Equals(home.Node))
            {
                home.Deliver(new OtpMsg(to, (IOtpErlangObject)msg.Clone()));
                return;
            }

            OtpCookedConnection conn = home.GetConnection(node);

            if (conn == null)
            {
                return;
            }

            conn.Send(Self, to, msg);
        }
Exemplo n.º 11
0
        /*
         * find or create a connection to the given node
         */
        public OtpCookedConnection getConnection(String node)
        {
            OtpPeer             peer = null;
            OtpCookedConnection conn = null;

            lock (connections)
            {
                // first just try looking up the name as-is

                if (connections.ContainsKey(node))
                {
                    conn = connections[node];
                }
                else
                {
                    // in case node had no '@' add localhost info and try again
                    peer = new OtpPeer(node);

                    if (connections.ContainsKey(peer.Node))
                    {
                        conn = connections[peer.Node];
                    }
                    else
                    {
                        try
                        {
                            conn = new OtpCookedConnection(this, peer);
                            conn.setFlags(flags);
                            addConnection(conn);
                        }
                        catch (Exception e)
                        {
                            /* false = outgoing */
                            connAttempt(peer.Node, false, e);
                        }
                    }
                }
                return(conn);
            }
        }
Exemplo n.º 12
0
        /**
         * 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}.
         */
        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) { }
        }
Exemplo n.º 13
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)
     {
     }
 }
Exemplo n.º 14
0
 void addConnection(OtpCookedConnection conn)
 {
     if (conn != null && conn.Name != null)
     {
         connections.Add(conn.Name, conn);
         remoteStatus(conn.Name, true, null);
     }
 }
Exemplo n.º 15
0
        /*
         * find or create a connection to the given node
         */
        public OtpCookedConnection getConnection(String node)
        {
            OtpPeer peer = null;
            OtpCookedConnection conn = null;

            lock (connections)
            {
                // first just try looking up the name as-is

                if (connections.ContainsKey(node))
                {
                    conn = connections[node];
                }
                else
                {
                    // in case node had no '@' add localhost info and try again
                    peer = new OtpPeer(node);

                    if (connections.ContainsKey(peer.Node))
                    {
                        conn = connections[peer.Node];
                    }
                    else
                    {
                        try
                        {
                            conn = new OtpCookedConnection(this, peer);
                            conn.setFlags(flags);
                            addConnection(conn);
                        }
                        catch (Exception e)
                        {
                            /* false = outgoing */
                            connAttempt(peer.Node, false, e);
                        }
                    }
                }
                return conn;
            }
        }
Exemplo n.º 16
0
 /*
  * OtpCookedConnection delivers errors here, we send them on to the handler
  * specified by the application
  */
 public void deliverError(OtpCookedConnection conn, Exception e)
 {
     removeConnection(conn);
     remoteStatus(conn.Name, false, e);
 }
Exemplo n.º 17
0
        /**
         * Close the node. Unpublish the node from Epmd (preventing new connections)
         * and close all existing connections.
         */
        public void close()
        {
            lock (this)
            {
                acceptor.quit();

                mboxes.clear();

                lock (connections)
                {
                    OtpCookedConnection[] conns = new OtpCookedConnection[connections.Count];
                    int i = 0;
                    foreach (OtpCookedConnection conn in connections.Values)
                    {
                        conns[i++] = conn;
                    }
                    connections.Clear();
                    foreach (OtpCookedConnection conn in conns)
                    {
                        conn.close();
                    }
                    initDone = false;
                }
            }
        }
Exemplo n.º 18
0
            public override void run()
            {
                TcpClient           newsock = null;
                OtpCookedConnection conn    = null;

                node.localStatus(node.Node, true, null);

                accept_loop : while (!done)
                {
                    conn = null;

                    try
                    {
                        newsock = sock.AcceptTcpClient();
                    }
                    catch (Exception e)
                    {
                        // Problem in java1.2.2: accept throws SocketException
                        // when socket is closed. This will happen when
                        // acceptor.quit()
                        // is called. acceptor.quit() will call localStatus(...), so
                        // we have to check if that's where we come from.
                        if (!done)
                        {
                            node.localStatus(node.Node, false, e);
                        }
                        goto accept_loop;
                    }

                    try
                    {
                        lock (node.Connections)
                        {
                            conn = new OtpCookedConnection(node, new BufferedTcpClient(newsock));
                            conn.setFlags(node.Flags);
                            node.addConnection(conn);
                        }
                    }
                    catch (OtpAuthException e)
                    {
                        if (conn != null && conn.Name != null)
                        {
                            node.connAttempt(conn.Name, true, e);
                        }
                        else
                        {
                            node.connAttempt("unknown", true, e);
                        }
                        closeSock(newsock);
                    }
                    catch (IOException e)
                    {
                        if (conn != null && conn.Name != null)
                        {
                            node.connAttempt(conn.Name, true, e);
                        }
                        else
                        {
                            node.connAttempt("unknown", true, e);
                        }
                        closeSock(newsock);
                    }
                    catch (Exception e)
                    {
                        closeSock(newsock);
                        closeSock(sock);
                        node.localStatus(node.Node, false, e);
                        goto accept_loop;
                    }
                } // while

                // if we have exited loop we must do this too
                unPublishPort();
            }
Exemplo n.º 19
0
 private void removeConnection(OtpCookedConnection conn)
 {
     if (conn != null && conn.Name != null)
     {
         connections.Remove(conn.Name);
     }
 }
Exemplo n.º 20
0
            public override void run()
            {
                TcpClient newsock = null;
                OtpCookedConnection conn = null;

                node.localStatus(node.Node, true, null);

                accept_loop: while (!done)
                {
                    conn = null;

                    try
                    {
                        newsock = sock.AcceptTcpClient();
                    }
                    catch (Exception e)
                    {
                        // Problem in java1.2.2: accept throws SocketException
                        // when socket is closed. This will happen when
                        // acceptor.quit()
                        // is called. acceptor.quit() will call localStatus(...), so
                        // we have to check if that's where we come from.
                        if (!done)
                        {
                            node.localStatus(node.Node, false, e);
                        }
                        goto accept_loop;
                    }

                    try
                    {
                        lock (node.Connections)
                        {
                            conn = new OtpCookedConnection(node, new BufferedTcpClient(newsock));
                            conn.setFlags(node.Flags);
                            node.addConnection(conn);
                        }
                    }
                    catch (OtpAuthException e)
                    {
                        if (conn != null && conn.Name != null)
                        {
                            node.connAttempt(conn.Name, true, e);
                        }
                        else
                        {
                            node.connAttempt("unknown", true, e);
                        }
                        closeSock(newsock);
                    }
                    catch (IOException e)
                    {
                        if (conn != null && conn.Name != null)
                        {
                            node.connAttempt(conn.Name, true, e);
                        }
                        else
                        {
                            node.connAttempt("unknown", true, e);
                        }
                        closeSock(newsock);
                    }
                    catch (Exception e)
                    {
                        closeSock(newsock);
                        closeSock(sock);
                        node.localStatus(node.Node, false, e);
                        goto accept_loop;
                    }
                } // while

                // if we have exited loop we must do this too
                unPublishPort();
            }
Exemplo n.º 21
0
 /*
  * OtpCookedConnection delivers errors here, we send them on to the handler
  * specified by the application
  */
 public void deliverError(OtpCookedConnection conn, Exception e)
 {
     removeConnection(conn);
     remoteStatus(conn.Name, false, e);
 }