Пример #1
0
        /*
         * called by OtpNode to deliver message to this mailbox.
         *
         * About exit and exit2: both cause exception to be raised upon
         * receive(). However exit (not 2) causes any link to be removed as
         * well, while exit2 leaves any links intact.
         */
        internal virtual void  deliver(OtpMsg m)
        {
            switch (m.type())
            {
            case OtpMsg.Tag.linkTag:
                links.addLink(_self, m.getSenderPid());
                break;

            case OtpMsg.Tag.unlinkTag:
                links.removeLink(_self, m.getSenderPid());
                break;

            case OtpMsg.Tag.exitTag:
                links.removeLink(_self, m.getSenderPid());
                queue.put(m);
                break;

            case OtpMsg.Tag.monitorPTag:
                monitors[m.getSenderPid()] = m.getMsg();
                break;

            case OtpMsg.Tag.demonitorPTag:
                monitors.Remove(m.getSenderPid());
                break;

            case OtpMsg.Tag.monitorPexitTag:
                queue.put(m);
                break;

            case OtpMsg.Tag.exit2Tag:
            default:
                queue.put(m);
                break;
            }
        }
Пример #2
0
        /*
         * this method simulates net_kernel only for
         * the purpose of replying to pings.
         */
        private bool netKernel(OtpMsg m)
        {
            OtpMbox mbox = null;

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

                Erlang.Pid pid = (Erlang.Pid)req.elementAt(0);                  // originating pid

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

                mbox = createMbox();
                mbox.send(pid, new Erlang.Tuple(pong));
                return(true);
            }
            catch (System.Exception)
            {
            }
            finally
            {
                closeMbox(mbox);
            }
            return(false);
        }
Пример #3
0
        /*
         * pass the message to the node for final delivery. Note that the
         * connection itself needs to know about links (in case of connection
         * failure), so we snoop for link/unlink too here.
         */
        public override void  deliver(OtpMsg msg)
        {
            bool delivered = self.deliver(msg);

            switch (msg.type())
            {
            case OtpMsg.Tag.linkTag:
                if (delivered)
                {
                    links.addLink(msg.getRecipientPid(), msg.getSenderPid());
                }
                else
                {
                    try
                    {
                        // no such pid - send exit to sender
                        base.sendExit(msg.getRecipientPid(), msg.getSenderPid(), "noproc");
                    }
                    catch (System.IO.IOException)
                    {
                    }
                }
                break;

            case OtpMsg.Tag.monitorPTag:
                if (delivered)
                {
                    monitors[msg.getSenderPid()] = msg.getMsg();
                }
                else
                {
                    try
                    {
                        base.sendExit(msg.getRecipientPid(), msg.getSenderPid(), "noproc");
                    }
                    catch (System.IO.IOException)
                    {
                    }
                }
                break;

            case OtpMsg.Tag.demonitorPTag:
            case OtpMsg.Tag.monitorPexitTag:
                monitors.Remove(msg.getSenderPid());
                break;

            case OtpMsg.Tag.unlinkTag:
            case OtpMsg.Tag.exitTag:
                links.removeLink(msg.getRecipientPid(), msg.getSenderPid());
                break;

            case OtpMsg.Tag.exit2Tag:
                break;
            }
            return;
        }
Пример #4
0
 /*
  * Receive a message from a remote process. This method blocks at
  * most for the specified time, until a valid message is received or
  * an exception is raised.
  *
  * <p> If the remote node sends a message that cannot be decoded
  * properly, the connection is closed and the method throws an
  * exception.
  *
  * @param timeout the time in milliseconds that this operation will
  * block. Specify 0 to poll the queue.
  *
  * @return an object containing a single Erlang term.
  *
  * @exception C#.io.IOException if the connection is not active or
  * a communication error occurs.
  *
  * @exception Erlang.Exit 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.
  *
  * @exception InterruptedException if no message if the method
  * times out before a message becomes available.
  **/
 public virtual Erlang.Object receive(long timeout)
 {
     try
     {
         OtpMsg msg = receiveMsg(timeout);
         return(msg == null ? null : msg.getMsg());
     }
     catch (Erlang.DecodeException e)
     {
         close();
         throw new System.IO.IOException(e.Message);
     }
 }
Пример #5
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 Object Object} representing
  * the body of the next message waiting in this mailbox.
  *
  * @exception Exit if a linked {@link Pid pid} has
  * exited or has sent an exit signal to this mailbox.
  *
  **/
 public virtual Erlang.Object receive(long timeout)
 {
     try
     {
         OtpMsg m = receiveMsg(timeout);
         if (m != null)
         {
             return(m.getMsg());
         }
     }
     catch (Erlang.Exit e)
     {
         throw e;
     }
     catch (System.Exception)
     {
     }
     return(null);
 }
Пример #6
0
        /*
         * OtpCookedConnection delivers messages here
         * return true if message was delivered successfully, or false otherwise.
         */
        internal virtual bool deliver(OtpMsg m)
        {
            OtpMbox mbox = null;

            try
            {
                OtpMsg.Tag t = m.type();

                if (t == OtpMsg.Tag.regSendTag)
                {
                    System.String name = m.getRecipientName();
                    /*special case for netKernel requests */
                    if (name.Equals("net_kernel"))
                    {
                        return(netKernel(m));
                    }
                    else
                    {
                        mbox = mboxes.get(name);
                    }
                }
                else
                {
                    mbox = mboxes.get(m.getRecipientPid());
                }
                if (mbox == null)
                {
                    return(false);
                }
                mbox.deliver(m);
            }
            catch (System.Exception)
            {
                return(false);
            }

            return(true);
        }
Пример #7
0
 public override void  deliver(OtpMsg msg)
 {
     queue.put(msg);
 }
Пример #8
0
        /*
         * Receive a raw (still encoded) message from a remote process. This
         * message blocks at most for the specified time until a valid
         * message is received or an exception is raised.
         *
         * <p> If the remote node sends a message that cannot be decoded
         * properly, the connection is closed and the method throws an
         * exception.
         *
         * @param timeout the time in milliseconds that this operation will
         * block. Specify 0 to poll the queue.
         *
         * @return an object containing a raw (still encoded) Erlang term.
         *
         * @exception C#.io.IOException if the connection is not active or
         * a communication error occurs.
         *
         * @exception Erlang.Exit if an exit signal is received from a
         * process on the peer node, or if the connection is lost for any
         * reason.
         *
         * @exception OtpAuthException if the remote node
         * sends a message containing an invalid cookie.
         *
         * @exception InterruptedException if no message if the method
         * times out before a message becomes available.
         **/
        public virtual OtpInputStream receiveBuf(long timeout)
        {
            OtpMsg str = receiveMsg(timeout);

            return(str != null?str.getMsgBuf() : null);
        }
Пример #9
0
        /*
        * called by OtpNode to deliver message to this mailbox.
        *
        * About exit and exit2: both cause exception to be raised upon
        * receive(). However exit (not 2) causes any link to be removed as
        * well, while exit2 leaves any links intact.
        */
        internal virtual void deliver(OtpMsg m)
        {
            switch (m.type())
            {
                case OtpMsg.linkTag:
                    links.addLink(_self, m.getSenderPid());
                    break;

                case OtpMsg.unlinkTag:
                    links.removeLink(_self, m.getSenderPid());
                    break;

                case OtpMsg.exitTag:
                    links.removeLink(_self, m.getSenderPid());
                    queue.put(m);
                    break;

                case OtpMsg.exit2Tag: default:
                    queue.put(m);
                    break;
            }
        }
Пример #10
0
 /*
 * Deliver messages to the recipient.
 **/
 public abstract void  deliver(OtpMsg msg);
Пример #11
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 a byte array representing the still-encoded body of the
         * next message waiting in this mailbox.
         *
         * @exception Exit if a linked {@link Pid 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 OtpInputStream receiveBuf(long timeout)
        {
            OtpMsg m = receiveMsg();

            return(m == null ? null : m.getMsgBuf());
        }
Пример #12
0
		/*
		* pass the message to the node for final delivery. Note that the
		* connection itself needs to know about links (in case of connection
		* failure), so we snoop for link/unlink too here.
		*/
		public override void  deliver(OtpMsg msg)
		{
			bool delivered = self.deliver(msg);

			switch (msg.type())
			{
				case OtpMsg.Tag.linkTag:
					if (delivered)
					{
						links.addLink(msg.getRecipientPid(), msg.getSenderPid());
					}
					else
						try
						{
							// no such pid - send exit to sender
							base.sendExit(msg.getRecipientPid(), msg.getSenderPid(), "noproc");
						}
						catch (System.IO.IOException)
						{
						}
					break;

                case OtpMsg.Tag.monitorPTag:
                    if (delivered)
                        monitors[msg.getSenderPid()] = msg.getMsg();
                    else
                        try
                        {
                            base.sendExit(msg.getRecipientPid(), msg.getSenderPid(), "noproc");
                        }
                        catch (System.IO.IOException)
                        {
                        }
                    break;

                case OtpMsg.Tag.demonitorPTag:
                case OtpMsg.Tag.monitorPexitTag:
                    monitors.Remove(msg.getSenderPid());
                    break;

                case OtpMsg.Tag.unlinkTag:
                case OtpMsg.Tag.exitTag:
					links.removeLink(msg.getRecipientPid(), msg.getSenderPid());
					break;

                case OtpMsg.Tag.exit2Tag:
					break;
			}
			return ;
		}
Пример #13
0
		/*
		* OtpCookedConnection delivers messages here
		* return true if message was delivered successfully, or false otherwise.
		*/
		internal virtual bool deliver(OtpMsg m)
		{
			OtpMbox mbox = null;
			
			try
			{
                OtpMsg.Tag t = m.type();
				
				if (t == OtpMsg.Tag.regSendTag)
				{
					System.String name = m.getRecipientName();
					/*special case for netKernel requests */
					if (name.Equals("net_kernel"))
						return netKernel(m);
					else
						mbox = mboxes.get(name);
				}
				else
				{
					mbox = mboxes.get(m.getRecipientPid());
				}
				if (mbox == null)
					return false;
				mbox.deliver(m);
			}
			catch (System.Exception)
			{
				return false;
			}
			
			return true;
		}
Пример #14
0
		/*
		* this method simulates net_kernel only for
		* the purpose of replying to pings.
		*/
		private bool netKernel(OtpMsg m)
		{
			OtpMbox mbox = null;
			try
			{
				Erlang.Tuple t = (Erlang.Tuple) (m.getMsg());
				Erlang.Tuple req = (Erlang.Tuple) t.elementAt(1); // actual request
				
				Erlang.Pid pid = (Erlang.Pid) req.elementAt(0); // originating pid
				
				Erlang.Object[] pong = new Erlang.Object[2];
				pong[0] = req.elementAt(1); // his #Ref
				pong[1] = new Erlang.Atom("yes");
				
				mbox = createMbox();
				mbox.send(pid, new Erlang.Tuple(pong));
				return true;
			}
			catch (System.Exception)
			{
			}
			finally
			{
				closeMbox(mbox);
			}
			return false;
		}
Пример #15
0
		/*
		* called by OtpNode to deliver message to this mailbox.
		*
		* About exit and exit2: both cause exception to be raised upon
		* receive(). However exit (not 2) causes any link to be removed as
		* well, while exit2 leaves any links intact.
		*/
		internal virtual void  deliver(OtpMsg m)
		{
			switch (m.type())
			{
                case OtpMsg.Tag.linkTag: 
					links.addLink(_self, m.getSenderPid());
					break;

                case OtpMsg.Tag.unlinkTag:
					links.removeLink(_self, m.getSenderPid());
					break;

                case OtpMsg.Tag.exitTag:
					links.removeLink(_self, m.getSenderPid());
					queue.put(m);
					break;

                case OtpMsg.Tag.monitorPTag:
                    monitors[m.getSenderPid()] = m.getMsg();
                    break;

                case OtpMsg.Tag.demonitorPTag:
                    monitors.Remove(m.getSenderPid());
                    break;

                case OtpMsg.Tag.monitorPexitTag:
                    queue.put(m);
                    break;

                case OtpMsg.Tag.exit2Tag:
                default:
					queue.put(m);
					break;
			}
		}
Пример #16
0
		public override void  deliver(OtpMsg msg)
		{
			queue.put(msg);
		}