/** * Constructs a message given a destination address * @param dest The Address of the receiver. If it is null, then the message is sent to the group. Otherwise, it is * sent to a single member. */ public Message(Address dest) { setDest(dest); headers=createHeaders(Util.DEFAULT_HEADERS); }
protected Message msgFromXmitRsp(Message msg, NakAckHeader2 hdr) { if(msg == null) return null; if(stats) xmit_rsps_received.increment(); msg.setDest(null); NakAckHeader2 newhdr=hdr.copy(); newhdr.type=NakAckHeader2.MSG; // change the type back from XMIT_RSP --> MSG msg.putHeader(id,newhdr); return msg; }
private void send(Collection<Address> destinations, Message msg, boolean sendToMyself) { if (log.isTraceEnabled()) { log.trace("sending anycast total order message %s to %s", msg, destinations); } for (Address address : destinations) { if (!sendToMyself && address.equals(localAddress)) { continue; } Message cpy = msg.copy(); cpy.setDest(address); down_prot.down(cpy); } }
public static List<Message> readMessageList(DataInput in, short transport_id) throws Exception { List<Message> list=new LinkedList<>(); Address dest=Util.readAddress(in); Address src=Util.readAddress(in); // AsciiString cluster_name=Bits.readAsciiString(in); // not used here short length=in.readShort(); byte[] cluster_name=length >= 0? new byte[length] : null; if(cluster_name != null) in.readFully(cluster_name, 0, cluster_name.length); int len=in.readInt(); for(int i=0; i < len; i++) { Message msg=new Message(false); msg.readFrom(in); msg.setDest(dest); if(msg.getSrc() == null) msg.setSrc(src); // Now add a TpHeader back on, was not marshalled. Every message references the *same* TpHeader, saving memory ! msg.putHeader(transport_id, new TpHeader(cluster_name)); list.add(msg); } return list; }
@Override public void deliver(Message message) { message.setDest(localAddress); if (log.isTraceEnabled()) { log.trace("Deliver message %s (%s) in total order", message, message.getHeader(id)); } up_prot.up(message); statsCollector.incrementMessageDeliver(); }
protected void handleXmitRsp(Message msg, NakAckHeader2 hdr) { if(msg == null) return; try { if(stats) xmit_rsps_received.increment(); msg.setDest(null); NakAckHeader2 newhdr=hdr.copy(); newhdr.type=NakAckHeader2.MSG; // change the type back from XMIT_RSP --> MSG msg.putHeader(id, newhdr); handleMessage(msg, newhdr); if(rebroadcasting) checkForRebroadcasts(); } catch(Exception ex) { log.error(Util.getMessage("FailedToDeliverMsg"), local_addr, "retransmitted message", msg, ex); } }
protected static Message deserialize(Message msg) throws Exception { try { Message ret=Util.streamableFromBuffer(Message::new, msg.getRawBuffer(), msg.getOffset(), msg.getLength()); if(ret.getDest() == null) ret.setDest(msg.getDest()); if(ret.getSrc() == null) ret.setSrc(msg.getSrc()); return ret; } catch(Exception e) { throw new Exception(String.format("failed deserialize message from %s", msg.src()), e); } } }
public Object down(Message msg) { if(msg.getDest() != null) return down_prot.down(msg); // only process multicast messages if(next == null) // view hasn'<></> been received yet, use the normal transport return down_prot.down(msg); // we need to copy the message, as we cannot do a msg.setSrc(next): the next retransmission // would use 'next' as destination ! Message copy=msg.copy(true); short hdr_ttl=(short)(loopback? view_size -1 : view_size); DaisyHeader hdr=new DaisyHeader(hdr_ttl); copy.setDest(next); copy.putHeader(getId(), hdr); msgs_sent++; if(loopback) { if(log.isTraceEnabled()) log.trace(new StringBuilder("looping back message ").append(msg)); if(msg.getSrc() == null) msg.setSrc(local_addr); default_pool.execute(() -> up_prot.up(msg)); } return down_prot.down(copy); }
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; }
message.setDest(destinations.iterator().next());
Message msg=new Message(false); msg.readFrom(in); msg.setDest(dest); if(msg.getSrc() == null) msg.setSrc(src);
public Object up(Message msg) { DaisyHeader hdr=msg.getHeader(getId()); if(hdr == null) return up_prot.up(msg); // 1. forward the message to the next in line if ttl > 0 short ttl=hdr.getTTL(); if(log.isTraceEnabled()) log.trace(local_addr + ": received message from " + msg.getSrc() + " with ttl=" + ttl); if(--ttl > 0) { Message copy=msg.copy(true); copy.setDest(next); copy.putHeader(getId(), new DaisyHeader(ttl)); msgs_forwarded++; if(log.isTraceEnabled()) log.trace(local_addr + ": forwarding message to " + next + " with ttl=" + ttl); down_prot.down(copy); } // 2. Pass up msg.setDest(null); return up_prot.up(msg); }
public void up(MessageBatch batch) { for(Message msg: batch) { DaisyHeader hdr=msg.getHeader(getId()); if(hdr != null) { // 1. forward the message to the next in line if ttl > 0 short ttl=hdr.getTTL(); if(log.isTraceEnabled()) log.trace(local_addr + ": received message from " + msg.getSrc() + " with ttl=" + ttl); if(--ttl > 0) { Message copy=msg.copy(true); copy.setDest(next); copy.putHeader(getId(), new DaisyHeader(ttl)); msgs_forwarded++; if(log.isTraceEnabled()) log.trace(local_addr + ": forwarding message to " + next + " with ttl=" + ttl); down_prot.down(copy); } // 2. Pass up msg.setDest(null); } } if(!batch.isEmpty()) up_prot.up(batch); }
public Object down(Event evt) { switch(evt.getType()) { case Event.FORWARD_TO_COORD: Address target=coord; if(target == null) throw new IllegalStateException("coord is null; dropping message"); Message msg=evt.getArg(); long msg_id=getNextId(); ForwardHeader hdr=new ForwardHeader(ForwardHeader.MSG, msg_id); msg.putHeader(id, hdr); msg.setDest(target); if(log.isTraceEnabled()) log.trace(local_addr + ": forwarding message with id=" + msg_id + " to current coordinator " + target); fwd_queue.send(msg_id, msg); return null; // FORWARD_TO_COORD is not passed down any further case Event.VIEW_CHANGE: handleViewChange(evt.getArg()); break; case Event.SET_LOCAL_ADDRESS: local_addr=evt.getArg(); fwd_queue.setLocalAddr(local_addr); break; } return down_prot.down(evt); }
jmsg.setFlag(Message.Flag.NO_RELIABILITY); tmp.setDest(to); tmp.setSrc(this.jgAddress); logger.trace("Unicasting to {}", to);
msg.setDest(null); msg.setSrc(src); setMessageFlags(gfmsg, msg);
Message msg=msg_queue[i]; if(msg != null && (dest == msg.getDest() || (Objects.equals(dest, msg.getDest())))) { msg.setDest(dest); // avoid further equals() calls numMsgs++;
/** Public constructor * @param dest Address of receiver. If it is <em>null</em> then the message sent to the group. * Otherwise, it contains a single destination and is sent to that member.<p> */ public Message(Address dest) { setDest(dest); headers=createHeaders(7); }
private void broadcast(Message msg) { SequencerHeader hdr=(SequencerHeader)msg.getHeader(name); hdr.type=SequencerHeader.BCAST; // we change the type of header, but leave the tag intact msg.setDest(null); // mcast msg.setSrc(local_addr); // the coord is sending it - this will be replaced with sender in deliver() down_prot.down(new Event(Event.MSG, msg)); bcast_msgs++; }