Exemplo n.º 1
0
        public void run()
        {
            Console.WriteLine("-=-=-=-=- Add 1 object -=-=-=-=-");
            q.Add(1);

            Console.WriteLine("-=-=-=-=- Peek 5sec -=-=-=-=-");
            Console.WriteLine("Peek: " + q.peek(5000));
            Console.WriteLine("-=-=-=-=- Remove 5sec -=-=-=-=-");
            Console.WriteLine("Remv: " + q.Remove(5000));
            Console.WriteLine("-=-=-=-=- Peek 5sec -=-=-=-=-");
            Console.WriteLine("Peek: " + q.peek(5000));
            Console.WriteLine("-=-=-=-=- Add 1 object -=-=-=-=-");
            q.Add(1);
            Console.WriteLine("-=-=-=-=- Remove 5sec -=-=-=-=-");
            Console.WriteLine("Remv: " + q.Remove(5000));
            Console.WriteLine("-=-=-=-=- Remove 5sec -=-=-=-=-");
            Console.WriteLine("Remv: " + q.Remove(5000));
            Console.WriteLine("-=-=-=-=- Close Queue -=-=-=-=-");
            q.close();
            Console.WriteLine("Closed?: " + q.Closed);

            try
            {
                Console.WriteLine("-=-=-=-=- Remove 5sec -=-=-=-=-");
                Console.WriteLine("Remv: " + q.Remove());
            }
            catch (Exception e)
            {
                Console.WriteLine("-=-=-=-=- Exception Thrown -=-=-=-=-");
                Console.WriteLine("Exception: " + e.Message);
            }
        }
Exemplo n.º 2
0
 /// <remarks>
 /// If the down_handler thread
 /// is not available (down_thread == false), then directly call the down() method, else add the
 /// event to the down queue.
 /// </remarks>
 /// <summary>
 /// Receive an event from the layer above
 /// </summary>
 /// <param name="evt">Event passed down</param>
 protected virtual void receiveDownEvent(Event evt)
 {
     if (down_handler == null)
     {
         down(evt);
         return;
     }
     try
     {
         down_queue.Add(evt);
     }
     catch (Exception e)
     {
         if (Trace.trace)
         {
             Trace.warn("Protocol.receiveDownEvent()", "exception: " + e);
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Called by the ProtocolSinkStack when messages are recevied.
        /// </summary>
        /// <param name="evt">Event that has been received.</param>
        public void up(Event evt)
        {
            int     type = evt.Type;
            Message msg;

            /*if the queue is not available, there is no point in
             * processing the message at all*/
            if (mq == null)
            {
                if (Trace.trace)
                {
                    Trace.error("GroupChannel.up()", "message queue is null");
                }
                return;
            }

            switch (type)
            {
            case Event.MSG:
                msg = (Message)evt.Arg;
                if (!receive_local_msgs)
                {                          // discard local messages (sent by myself to me)
                    if (local_addr != null && msg.Source != null)
                    {
                        if (local_addr.Equals(msg.Source))
                        {
                            return;
                        }
                    }
                }
                break;

            case Event.VIEW_CHANGE:
                my_view = (View)evt.Arg;
                if (!receive_views)                                 // discard if client has not set receving views to on
                {
                    return;
                }
                break;

            case Event.SUSPECT:
                if (!receive_suspects)
                {
                    return;
                }
                break;

            case Event.CONNECT_OK:
                lock (connect_mutex)
                {
                    Monitor.Pulse(connect_mutex);
                }
                break;

            case Event.DISCONNECT_OK:
                lock (disconnect_mutex)
                {
                    Monitor.Pulse(disconnect_mutex);
                }
                break;

            case Event.SET_LOCAL_ADDRESS:
                local_addr = (Address)evt.Arg;
                break;

            case Event.EXIT:
                handleExit(evt);
                return;                                  // no need to pass event up; already done in handleExit()

            default:
                break;
            }


            // If UpHandler is installed, pass all events to it and return (UpHandler is e.g. a building block)
            if (up_handler != null)
            {
                up_handler.up(evt);
                return;
            }
            if (type == Event.MSG || type == Event.VIEW_CHANGE || type == Event.SUSPECT ||
                type == Event.EXIT)                  //type == Event.GET_APPLSTATE || type == Event.BLOCK
            {
                try
                {
                    mq.Add(evt);
                }
                catch (Exception e)
                {
                    if (Trace.trace)
                    {
                        Trace.error("GroupChannel.up()", "exception: " + e);
                    }
                }
            }
        }