当前位置: 首页>>代码示例>>C#>>正文


C# Message.putHeader方法代码示例

本文整理汇总了C#中Message.putHeader方法的典型用法代码示例。如果您正苦于以下问题:C# Message.putHeader方法的具体用法?C# Message.putHeader怎么用?C# Message.putHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Message的用法示例。


在下文中一共展示了Message.putHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: up

        /// <summary>
        /// Processes <c>Events</c> travelling up the stack
        /// </summary>
        /// <param name="evt">The Event to be processed</param>
        public override void up(Event evt)
        {
            Address       suspected_mbr;
            Message       msg, rsp;
            Object        obj;
            VerifyHeader  hdr;

            switch(evt.Type)
            {

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

                case Event.SUSPECT:  // it all starts here ...
                    suspected_mbr=(Address)evt.Arg;
                    if(suspected_mbr == null)
                    {
                        if(Trace.trace)
                            Trace.error("VERIFY_SUSPECT.up()", "suspected member is null");
                        return;
                    }
                    suspect(suspected_mbr);
                    return;  // don't pass up; we will decide later (after verification) whether to pass it up

                case Event.MSG:
                    msg=(Message)evt.Arg;
                    obj=msg.getHeader(getName());
                    if(obj == null || !(obj is VerifyHeader))
                        break;
                    hdr=(VerifyHeader)msg.removeHeader(getName());
                switch(hdr.type)
                {
                    case VerifyHeader.ARE_YOU_DEAD:
                        if(hdr.from == null)
                            if(Trace.trace)
                                Trace.error("VERIFY_SUSPECT.up()", "ARE_YOU_DEAD: hdr.from is null");
                        else
                        {
                            for(int i=0; i < num_msgs; i++)
                            {
                                rsp=new Message(hdr.from, null, null);
                                rsp.putHeader(getName(), new VerifyHeader(VerifyHeader.I_AM_NOT_DEAD, local_addr));
                                passDown(new Event(Event.MSG, rsp));
                            }
                        }
                        return;
                    case VerifyHeader.I_AM_NOT_DEAD:
                        if(hdr.from == null)
                        {
                            if(Trace.trace)
                                Trace.error("VERIFY_SUSPECT.up()", "I_AM_NOT_DEAD: hdr.from is null");
                            return;
                        }
                        unsuspect(hdr.from);
                        return;
                }
                    return;
            }
            passUp(evt);
        }
开发者ID:curasystems,项目名称:externals,代码行数:65,代码来源:VERIFY_SUSPECT.cs

示例2: suspect

        /* --------------------------------- Private Methods ----------------------------------- */
        /// <summary>
        /// Sends ARE_YOU_DEAD message to suspected_mbr, wait for return or timeout
        /// </summary>
        /// <param name="mbr">Suspected member</param>
        private void suspect(Address mbr)
        {
            Message msg;
            if(mbr == null) return;

            lock(suspects)
            {
                if(suspects.ContainsKey(mbr))
                    return;
                suspects.Add(mbr, (long)System.Environment.TickCount);
                if(Trace.trace)
                    Trace.info("VERIFY_SUSPECT.suspect()", "verifying that " + mbr + " is dead");
                for(int i=0; i < num_msgs; i++)
                {
                    msg=new Message(mbr, null, null);
                    msg.putHeader(getName(), new VerifyHeader(VerifyHeader.ARE_YOU_DEAD, local_addr));
                    passDown(new Event(Event.MSG, msg));
                }
            }
            if(timer == null)
                startTimer();
        }
开发者ID:curasystems,项目名称:externals,代码行数:27,代码来源:VERIFY_SUSPECT.cs

示例3: down

        /// <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;
            PINGHeader		hdr;
            long			time_to_wait, start_time;

            switch(evt.Type)
            {
                case Event.FIND_INITIAL_MBRS:   // sent by GMS layer, pass up a GET_MBRS_OK event

                    initial_members.Clear();

                    // 1. Mcast GET_MBRS_REQ message
                    if(Trace.trace) Trace.info("PING.down()", "FIND_INITIAL_MBRS");
                    hdr=new PINGHeader(PINGHeader.GET_MBRS_REQ, null);
                    msg=new Message(null, null, null);  // mcast msg
                    msg.putHeader(name, hdr);
                    passDown(new Event(Event.MSG, msg));

                    // 2. Wait 'timeout' ms or until 'num_initial_members' have been retrieved
                    lock(initial_members)
                    {
                        start_time = System.Environment.TickCount;
                        time_to_wait=timeout;

                        while(initial_members.Count < num_initial_members && time_to_wait > 0)
                        {

                            if(Trace.trace)
                                Trace.info("PING.down()", "waiting for initial members: time_to_wait=" + time_to_wait +
                                ", got " + initial_members.Count + " rsps");

                            Monitor.Wait(initial_members, (int)time_to_wait);
                            time_to_wait -= System.Environment.TickCount - start_time;
                        }

                        if(Trace.trace)
                            Trace.info("PING.down()", "No longer waiting for members as Initial Members = " + initial_members.Count.ToString()  + "|" + num_initial_members + "   TimeToWait = " + time_to_wait );
                    }

                    // 3. Send response
                    if(Trace.trace)
                        Trace.info("PING.down()", "initial mbrs are " + initialMembersString());
                    passUp(new Event(Event.FIND_INITIAL_MBRS_OK, initial_members));
                    break;
                //case Event.TMP_VIEW:
                case Event.VIEW_CHANGE:
                    ArrayList tmp;
                    if((tmp=((View)evt.Arg).getMembers()) != null)
                    {
                        lock(members)
                        {
                            members.Clear();
                            for(int i=0; i < tmp.Count; i++)
                                members.Add(tmp[i]);
                        }
                    }
                    passDown(evt);
                    break;

                case Event.BECOME_SERVER: // called after client has joined and is fully working group member
                    passDown(evt);
                    is_server=true;
                    break;

                case Event.CONNECT:
                    group_addr=(String)evt.Arg;
                    passDown(evt);
                    break;
                default:
                    passDown(evt);          // Pass on to the layer below us
                    break;
            }
        }
开发者ID:curasystems,项目名称:externals,代码行数:78,代码来源:PING.cs

示例4: send

 /// <summary>
 /// Sends a message.
 /// </summary>
 /// <param name="identifier">Listener object message will be returned to. If null then the default listener will be used</param>
 /// <param name="msg">Message to be sent</param>
 public void send(Object identifier, Message msg)
 {
     if(msg == null)
     {
         if(Trace.trace)
             Trace.error("PullPushAdapter.send()", "msg is null");
         return;
     }
     if(identifier == null)
         transport.send(msg);
     else
     {
         msg.putHeader(PULL_HEADER, new PullHeader(identifier));
         transport.send(msg);
     }
 }
开发者ID:curasystems,项目名称:externals,代码行数:21,代码来源:PullPushAdapter.cs

示例5: shunInvalidHeartbeatSender

        /// <summary>
        /// Shun member pinging this member if it is not a member of the group.
        /// </summary>
        /// <param name="hb_sender"></param>
        private void shunInvalidHeartbeatSender(Address hb_sender)
        {
            int      num_pings=0;
            Message  shun_msg;

            if(hb_sender != null && members != null && !members.Contains(hb_sender))
            {
                if(invalid_pingers.ContainsKey(hb_sender))
                {
                    num_pings=(int)invalid_pingers[hb_sender];
                    if(num_pings >= max_tries)
                    {
                        if(Trace.trace)
                            Trace.info("FD.shunInvalidHeartbeatSender()", "sender " + hb_sender +
                            " is not member in " + members + " ! Telling it to leave group");
                        shun_msg=new Message(hb_sender, null, null);
                        shun_msg.putHeader(getName(), new FdHeader(FdHeader.NOT_MEMBER));
                        passDown(new Event(Event.MSG, shun_msg));
                        invalid_pingers.Remove(hb_sender);
                    }
                    else
                    {
                        num_pings++;
                        invalid_pingers[hb_sender] = (int)num_pings;
                    }
                }
                else
                {
                    num_pings++;
                    invalid_pingers[hb_sender] = (int)num_pings;
                }
            }
        }
开发者ID:curasystems,项目名称:externals,代码行数:37,代码来源:FD.cs

示例6: up

        /// <summary>
        /// Processes <c>Events</c> travelling up the stack
        /// </summary>
        /// <param name="evt">The Event to be processed</param>
        public override void up(Event evt)
        {
            Message      msg, rsp_msg;
            Object       obj;
            PINGHeader   hdr, rsp_hdr;
            PingRsp      rsp;
            Address      coord;

            switch(evt.Type)
            {
                case Event.MSG:
                    msg=(Message)evt.Arg;
                    obj=msg.getHeader(name);
                    if(obj == null || !(obj is PINGHeader))
                    {
                        passUp(evt);
                        return;
                    }
                    hdr=(PINGHeader)msg.removeHeader(name);

                switch(hdr.type)
                {

                    case PINGHeader.GET_MBRS_REQ:   // return Rsp(local_addr, coord)
                        if(!is_server)
                        {
                            return;
                        }
                        lock(members)
                        {
                            coord=members.Count > 0 ? (Address)members[0] : local_addr;
                        }
                        rsp_msg=new Message(msg.Source, null, null);
                        rsp_hdr=new PINGHeader(PINGHeader.GET_MBRS_RSP, new PingRsp(local_addr, coord));
                        rsp_msg.putHeader(name, rsp_hdr);
                        if(Trace.trace) Trace.info("PING.up()", "received GET_MBRS_REQ from " + msg.Source+ ", returning " + rsp_hdr);
                        passDown(new Event(Event.MSG, rsp_msg));
                        return;

                    case PINGHeader.GET_MBRS_RSP:   // add response to vector and notify waiting thread
                        rsp=(PingRsp)hdr.arg;
                        lock(initial_members)
                        {
                            if(Trace.trace)
                                Trace.info("PING.up()", "received FIND_INITAL_MBRS_RSP, rsp=" + rsp);
                            initial_members.Add(rsp);
                            Monitor.Pulse(initial_members);
                        }
                        return;

                    default:
                        if(Trace.trace)
                            Trace.warn("PING.up()", "got PING header with unknown type (" + hdr.type + ")");
                        return;
                }

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

                default:
                    passUp(evt);            // Pass up to the layer above us
                    break;
            }
        }
开发者ID:curasystems,项目名称:externals,代码行数:70,代码来源:PING.cs

示例7: sendXmitRsp

 /// <summary>
 /// Sends a XMIT_RSP message
 /// </summary>
 /// <param name="msg">Message containing missing messages</param>
 /// <param name="first_seqno">First sequence number of missing messages</param>
 /// <param name="last_seqno">Last sequence number of missing messages</param>
 void sendXmitRsp(Message msg, long first_seqno, long last_seqno)
 {
     msg.putHeader(getName(), new NakAckHeader(NakAckHeader.XMIT_RSP, first_seqno, last_seqno));
     passDown(new Event(Event.MSG, msg));
 }
开发者ID:curasystems,项目名称:externals,代码行数:11,代码来源:NAKACK.cs

示例8: handleJoinRequest

        /// <summary>
        /// Deals with incoming join requests. If we are a coordinator then a response will be sent.
        /// </summary>
        /// <param name="mbr"></param>
        void handleJoinRequest(Address mbr)
        {
            JoinRsp   join_rsp;
            Message   m;
            GmsHeader hdr;
            ArrayList    new_mbrs=new ArrayList();

            if(mbr == null)
            {
                if(Trace.trace)
                    Trace.error("GMS.handleJoinRequest()", "mbr is null");
                return;
            }

            if(Trace.trace)
                Trace.info("GMS.handleJoinRequest()", "mbr=" + mbr);

            // 1. Get the new view and digest
            join_rsp=impl.handleJoin(mbr);
            if(join_rsp == null)
                if(Trace.trace)
                    Trace.error("GMS.handleJoinRequest()", impl.getName() + ".handleJoin(" + mbr +
                    ") returned null: will not be able to multicast new view");

            // 2. Send down a local TMP_VIEW event. This is needed by certain layers (e.g. NAKACK) to compute correct digest
            //    in case client's next request reaches us *before* our own view change multicast.
            if(join_rsp != null && join_rsp.getView() != null)
                passDown(new Event(Event.TMP_VIEW, join_rsp.getView()));

            // 3. Return result to client
            m=new Message(mbr, null, null);
            hdr=new GmsHeader(GmsHeader.JOIN_RSP, join_rsp);
            m.putHeader(getName(), hdr);
            passDown(new Event(Event.MSG, m));

            // 4. Bcast the new view
            if(join_rsp != null)
                castViewChange(join_rsp.getView());
        }
开发者ID:curasystems,项目名称:externals,代码行数:43,代码来源:GMS.cs

示例9: handleMessage

        /// <remarks>
        /// Finds the corresponding NakReceiverWindow and adds the message to it (according to seqno). Then removes
        /// as many messages as possible from the NRW and passes them up the stack. Discards messages from non-members.
        /// </remarks>
        /// <summary>
        /// Results in all possible messages from sender being delivered up the stacks
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="hdr"></param>
        void handleMessage(Message msg, NakAckHeader hdr)
        {
            NakReceiverWindow  win=null;
            Message            msg_to_deliver;
            Address            sender;

            if(msg == null || hdr == null)
            {
                if(Trace.trace)
                    Trace.error("NAKACK.handleMessage()", "msg or header is null");
                return;
            }
            sender=msg.Source;
            if(sender == null)
            {
                if(Trace.trace)
                    Trace.error("NAKACK.handleMessage()", "sender of message is null");
                return;
            }
            if(Trace.trace)
                Trace.info("NAKACK.handleMessage()", "[" + local_addr + "] received <" + sender + "#" + hdr.seqno + ">");

            // msg is potentially re-sent later as result of XMIT_REQ reception; that's why hdr is added !
            msg.putHeader(getName(), hdr);

            win=(NakReceiverWindow)received_msgs[sender];
            if(win == null)
            {  // discard message if there is no entry for sender
                if(leaving)
                    return;
                if(Trace.trace)
                    Trace.warn("NAKACK.handleMessage()", "[" + local_addr + "] discarded message from non-member " + sender);
                return;
            }
            win.add(hdr.seqno, msg);  // add in order, then remove and pass up as many msgs as possible
            while((msg_to_deliver=win.remove()) != null)
            {
                msg_to_deliver.removeHeader(getName());
                passUp(new Event(Event.MSG, msg_to_deliver));
            }
        }
开发者ID:curasystems,项目名称:externals,代码行数:50,代码来源:NAKACK.cs

示例10: send

        /// <summary>
        /// Adds the message to the sent_msgs table and then passes it down the stack.
        /// </summary>
        /// <param name="msg">The message to be sent</param>
        void send(Message msg)
        {
            long msg_id = getNextSeqno();
            if(Trace.trace)
                Trace.info("NAKACK.send()", "sending msg #" + msg_id);
            msg.putHeader(name, new NakAckHeader(NakAckHeader.MSG, msg_id));

            sent_msgs.Add((long)msg_id, msg);
            passDown(new Event(Event.MSG, msg));
        }
开发者ID:curasystems,项目名称:externals,代码行数:14,代码来源:NAKACK.cs

示例11: retransmit

        /* ---------------------- Interface Retransmitter.RetransmitCommand ---------------------- */
        /// <summary>
        /// Implementation of Retransmitter.RetransmitCommand, sends XMIT_REQ to originator of message
        /// </summary>
        /// <param name="first_seqno">First sequence number missing</param>
        /// <param name="last_seqno">Last sequence number missing</param>
        /// <param name="sender">Origin of the message</param>
        public void retransmit(long first_seqno, long last_seqno, Address sender)
        {
            lock(this)
            {
                NakAckHeader hdr;
                Message      retransmit_msg = new Message(sender, null, null);

                if(Trace.trace)
                    Trace.info("NAKACK.retransmit()", "sending XMIT_REQ ([" + first_seqno +
                    ", " + last_seqno + "]) to " + sender);

                hdr=new NakAckHeader(NakAckHeader.XMIT_REQ, first_seqno, last_seqno);
                retransmit_msg.putHeader(getName(), hdr);
                passDown(new Event(Event.MSG, retransmit_msg));
            }
        }
开发者ID:curasystems,项目名称:externals,代码行数:23,代码来源:NAKACK.cs

示例12: sendAck

 /// <summary>
 /// Sends an acknowledgement (ACK) to the sender of the message
 /// </summary>
 /// <param name="dst">Sender of the Message</param>
 /// <param name="seqno">Sequence number of received Message</param>
 private void sendAck(Address dst, long seqno)
 {
     Message ack=new Message(dst, null, null);
     ack.putHeader(getName(), new UnicastHeader(UnicastHeader.DATA_ACK, seqno));
     if(Trace.trace)
         Trace.info("UNICAST.sendAck()", "[" + local_addr + "] --> ACK(" + dst + ": #" + seqno + ")");
     passDown(new Event(Event.MSG, ack));
 }
开发者ID:curasystems,项目名称:externals,代码行数:13,代码来源:UNICAST.cs

示例13: run

            /// <summary>
            /// Sends a Heartbeat to the <i>next</i> member in the group
            /// </summary>
            public void run()
            {
                Message   suspect_msg, hb_req;
                FdHeader  hdr;
                long      not_heard_from=0; // time in msecs we haven't heard from ping_dest

                if(fd.ping_dest == null)
                {
                    if(Trace.trace)
                        Trace.error("FD.Monitor.run()", "ping_dest is null");
                    return;
                }

                // 1. send heartbeat request
                hb_req=new Message(fd.ping_dest, null, null);
                hb_req.putHeader(fd.Name, new FdHeader(FdHeader.HEARTBEAT));  // send heartbeat request
                if(Trace.trace)
                    Trace.info("FD.Monitor.run()", "sending are-you-alive msg to " + fd.ping_dest);
                fd.passDown(new Event(Event.MSG, hb_req));

                // 2. If the time of the last heartbeat is > timeout and max_tries heartbeat messages have not been
                //    received, then broadcast a SUSPECT message. Will be handled by coordinator, which may install
                //    a new view
                not_heard_from=System.Environment.TickCount - fd.last_ack;

                if(not_heard_from >= fd.timeout)
                {
                    // no heartbeat ack for more than timeout msecs
                    if(fd.num_tries >= fd.max_tries)
                    {
                        if(Trace.trace)
                            Trace.info("FD.Monitor.run()", "[" + fd.local_addr + "]: received no heartbeat ack from " + fd.ping_dest + ", suspecting it");
                        hdr=new FdHeader(FdHeader.SUSPECT);
                        hdr.suspected_mbr=fd.ping_dest;
                        hdr.from=fd.local_addr;
                        suspect_msg=new Message(null,null,null);                       // mcast SUSPECT to all members
                        suspect_msg.putHeader(fd.Name, hdr);
                        fd.passDown(new Event(Event.MSG, suspect_msg));
                    }
                    else
                    {
                        if(Trace.trace)
                            Trace.info("FD.Monitor.run()", "heartbeat missing from " + fd.ping_dest +
                                " (number=" + fd.num_tries + ")");

                        fd.num_tries++;
                    }
                }
            }
开发者ID:curasystems,项目名称:externals,代码行数:52,代码来源:FD.cs

示例14: sendJoinMessage

        /// <summary>
        /// Sends a join message to the coordinator of the group.
        /// </summary>
        /// <param name="coord">The Address of the Coordinator</param>
        /// <param name="mbr">The local Address (i.e. this member)</param>
        private void sendJoinMessage(Address coord, Address mbr)
        {
            Message			msg;
            GmsHeader		hdr;

            msg=new Message(coord, null, null);
            hdr=new GmsHeader(GmsHeader.JOIN_REQ, mbr);
            msg.putHeader(gms.getName(), hdr);
            gms.passDown(new Event(Event.MSG, msg));
        }
开发者ID:curasystems,项目名称:externals,代码行数:15,代码来源:ClientGmsImpl.cs

示例15: run

            /// <summary>
            /// Sends the stability message to all members.
            /// </summary>
            public void run()
            {
                Message      msg;
                StableHeader hdr;

                if(d != null && !stopped)
                {
                    msg=new Message(null,null,null);
                    hdr=new StableHeader(StableHeader.STABILITY, d);
                    msg.putHeader("STABLE", hdr);
                    stable_prot.passDown(new Event(Event.MSG, msg));
                    d=null;
                }
                stopped=true;
            }
开发者ID:curasystems,项目名称:externals,代码行数:18,代码来源:STABLE.cs


注:本文中的Message.putHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。