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


Java Message.setSrc方法代码示例

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


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

示例1: sendMcastDiscoveryRequest

import org.jgroups.Message; //导入方法依赖的package包/类
@Override
protected void sendMcastDiscoveryRequest(Message msg) {
    try {
        if(msg.getSrc() == null)
            msg.setSrc(local_addr);
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(128);
        msg.writeTo(out);
        for(int i=bind_port; i <= bind_port+port_range; i++) {
            DatagramPacket packet=new DatagramPacket(out.buffer(), 0, out.position(), dest_addr, i);
            sock.send(packet);
        }
    }
    catch(Exception ex) {
        log.error("failed sending discovery request", ex);
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:17,代码来源:BPING.java

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

示例3: up

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * If event is a message, if it is fragmented, re-assemble fragments into big message and pass up the stack.
 */
public Object up(Event evt) {
    switch(evt.getType()) {

        case Event.MSG:
            Message msg=(Message)evt.getArg();
            FragHeader hdr=(FragHeader)msg.getHeader(this.id);
            if(hdr != null) { // needs to be defragmented
                Message assembled_msg=unfragment(msg, hdr);
                if(assembled_msg != null) {
                    if(log.isTraceEnabled()) log.trace("%s: assembled_msg is %s", local_addr, assembled_msg);
                    assembled_msg.setSrc(msg.getSrc()); // needed ? YES, because fragments have a null src !!
                    up_prot.up(new Event(Event.MSG, assembled_msg));
                }
                return null;
            }
            break;

        case Event.VIEW_CHANGE:
            handleViewChange((View)evt.getArg());
            break;
    }

    return up_prot.up(evt); // Pass up to the layer above us by default
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:28,代码来源:FRAG2.java

示例4: createJGMessage

import org.jgroups.Message; //导入方法依赖的package包/类
private Message createJGMessage(byte[] msgBytes, Address src, Address dest, short version) {
  Message msg = new Message();
  msg.setDest(dest);
  msg.setSrc(src);
  msg.setObject(msgBytes);
  msg.setFlag(Message.Flag.NO_RELIABILITY);
  msg.setFlag(Message.Flag.NO_FC);
  msg.setFlag(Message.Flag.DONT_BUNDLE);
  msg.setFlag(Message.Flag.OOB);
  return msg;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:12,代码来源:GMSPingPonger.java

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

示例6: unfragment

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * 1. Get all the fragment buffers
 * 2. When all are received -> Assemble them into one big buffer
 * 3. Read headers and byte buffer from big buffer
 * 4. Set headers and buffer in msg
 * 5. Pass msg up the stack
 */
private Message unfragment(Message msg, FragHeader hdr) {
    Address            sender=msg.getSrc();
    FragmentationTable frag_table=fragment_list.get(sender);
    if(frag_table == null) {
        frag_table=new FragmentationTable(sender);
        try {
            fragment_list.add(sender, frag_table);
        }
        catch(IllegalArgumentException x) { // the entry has already been added, probably in parallel from another thread
            frag_table=fragment_list.get(sender);
        }
    }
    num_received_frags++;
    byte[] buf=frag_table.add(hdr.id, hdr.frag_id, hdr.num_frags, msg.getBuffer());
    if(buf == null)
        return null;

    try {
        DataInput in=new ByteArrayDataInputStream(buf);
        Message assembled_msg=new Message(false);
        assembled_msg.readFrom(in);
        assembled_msg.setSrc(sender); // needed ? YES, because fragments have a null src !!
        if(log.isTraceEnabled()) log.trace("assembled_msg is " + assembled_msg);
        num_received_msgs++;
        return assembled_msg;
    }
    catch(Exception e) {
        log.error("failed unfragmenting a message", e);
        return null;
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:39,代码来源:FRAG.java

示例7: sendMcastDiscoveryRequest

import org.jgroups.Message; //导入方法依赖的package包/类
@Override
protected void sendMcastDiscoveryRequest(Message msg) {
    try {
        if(msg.getSrc() == null)
            msg.setSrc(local_addr);
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(128);
        msg.writeTo(out);
        Buffer buf=out.getBuffer();
        DatagramPacket packet=new DatagramPacket(buf.getBuf(), buf.getOffset(), buf.getLength(), mcast_addr, mcast_port);
        if(mcast_send_sockets != null) {
            MulticastSocket s;
            for(int i=0; i < mcast_send_sockets.length; i++) {
                s=mcast_send_sockets[i];
                try {
                    s.send(packet);
                }
                catch(Exception e) {
                    log.error("failed sending packet on socket " + s);
                }
            }
        }
        else { // DEFAULT path
            if(mcast_sock != null)
                mcast_sock.send(packet);
        }
    }
    catch(Exception ex) {
        log.error("failed sending discovery request", ex);
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:31,代码来源:MPING.java

示例8: send

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * Adds the message to the sent_msgs table and then passes it down the stack. Change Bela Ban May 26 2002: we don't
 * store a copy of the message, but a reference ! This saves us a lot of memory. However, this also means that a
 * message should not be changed after storing it in the sent-table ! See protocols/DESIGN for details.
 * Made seqno increment and adding to sent_msgs atomic, e.g. seqno won't get incremented if adding to
 * sent_msgs fails e.g. due to an OOM (see http://jira.jboss.com/jira/browse/JGRP-179). bela Jan 13 2006
 */
protected void send(Event evt, Message msg) {
    if(msg == null)
        throw new NullPointerException("msg is null; event is " + evt);

    if(!running) {
        if(log.isTraceEnabled())
            log.trace(local_addr + ": discarded message as we're not in the 'running' state, message: " + msg);
        return;
    }

    long msg_id;
    NakReceiverWindow win=xmit_table.get(local_addr);
    if(win == null) {  // discard message if there is no entry for local_addr
        if(log.isWarnEnabled() && log_discard_msgs)
            log.warn(local_addr + ": discarded message to " + local_addr + " with no window, my view is " + view);
        return;
    }

    if(msg.getSrc() == null)
        msg.setSrc(local_addr); // this needs to be done so we can check whether the message sender is the local_addr

    msg_id=seqno.incrementAndGet();
    long sleep=10;
    while(running) {
        try {
            msg.putHeader(this.id, NakAckHeader.createMessageHeader(msg_id));
            win.add(msg_id, msg);
            break;
        }
        catch(Throwable t) {
            if(running)
                Util.sleep(sleep);
            sleep=Math.min(5000, sleep*2);
        }
    }

     // moved down_prot.down() out of synchronized clause (bela Sept 7 2006) http://jira.jboss.com/jira/browse/JGRP-300
    if(log.isTraceEnabled())
        log.trace("sending " + local_addr + "#" + msg_id);
    down_prot.down(evt); // if this fails, since msg is in sent_msgs, it can be retransmitted
    num_messages_sent++;
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:50,代码来源:NAKACK.java


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