Пример #1
0
        /// <summary>
        /// Processes <c>Events</c> traveling down the stack
        /// </summary>
        /// <param name="evt">The Event to be processed</param>
        public override void down(Event evt)
        {
            Message        msg;
            Object         dst;
            Entry          entry;
            UnicastHeader  hdr;

            switch(evt.Type)
            {

                case Event.MSG: // Add UnicastHeader, add to AckSenderWindow and pass down
                    msg=(Message)evt.Arg;
                    dst=msg.Destination;

                    /* only handle unicast messages */
                    if(dst == null || ((Address)dst).isMulticastAddress())
                        break;

                    entry = (Entry)connections[dst];
                    if(entry == null)
                    {
                        entry = new Entry(this);
                        connections.Add(dst, entry);
                    }

                    hdr = new UnicastHeader(UnicastHeader.DATA, entry.sent_msgs_seqno);
                    if(entry.sent_msgs == null)
                    { // first msg to peer 'dst'
                        hdr.first=true;
                        entry.sent_msgs = new AckSenderWindow(this, timeout, this);
                        if(window_size > 0)
                            entry.sent_msgs.setWindowSize(window_size, min_threshold);
                    }
                    msg.putHeader(getName(), hdr);

                    if(Trace.trace)
                        Trace.info("UNICAST.down()", "[" + local_addr + "] --> DATA(" + dst + ": #" + entry.sent_msgs_seqno + ", first=" + hdr.first + ")");
                    entry.sent_msgs.add(entry.sent_msgs_seqno, msg);	 // add *including* UnicastHeader
                    entry.sent_msgs_seqno++;
                    return; // AckSenderWindow will send message for us

                case Event.BECOME_SERVER:
                    operational=true;
                    break;

                case Event.VIEW_CHANGE:  // remove connections to peers that are not members anymore !
                    ArrayList new_members=((View)evt.Arg).getMembers();
                    ArrayList left_members = new ArrayList();
                    lock(members)
                    {
                        foreach(Address a in members)
                            left_members.Add(a.Copy());
                        members.Clear();
                        if(new_members != null)
                            members.AddRange(new_members);

                        foreach(Address a in members)
                        {
                            if(left_members.Contains(a))
                                left_members.Remove(a);
                        }

                        foreach(Address oldMbr in left_members)
                        {
                            entry=(Entry)connections[oldMbr];
                            entry.reset();
                            connections.Remove(oldMbr);
                        }
                    }
                    break;
            }  // switch
            passDown(evt);          // Pass on to the layer below us
        }
Пример #2
0
        /// <summary>
        /// Processes <c>Events</c> traveling down the stack
        /// </summary>
        /// <param name="evt">The Event to be processed</param>
        public override void down(Event evt)
        {
            Message       msg;
            Object        dst;
            Entry         entry;
            UnicastHeader hdr;

            switch (evt.Type)
            {
            case Event.MSG:                     // Add UnicastHeader, add to AckSenderWindow and pass down
                msg = (Message)evt.Arg;
                dst = msg.Destination;

                /* only handle unicast messages */
                if (dst == null || ((Address)dst).isMulticastAddress())
                {
                    break;
                }

                entry = (Entry)connections[dst];
                if (entry == null)
                {
                    entry = new Entry(this);
                    connections.Add(dst, entry);
                }

                hdr = new UnicastHeader(UnicastHeader.DATA, entry.sent_msgs_seqno);
                if (entry.sent_msgs == null)
                {                         // first msg to peer 'dst'
                    hdr.first       = true;
                    entry.sent_msgs = new AckSenderWindow(this, timeout, this);
                    if (window_size > 0)
                    {
                        entry.sent_msgs.setWindowSize(window_size, min_threshold);
                    }
                }
                msg.putHeader(getName(), hdr);

                if (Trace.trace)
                {
                    Trace.info("UNICAST.down()", "[" + local_addr + "] --> DATA(" + dst + ": #" + entry.sent_msgs_seqno + ", first=" + hdr.first + ")");
                }
                entry.sent_msgs.add(entry.sent_msgs_seqno, msg); // add *including* UnicastHeader
                entry.sent_msgs_seqno++;
                return;                                          // AckSenderWindow will send message for us

            case Event.BECOME_SERVER:
                operational = true;
                break;

            case Event.VIEW_CHANGE:                      // remove connections to peers that are not members anymore !
                ArrayList new_members  = ((View)evt.Arg).getMembers();
                ArrayList left_members = new ArrayList();
                lock (members)
                {
                    foreach (Address a in members)
                    {
                        left_members.Add(a.Copy());
                    }
                    members.Clear();
                    if (new_members != null)
                    {
                        members.AddRange(new_members);
                    }

                    foreach (Address a in members)
                    {
                        if (left_members.Contains(a))
                        {
                            left_members.Remove(a);
                        }
                    }

                    foreach (Address oldMbr in left_members)
                    {
                        entry = (Entry)connections[oldMbr];
                        entry.reset();
                        connections.Remove(oldMbr);
                    }
                }
                break;
            }              // switch
            passDown(evt); // Pass on to the layer below us
        }