本文整理汇总了Java中org.jgroups.Message.getSrc方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getSrc方法的具体用法?Java Message.getSrc怎么用?Java Message.getSrc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.Message
的用法示例。
在下文中一共展示了Message.getSrc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: handleUpEvent
import org.jgroups.Message; //导入方法依赖的package包/类
protected void handleUpEvent(final Message msg, FcHeader hdr) {
switch(hdr.type) {
case FcHeader.REPLENISH:
num_credit_responses_received++;
handleCredit(msg.getSrc(), (Long)msg.getObject());
break;
case FcHeader.CREDIT_REQUEST:
num_credit_requests_received++;
Address sender=msg.getSrc();
Long requested_credits=(Long)msg.getObject();
if(requested_credits != null)
handleCreditRequest(received, sender,requested_credits);
break;
default:
log.error("header type " + hdr.type + " not known");
break;
}
}
示例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));
}
示例4: handleUpEvent
import org.jgroups.Message; //导入方法依赖的package包/类
protected void handleUpEvent(FcHeader hdr, Message msg) {
switch(hdr.type) {
case FcHeader.REPLENISH:
num_credit_responses_received++;
handleCredit(msg.getSrc(), (Number)msg.getObject());
break;
case FcHeader.CREDIT_REQUEST:
num_credit_requests_received++;
Address sender=msg.getSrc();
Long sent_credits=(Long)msg.getObject();
if(sent_credits != null)
handleCreditRequest(received, sender,sent_credits);
break;
default:
log.error("header type " + hdr.type + " not known");
break;
}
}
示例5: receive
import org.jgroups.Message; //导入方法依赖的package包/类
public void receive(long id, Message msg) {
Address sender=msg.getSrc();
if(sender == null) {
if(log.isErrorEnabled())
log.error(local_addr + ": sender is null, cannot deliver message " + "::" + id);
return;
}
if(!canDeliver(sender, id)) {
if(log.isWarnEnabled())
log.warn(local_addr + ": dropped duplicate message " + sender + "::" + id);
return;
}
if(log.isTraceEnabled())
log.trace(local_addr + ": delivering " + sender + "::" + id);
up_prot.up(new Event(Event.MSG, msg));
}
示例6: receive
import org.jgroups.Message; //导入方法依赖的package包/类
@Override
public void receive(Message msg) {
Address srcAddress = msg.getSrc();
Object object = msg.getObject();
LOG.debug("receiving from " + srcAddress + " message " + object);
LOG.debug("message object type: " + object.getClass().getName());
if (this.expectedMessage.equals(object)) {
this.expectedMessageReceived = true;
}
}
示例7: up
import org.jgroups.Message; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Object up(Event evt) {
switch(evt.getType()) {
case Event.MSG:
Message msg=(Message)evt.getArg();
if(msg.isFlagSet(Message.Flag.NO_FC))
break;
Address dest=msg.getDest();
boolean multicast=dest == null;
boolean handle_multicasts=handleMulticastMessage();
FcHeader hdr=(FcHeader)msg.getHeader(this.id);
boolean process=(handle_multicasts && multicast) || (!handle_multicasts && !multicast) || hdr != null;
if(!process)
break;
if(hdr != null) {
handleUpEvent(msg, hdr);
return null; // don't pass message up
}
Address sender=msg.getSrc();
long new_credits=adjustCredit(received, sender, msg.getLength());
try {
return up_prot.up(evt);
}
finally {
if(new_credits > 0)
sendCredit(sender, new_credits);
}
case Event.VIEW_CHANGE:
handleViewChange(((View)evt.getArg()).getMembers());
break;
}
return up_prot.up(evt);
}
示例8: up
import org.jgroups.Message; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Object up(Event evt) {
switch(evt.getType()) {
case Event.MSG:
// JGRP-465. We only deal with msgs to avoid having to use a concurrent collection; ignore views,
// suspicions, etc which can come up on unusual threads.
Message msg=(Message)evt.getArg();
if(msg.isFlagSet(Message.Flag.NO_FC))
break;
FcHeader hdr=(FcHeader)msg.getHeader(this.id);
if(hdr != null) {
handleUpEvent(hdr, msg);
return null; // don't pass message up
}
Address sender=msg.getSrc();
long new_credits=adjustCredit(received, sender, msg.getLength());
try {
return up_prot.up(evt);
}
finally {
if(new_credits > 0) {
if(log.isTraceEnabled()) log.trace("sending " + new_credits + " credits to " + sender);
sendCredit(sender, new_credits);
}
}
case Event.VIEW_CHANGE:
handleViewChange(((View)evt.getArg()).getMembers());
break;
}
return up_prot.up(evt);
}
示例9: 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();
}
示例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);
}
}
示例11: 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;
}
}
示例12: 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);
}
}
示例13: sendResponses
import org.jgroups.Message; //导入方法依赖的package包/类
protected void sendResponses() {
if(responses != null) {
Object obj;
for(int i=0; i < responses.length; i++) {
if(delay > 0)
Util.sleep(delay);
obj=responses[i];
if(obj == null) {
System.err.println("object was null");
continue;
}
if(obj instanceof Message) {
Message msg=(Message)obj;
Address sender=msg.getSrc();
Object retval=null;
try {
retval=Util.objectFromByteBuffer(msg.getBuffer());
}
catch(Exception e) {
e.printStackTrace();
}
request.receiveResponse(retval, sender, false);
}
else if(obj instanceof View)
request.viewChange((View)obj);
}
}
}
示例14: receive
import org.jgroups.Message; //导入方法依赖的package包/类
public void receive(Message msg) {
String line=msg.getSrc() + ": " + msg.getObject();
System.out.println(line);
synchronized(state) {
state.add(line);
}
}
示例15: sendMcastDiscoveryRequest
import org.jgroups.Message; //导入方法依赖的package包/类
@Override
protected void sendMcastDiscoveryRequest(Message msg) {
List<InetSocketAddress> nodes = readAll();
if (nodes == null) {
return;
}
if (msg.getSrc() == null) {
setSrc(msg);
}
for (InetSocketAddress node : nodes) {
// forward the request to each node
timer.execute(new SendDiscoveryRequest(node, msg));
}
}