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


Java Message.copy方法代码示例

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


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

示例1: testCopyWithOffset

import org.jgroups.Message; //导入方法依赖的package包/类
public static void testCopyWithOffset() {
    byte[] buf={'b', 'e', 'l', 'a', 'b', 'a', 'n'};
    Message m1=new Message(null, null, buf, 0, 4);
    Message m2=new Message(null, null, buf, 4, 3);

    Message m3, m4;
    m3=m1.copy();
    m4=m2.copy();

    Assert.assertEquals(0, m3.getOffset());
    Assert.assertEquals(4, m3.getLength());
    Assert.assertEquals(4, m3.getBuffer().length);

    Assert.assertEquals(4, m4.getOffset());
    Assert.assertEquals(3, m4.getLength());
    Assert.assertEquals(3, m4.getBuffer().length);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:18,代码来源:MessageTest.java

示例2: MessageInfo

import org.jgroups.Message; //导入方法依赖的package包/类
public MessageInfo(MessageID messageID, Message message, long sequenceNumber) {
    if (messageID == null) {
        throw new NullPointerException("Message ID can't be null");
    }
    this.messageID = messageID;
    this.message = message.copy(true, true);
    this.sequenceNumber = sequenceNumber;
    this.readyToDeliver = false;
    this.message.setSrc(messageID.getAddress());
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:11,代码来源:DeliveryManagerImpl.java

示例3: loopback

import org.jgroups.Message; //导入方法依赖的package包/类
private void loopback(Message msg) {
    final Message rsp=msg.copy(true);
    if(rsp.getSrc() == null)
        rsp.setSrc(localAddress());

    // pretty inefficient: creates one thread per message, okay for testing only
    Thread thread=new Thread(new Runnable() {
        public void run() {
            up_prot.up(new Event(Event.MSG, rsp));
        }
    });
    thread.start();
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:14,代码来源:DISCARD.java

示例4: 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

示例5: flushMessagesInForwardTable

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * Sends all messages currently in forward_table to the new target (changing the dest field).
 * This needs to be done, so the underlying reliable unicast protocol (e.g. UNICAST) adds these messages
 * to its retransmission mechanism<br/>
 * Note that we need to resend the messages in order of their seqnos ! We also need to prevent other message
 * from being inserted until we're done, that's why there's synchronization.<br/>
 * Access to the forward_table doesn't need to be synchronized as there won't be any insertions during flushing
 * (all down-threads are blocked)
 */
protected void flushMessagesInForwardTable(Address target) {
    // for forwarded messages, we need to receive the forwarded message from the coordinator, to prevent this case:
    // - V1={A,B,C}
    // - A crashes
    // - C installs V2={B,C}
    // - C forwards messages 3 and 4 to B (the new coord)
    // - B drops 3 because its view is still V1
    // - B installs V2
    // - B receives message 4 and broadcasts it
    // ==> C's message 4 is delivered *before* message 3 !
    // ==> By resending 3 until it is received, then resending 4 until it is received, we make sure this won't happen
    // (see https://issues.jboss.org/browse/JGRP-1449)

    // Forward the first entry and wait for the ack
    Map.Entry<Long,Message> first=forward_table.firstEntry();
    if(first == null)
        return;
    Long key=first.getKey();
    Message val=first.getValue();
    Message forward_msg;

    while(flushing && running && !forward_table.isEmpty()) {
        forward_msg=val.copy();
        forward_msg.setDest(target);
        forward_msg.setFlag(Message.Flag.DONT_BUNDLE);
        if(log.isTraceEnabled())
            log.trace(local_addr + ": flushing (forwarding) " + "::" + key + " to target " + target);
        ack_promise.reset();
        down_prot.down(new Event(Event.MSG, forward_msg));
        Long ack=ack_promise.getResult(500);
        if((ack != null && ack.equals(key)) || !forward_table.containsKey(key))
            break;
    }

    for(Map.Entry<Long,Message> entry: forward_table.entrySet()) {
        key=entry.getKey();
        val=entry.getValue();
        if(flushing && running) {
            forward_msg=val.copy();
            forward_msg.setDest(target);
            forward_msg.setFlag(Message.Flag.DONT_BUNDLE);
            if(log.isTraceEnabled())
                log.trace(local_addr + ": flushing (forwarding) " + "::" + key + " to target " + target);
            down_prot.down(new Event(Event.MSG, forward_msg));
        }
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:57,代码来源:ForwardQueue.java


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