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


Java Message.putHeader方法代码示例

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


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

示例1: handleMessage

import org.jgroups.Message; //导入方法依赖的package包/类
private void handleMessage(Message msg) {
  if (collectMessages) {
    collectedMessages.add(msg);
  }
  Object o = msg.getHeader(nakackHeaderId);
  if (o != null) {
    mcastSentDataMessages++;
  } else {
    o = msg.getHeader(unicastHeaderId);
    if (o != null) {
      UNICAST3.Header hdr = (UNICAST3.Header) o;
      switch (hdr.type()) {
        case UNICAST3.Header.DATA:
          unicastSentDataMessages++;
          Message response = new Message(uuid, msg.getDest(), null);
          response.putHeader(unicastHeaderId, UNICAST3.Header.createAckHeader(hdr.seqno(),
              hdr.connId(), System.currentTimeMillis()));
          up_prot.up(new Event(Event.MSG, response));
          break;
      }
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:24,代码来源:InterceptUDP.java

示例2: down

import org.jgroups.Message; //导入方法依赖的package包/类
public Object down(Event evt) {
    switch(evt.getType()) {
        case Event.MSG:
            Message msg=(Message)evt.getArg();
            FORK.ForkHeader hdr=(FORK.ForkHeader)msg.getHeader(FORK.ID);
            if(hdr == null)
                msg.putHeader(FORK.ID, hdr=new FORK.ForkHeader(fork_stack_id, null));
            else
                hdr.setForkStackId(fork_stack_id);
            break;
        case Event.SET_LOCAL_ADDRESS:
        case Event.VIEW_CHANGE:
        case Event.CONNECT:
        case Event.CONNECT_USE_FLUSH:
        case Event.CONNECT_WITH_STATE_TRANSFER:
        case Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH:
        case Event.DISCONNECT:
            return null; // don't propagate further down, this is only important for the main stack
    }
    return down_prot.down(evt);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:22,代码来源:ForkProtocol.java

示例3: sendXmitRsp

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * Sends a message msg to the requester. We have to wrap the original message into a retransmit message, as we need
 * to preserve the original message's properties, such as src, headers etc.
 * @param dest
 * @param msg
 */
private void sendXmitRsp(Address dest, Message msg) {
    if(msg == null) {
        if(log.isErrorEnabled())
            log.error("message is null, cannot send retransmission");
        return;
    }

    if(stats)
        xmit_rsps_sent.incrementAndGet();

    if(msg.getSrc() == null)
        msg.setSrc(local_addr);

    if(use_mcast_xmit) { // we simply send the original multicast message
        down_prot.down(new Event(Event.MSG, msg));
        return;
    }

    Message xmit_msg=msg.copy(true, true).dest(dest).setFlag(Message.Flag.INTERNAL); // copy payload and headers
    NakAckHeader hdr=(NakAckHeader)xmit_msg.getHeader(id);
    NakAckHeader newhdr=hdr.copy();    // create a copy of the header: https://issues.jboss.org/browse/JGRP-1502
    newhdr.type=NakAckHeader.XMIT_RSP; // change the type in the copy from MSG --> XMIT_RSP
    xmit_msg.putHeader(id, newhdr);
    down_prot.down(new Event(Event.MSG, xmit_msg));
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:32,代码来源:NAKACK.java

示例4: handleXmitRsp

import org.jgroups.Message; //导入方法依赖的package包/类
private void handleXmitRsp(Message msg, NakAckHeader hdr) {
    if(msg == null)
        return;

    try {
        if(stats)
            xmit_rsps_received.incrementAndGet();

        msg.setDest(null);
        NakAckHeader newhdr=hdr.copy();
        newhdr.type=NakAckHeader.MSG; // change the type back from XMIT_RSP --> MSG
        msg.putHeader(id, newhdr);
        up(new Event(Event.MSG, msg));
        if(rebroadcasting)
            checkForRebroadcasts();
    }
    catch(Exception ex) {
        if(log.isErrorEnabled()) {
            log.error("failed reading retransmitted message", ex);
        }
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:23,代码来源:NAKACK.java

示例5: addHeader

import org.jgroups.Message; //导入方法依赖的package包/类
public Message addHeader(Message msg, byte[] payload) throws SaslException {
    byte[] response;
    if (payload == null) {
        if (client.hasInitialResponse()) {
            response = evaluateChallenge(EMPTY_CHALLENGE);
        } else {
            response = EMPTY_CHALLENGE;
        }
    } else {
        response = evaluateChallenge(payload);
    }
    if (response != null) {
        return msg.putHeader(SASL.SASL_ID, new SaslHeader(Type.RESPONSE, response));
    } else {
        return null;
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:18,代码来源:SaslClientContext.java

示例6: createMessages

import org.jgroups.Message; //导入方法依赖的package包/类
protected List<Message> createMessages() {
    List<Message> retval=new ArrayList<>(10);

    for(long seqno=1; seqno <= 5; seqno++)
        retval.add(new Message(b).putHeader(UNICAST2_ID, UNICAST2.Unicast2Header.createDataHeader(seqno, (short)22, false)));

    retval.add(new Message(b).putHeader(PING_ID, new PingHeader(PingHeader.GET_MBRS_RSP).clusterName("demo-cluster")));
    retval.add(new Message(b).putHeader(FD_ID, new FD.FdHeader(org.jgroups.protocols.FD.FdHeader.HEARTBEAT)));
    retval.add(new Message(b).putHeader(MERGE_ID, MERGE3.MergeHeader.createViewResponse()));

    for(long seqno=6; seqno <= 10; seqno++)
        retval.add(new Message(b).putHeader(UNICAST2_ID, UNICAST2.Unicast2Header.createDataHeader(seqno, (short)22, false)));

    for(Message msg: retval)
        msg.putHeader(UDP_ID, new TpHeader("demo-cluster"));

    return retval;
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:19,代码来源:MessageBatchTest.java

示例7: sendMergeRejectedResponse

import org.jgroups.Message; //导入方法依赖的package包/类
protected void sendMergeRejectedResponse(Address sender, MergeId merge_id) {
    Message msg=new Message(sender).setFlag(Message.Flag.OOB);
    GMS.GmsHeader hdr=new GMS.GmsHeader(GMS.GmsHeader.MERGE_RSP);
    hdr.merge_rejected=true;
    hdr.merge_id=merge_id;
    msg.putHeader(gms.getId(), hdr);
    log.debug("%s: merge response=%s", gms.local_addr, hdr);
    gms.getDownProtocol().down(new Event(Event.MSG, msg));
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:10,代码来源:GmsImpl.java

示例8: sendJoinMessage

import org.jgroups.Message; //导入方法依赖的package包/类
void sendJoinMessage(Address coord, Address mbr,boolean joinWithTransfer, boolean useFlushIfPresent) {
    Message msg=new Message(coord).setFlag(Message.Flag.OOB, Message.Flag.INTERNAL);
    GMS.GmsHeader hdr=joinWithTransfer? new GMS.GmsHeader(GMS.GmsHeader.JOIN_REQ_WITH_STATE_TRANSFER, mbr,useFlushIfPresent)
      : new GMS.GmsHeader(GMS.GmsHeader.JOIN_REQ, mbr,useFlushIfPresent);
    msg.putHeader(gms.getId(), hdr);
    gms.getDownProtocol().down(new Event(Event.MSG, msg));
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:8,代码来源:ClientGmsImpl.java

示例9: retransmit

import org.jgroups.Message; //导入方法依赖的package包/类
protected void retransmit(long first_seqno, long last_seqno, final Address sender, boolean multicast_xmit_request) {
    Address dest=sender; // to whom do we send the XMIT request ?

    if(multicast_xmit_request || this.use_mcast_xmit_req) {
        dest=null;
    }
    else {
        if(xmit_from_random_member && !local_addr.equals(sender)) {
            Address random_member=(Address)Util.pickRandomElement(members);
            if(random_member != null && !local_addr.equals(random_member)) {
                dest=random_member;
                if(log.isTraceEnabled())
                    log.trace("picked random member " + dest + " to send XMIT request to");
            }
        }
    }

    NakAckHeader hdr=NakAckHeader.createXmitRequestHeader(first_seqno, last_seqno, sender);
    Message retransmit_msg=new Message(dest).setFlag(Message.Flag.OOB, Message.Flag.INTERNAL);
    if(log.isTraceEnabled())
        log.trace(local_addr + ": sending XMIT_REQ ([" + first_seqno + ", " + last_seqno + "]) to " + dest);
    retransmit_msg.putHeader(this.id, hdr);

    down_prot.down(new Event(Event.MSG, retransmit_msg));
    if(stats)
        xmit_reqs_sent.addAndGet(last_seqno - first_seqno +1);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:28,代码来源:NAKACK.java

示例10: fragment

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * Send all fragments as separate messages (with same ID !).
 * Example:
 * <pre>
 * Given the generated ID is 2344, number of fragments=3, message {dst,src,buf}
 * would be fragmented into:
 * <p/>
 * [2344,3,0]{dst,src,buf1},
 * [2344,3,1]{dst,src,buf2} and
 * [2344,3,2]{dst,src,buf3}
 * </pre>
 */
private void fragment(Message msg, long size) {
    Address            dest=msg.getDest(), src=msg.getSrc();
    long               frag_id=curr_id.getAndIncrement(); // used as seqnos
    int                num_frags;

    try {
        // write message into a byte buffer and fragment it
        ByteArrayDataOutputStream dos=new ByteArrayDataOutputStream((int)(size + 50));
        msg.writeTo(dos);
        byte[] buffer=dos.buffer();
        byte[][] fragments=Util.fragmentBuffer(buffer, frag_size, dos.position());
        num_frags=fragments.length;
        num_sent_frags+=num_frags;

        if(log.isTraceEnabled()) {
            StringBuilder sb=new StringBuilder();
            sb.append("fragmenting packet to ").append(dest != null ? dest.toString() : "<all members>");
            sb.append(" (size=").append(buffer.length).append(") into ").append(num_frags);
            sb.append(" fragment(s) [frag_size=").append(frag_size).append(']');
            log.trace(sb.toString());
        }

        for(int i=0; i < num_frags; i++) {
            Message frag_msg=new Message(dest, src, fragments[i]);
            FragHeader hdr=new FragHeader(frag_id, i, num_frags);
            frag_msg.putHeader(this.id, hdr);
            Event evt=new Event(Event.MSG, frag_msg);
            down_prot.down(evt);
        }
    }
    catch(Exception e) {
        log.error("exception occurred trying to fragment message", e);
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:47,代码来源:FRAG.java

示例11: fragment

import org.jgroups.Message; //导入方法依赖的package包/类
/** Send all fragments as separate messages (with same ID !).
 Example:
 <pre>
 Given the generated ID is 2344, number of fragments=3, message {dst,src,buf}
 would be fragmented into:

 [2344,3,0]{dst,src,buf1},
 [2344,3,1]{dst,src,buf2} and
 [2344,3,2]{dst,src,buf3}
 </pre>
 */
protected void fragment(Message msg) {
    try {
        byte[] buffer=msg.getRawBuffer();
        final List<Range> fragments=Util.computeFragOffsets(msg.getOffset(), msg.getLength(), frag_size);
        int num_frags=fragments.size();
        num_frags_sent.addAndGet(num_frags);

        if(log.isTraceEnabled()) {
            Address dest=msg.getDest();
            log.trace("%s: fragmenting message to %s (size=%d) into %d fragment(s) [frag_size=%d]",
                      local_addr, dest != null ? dest : "<all>", msg.getLength(), num_frags, frag_size);
        }

        long frag_id=getNextId(); // used as a seqno
        for(int i=0; i < num_frags; i++) {
            Range r=fragments.get(i);
            // don't copy the buffer, only src, dest and headers. Only copy the headers one time !
            Message frag_msg=msg.copy(false, i == 0);
            frag_msg.setBuffer(buffer, (int)r.low, (int)r.high);
            FragHeader hdr=new FragHeader(frag_id, i, num_frags);
            frag_msg.putHeader(this.id, hdr);
            down_prot.down(new Event(Event.MSG, frag_msg));
        }
    }
    catch(Exception e) {
        log.error("%s: fragmentation failure: %s", local_addr, e);
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:40,代码来源:FRAG2.java

示例12: sendMergeRejectionMessage

import org.jgroups.Message; //导入方法依赖的package包/类
protected void sendMergeRejectionMessage(Address dest) {
    Message msg = new Message(dest).setFlag(Message.Flag.OOB);
    GmsHeader hdr = new GmsHeader(GmsHeader.MERGE_RSP);
    hdr.setMergeRejected(true);
    msg.putHeader(GMS_ID, hdr);
    if (log.isDebugEnabled())
        log.debug("merge response=" + hdr);
    down_prot.down(new Event(Event.MSG, msg));
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:10,代码来源:SASL.java

示例13: nextMessage

import org.jgroups.Message; //导入方法依赖的package包/类
@Override
public Message nextMessage(Address address, SaslHeader header) throws SaslException {
    Message message = new Message(address).setFlag(Message.Flag.OOB);
    byte[] challenge = server.evaluateResponse(header.getPayload());
    if (server.isComplete()) {
        latch.countDown();
    }
    if (challenge != null) {
        return message.putHeader(SASL.SASL_ID, new SaslHeader(Type.CHALLENGE, challenge));
    } else {
        return null;
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:14,代码来源:SaslServerContext.java

示例14: sendUnicast

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * Sends a unicast message up UNICAST2
 */
public void sendUnicast(JChannel ch) throws Exception {
    final Message msg=new Message(ch.getAddress(), ch.getAddress(), "hello-1");

    // Add a UNICAST2 header
    final UNICAST3 unicast=(UNICAST3)ch.getProtocolStack().findProtocol(UNICAST3.class);
    UNICAST3.Header hdr=UNICAST3.Header.createDataHeader(1, (short)1, true);
    msg.putHeader(unicast.getId(), hdr);

    new Thread() {
        public void run() {
            unicast.down(new Event(Event.MSG, msg));
        }
    }.start();
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:18,代码来源:MessageBeforeConnectedTestHelper.java

示例15: addHeaders

import org.jgroups.Message; //导入方法依赖的package包/类
protected static void addHeaders(Message msg) {
    TpHeader tp_hdr=new TpHeader("DemoChannel2");
    msg.putHeader(UDP_ID, tp_hdr);
    PingHeader ping_hdr=new PingHeader(PingHeader.GET_MBRS_REQ).clusterName("demo-cluster");
    msg.putHeader(PING_ID, ping_hdr);
    NakAckHeader nak_hdr=NakAckHeader.createXmitRequestHeader(100, 104, null);
    msg.putHeader(NAKACK_ID, nak_hdr);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:9,代码来源:MessageTest.java


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