示例#1
0
        /**
         * Wait for a message to arrive for this mailbox.
         *
         * @param timeout
         *                the time, in milliseconds, to wait for a message.
         *
         * @return an {@link OtpMsg OtpMsg} containing the header information as
         *         well as the body of the next message waiting in this mailbox.
         *
         * @exception OtpErlangExit
         *                    if a linked {@link OtpErlangPid pid} has exited or has
         *                    sent an exit signal to this mailbox.
         *
         * @exception InterruptedException
         *                    if no message if the method times out before a message
         *                    becomes available.
         */
        public virtual OtpMsg receiveMsg(long timeout)
        {
            OtpMsg m = (OtpMsg)queue.get(timeout);

            if (m == null)
            {
                return(null);
            }

            switch (m.type())
            {
            case OtpMsg.exitTag:
            case OtpMsg.exit2Tag:
                try
                {
                    OtpErlangObject o = m.getMsg();
                    throw new OtpErlangExit(o, m.getSenderPid());
                }
                catch (OtpErlangDecodeException)
                {
                    throw new OtpErlangExit("unknown", m.getSenderPid());
                }

            default:
                return(m);
            }
        }
示例#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);
        }
示例#3
0
 /**
  * Wait for a message to arrive for this mailbox.
  *
  * @param timeout
  *                the time, in milliseconds, to wait for a message before
  *                returning null.
  *
  * @return an {@link OtpErlangObject OtpErlangObject} representing the body
  *         of the next message waiting in this mailbox.
  *
  * @exception OtpErlangDecodeException
  *                    if the message can not be decoded.
  *
  * @exception OtpErlangExit
  *                    if a linked {@link OtpErlangPid pid} has exited or has
  *                    sent an exit signal to this mailbox.
  */
 public OtpErlangObject receive(long timeout)
 {
     try
     {
         OtpMsg m = receiveMsg(timeout);
         if (m != null)
         {
             return(m.getMsg());
         }
     }
     catch (OtpErlangExit e)
     {
         throw e;
     }
     catch (OtpErlangDecodeException f)
     {
         throw f;
     }
     catch (ThreadInterruptedException)
     {
     }
     return(null);
 }
示例#4
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;
        }