elementAt() 공개 메소드

public elementAt ( int i ) : OtpErlangObject
i int
리턴 OtpErlangObject
예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
        /**
         * Receive an RPC reply from the remote Erlang node. This convenience
         * function receives a message from the remote node, and expects it to have
         * the following format:
         *
         * <pre>
         * { rex, Term }
         * </pre>
         *
         * @return the second element of the tuple if the received message is a
         *         two-tuple, otherwise null. No further error checking is
         *         performed.
         *
         * @exception java.io.IOException
         *                    if the connection is not active or a communication
         *                    error occurs.
         *
         * @exception OtpErlangExit
         *                    if an exit signal is received from a process on the
         *                    peer node.
         *
         * @exception OtpAuthException
         *                    if the remote node sends a message containing an
         *                    invalid cookie.
         */
        public OtpErlangObject receiveRPC()
        {
            OtpErlangObject msg = receive();

            if (msg is OtpErlangTuple)
            {
                OtpErlangTuple t = (OtpErlangTuple)msg;
                if (t.arity() == 2)
                {
                    return(t.elementAt(1)); // obs: second element
                }
            }

            return(null);
        }
 /// <summary>Extracts the name value from tuple.</summary>
 /// <param name="value">The value.</param>
 /// <returns>The name value.</returns>
 private string ExtractNameValueFromTuple(OtpErlangTuple value)
 {
     object nameElement = value.elementAt(3);
     return new UTF8Encoding().GetString(((OtpErlangBinary)nameElement).binaryValue());
 }