Exemple #1
0
        /**
         * <p>
         * Determine if another node is alive. This method has the side effect of
         * setting up a connection to the remote node (if possible). Only a single
         * outgoing message is sent; the timeout is how long to wait for a response.
         * </p>
         *
         * <p>
         * Only a single attempt is made to connect to the remote node, so for
         * example it is not possible to specify an extremely long timeout and
         * expect to be notified when the node eventually comes up. If you wish to
         * wait for a remote node to be started, the following construction may be
         * useful:
         * </p>
         *
         * <pre>
         * // ping every 2 seconds until positive response
         * while (!me.ping(him, 2000))
         *     ;
         * </pre>
         *
         * @param node
         *            the name of the node to ping.
         *
         * @param timeout
         *            the time, in milliseconds, to wait for response before
         *            returning false.
         *
         * @return true if the node was alive and the correct ping response was
         *         returned. false if the correct response was not returned on time.
         */
        /*
         * internal info about the message formats...
         *
         * the request: -> REG_SEND {6,#Pid<[email protected]>,'',net_kernel}
         * {'$gen_call',{#Pid<[email protected]>,#Ref<[email protected]>},{is_auth,bingo@aule}}
         *
         * the reply: <- SEND {2,'',#Pid<[email protected]>} {#Ref<[email protected]>,yes}
         */
        public bool ping(String node, long timeout)
        {
            if (node.Equals(this.Node))
            {
                return(true);
            }
            else if (node.IndexOf('@', 0) < 0 && node.Equals(this.Node.Substring(0, this.Node.IndexOf('@', 0))))
            {
                return(true);
            }

            // other node
            OtpMbox mbox = null;

            try
            {
                mbox = createMbox(true);
                mbox.send("net_kernel", node, getPingTuple(mbox));
                OtpErlangObject reply = mbox.receive(timeout);
                OtpErlangTuple  t     = (OtpErlangTuple)reply;
                OtpErlangAtom   a     = (OtpErlangAtom)t.elementAt(1);
                return("yes".Equals(a.atomValue()));
            }
            catch (Exception)
            {
            }
            finally
            {
                closeMbox(mbox);
            }
            return(false);
        }
Exemple #2
0
        /*
         * this method simulates net_kernel only for the purpose of replying to
         * pings.
         */
        private bool netKernel(OtpMsg m)
        {
            OtpMbox mbox = null;

            try
            {
                OtpErlangTuple t   = (OtpErlangTuple)m.getMsg();
                OtpErlangTuple req = (OtpErlangTuple)t.elementAt(1); // actual
                // request

                OtpErlangPid pid = (OtpErlangPid)req.elementAt(0); // originating
                // pid

                OtpErlangObject[] pong = new OtpErlangObject[2];
                pong[0] = req.elementAt(1); // his #Ref
                pong[1] = new OtpErlangAtom("yes");

                mbox = createMbox(true);
                mbox.send(pid, new OtpErlangTuple(pong));
                return(true);
            }
            catch (Exception)
            {
            }
            finally
            {
                closeMbox(mbox);
            }
            return(false);
        }
Exemple #3
0
        public static OtpErlangTuple Load(OtpMbox mbox, OtpErlangPid pid, string script)
        {
            OtpErlangObject body;
            OtpErlangBoolean debug = new OtpErlangBoolean(false);
            OtpErlangObject message;

            if (script.Length <= 65535)
            {
                body = new OtpErlangString(script);
            }
            else
            {
                body = new OtpErlangBinary(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(script));
            }
            message = new OtpErlangTuple(new OtpErlangObject[] { mbox.Self, new OtpErlangAtom("load"), body, debug });

            mbox.send(pid, message);
            OtpErlangTuple reply = (OtpErlangTuple)mbox.receive();
            Console.WriteLine("Load: {0}", reply);

            return reply;
        }