public void up(MessageBatch batch) { for (Message msg : batch) { DaisyHeader hdr = (DaisyHeader) 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(new Event(Event.MSG, copy)); } // 2. Pass up msg.setDest(null); } } if (!batch.isEmpty()) up_prot.up(batch); }
public Object up(Event evt) { switch (evt.getType()) { case Event.MSG: Message msg = (Message) evt.getArg(); DaisyHeader hdr = (DaisyHeader) msg.getHeader(getId()); if (hdr == null) break; // 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(new Event(Event.MSG, copy)); } // 2. Pass up msg.setDest(null); break; } return up_prot.up(evt); }
private void sendRequest(final Collection<Address> targetMembers, long requestId) throws Exception { try { if (corr != null) { corr.sendRequest( requestId, targetMembers, request_msg, options.getMode() == GET_NONE ? null : this, options); } else { if (options.getAnycasting()) { for (Address mbr : targetMembers) { Message copy = request_msg.copy(true); copy.setDest(mbr); transport.send(copy); } } else { transport.send(request_msg); } } } catch (Exception ex) { if (corr != null) corr.done(requestId); throw ex; } }
/** Send a message to the address specified in msg.dest */ private void sendUnicastMessage(Message msg) { IpAddress dest; Message copy; Object hdr; Event evt; dest = (IpAddress) msg.getDest(); // guaranteed not to be null if (!(dest instanceof IpAddress)) { Trace.error("TCP.sendUnicastMessage()", "destination address is not of type IpAddress !"); return; } setSourceAddress(msg); /* Don't send if destination is local address. Instead, switch dst and src and put in up_queue */ if (loopback && local_addr != null && dest != null && dest.equals(local_addr)) { copy = msg.copy(); hdr = copy.getHeader(getName()); if (hdr != null && hdr instanceof TcpHeader) copy.removeHeader(getName()); copy.setSrc(local_addr); copy.setDest(local_addr); evt = new Event(Event.MSG, copy); /* Because Protocol.up() is never called by this bottommost layer, we call up() directly in the observer. This allows e.g. PerfObserver to get the time of reception of a message */ if (observer != null) observer.up(evt, up_queue.size()); passUp(evt); return; } if (Trace.trace) Trace.info( "TCP.sendUnicastMessage()", "dest=" + msg.getDest() + ", hdrs:\n" + msg.printObjectHeaders()); try { if (skip_suspected_members) { if (suspected_mbrs.contains(dest)) { if (Trace.trace) Trace.info( "TCP.sendUnicastMessage()", "will not send unicast message to " + dest + " as it is currently suspected"); return; } } ct.send(msg); } catch (SocketException e) { if (members.contains(dest)) { if (!suspected_mbrs.contains(dest)) { suspected_mbrs.add(dest); passUp(new Event(Event.SUSPECT, dest)); } } } }
/** Send a message to the address specified in dest */ void sendUdpMessage(Message msg) throws Exception { IpAddress dest; Message copy; Event evt; dest = (IpAddress) msg.getDest(); // guaranteed not to be null setSourceAddress(msg); if (Trace.debug) { Trace.debug( "UDP.sendUdpMessage()", "sending message to " + msg.getDest() + " (src=" + msg.getSrc() + "), headers are " + msg.getHeaders()); // Don't send if destination is local address. Instead, switch dst and src and put in // up_queue. // If multicast message, loopback a copy directly to us (but still multicast). Once we receive // this, // we will discard our own multicast message } if (loopback && (dest.equals(local_addr) || dest.isMulticastAddress())) { copy = msg.copy(); copy.removeHeader(name); copy.setSrc(local_addr); copy.setDest(dest); evt = new Event(Event.MSG, copy); /* Because Protocol.up() is never called by this bottommost layer, we call up() directly in the observer. This allows e.g. PerfObserver to get the time of reception of a message */ if (observer != null) { observer.up(evt, up_queue.size()); } if (Trace.debug) { Trace.info("UDP.sendUdpMessage()", "looped back local message " + copy); } passUp(evt); if (!dest.isMulticastAddress()) { return; } } if (use_outgoing_packet_handler) { outgoing_queue.add(msg); return; } send(msg); }
private void sendMulticastMessage(Message msg) { Address dest; Vector mbrs = (Vector) members.clone(); // if(Trace.trace) // Trace.info("TCP.sendMulticastMessage()", "sending message to " + msg.getDest() + // ", mbrs=" + mbrs); for (int i = 0; i < mbrs.size(); i++) { dest = (Address) mbrs.elementAt(i); msg.setDest(dest); sendUnicastMessage(msg); } }
protected static Message constructMessage( Buffer buf, Address recipient, ResponseMode mode, boolean rsvp, DeliverOrder deliverOrder) { Message msg = new Message(); msg.setBuffer(buf); encodeDeliverMode(msg, deliverOrder); // some issues with the new bundler. put back the DONT_BUNDLE flag. if (deliverOrder == DeliverOrder.NONE || mode != ResponseMode.GET_NONE) msg.setFlag(Message.Flag.DONT_BUNDLE); if (rsvp) msg.setFlag(Message.Flag.RSVP); if (recipient != null) msg.setDest(recipient); return msg; }
void sendMultipleUdpMessages(Message msg, Vector dests) { Address dest; for (int i = 0; i < dests.size(); i++) { dest = (Address) dests.elementAt(i); msg.setDest(dest); try { sendUdpMessage(msg); } catch (Exception e) { Trace.debug("UDP.sendMultipleUdpMessages()", "exception=" + e); } } }
private static Message constructMessage( Buffer buf, Address recipient, boolean oob, ResponseMode mode, boolean rsvp) { Message msg = new Message(); msg.setBuffer(buf); if (oob) msg.setFlag(Message.OOB); if (oob || mode != ResponseMode.GET_NONE) { msg.setFlag(Message.DONT_BUNDLE); // This is removed since this optimisation is no longer valid. See ISPN-1878 // msg.setFlag(Message.NO_FC); } if (rsvp) msg.setFlag(Message.RSVP); if (recipient != null) msg.setDest(recipient); return msg; }
private Message _decrypt(final Cipher cipher, Message msg, boolean decrypt_entire_msg) throws Exception { byte[] decrypted_msg; if (cipher == null) decrypted_msg = code(msg.getRawBuffer(), msg.getOffset(), msg.getLength(), true); else decrypted_msg = cipher.doFinal(msg.getRawBuffer(), msg.getOffset(), msg.getLength()); if (!decrypt_entire_msg) { msg.setBuffer(decrypted_msg); return msg; } Message ret = Util.streamableFromBuffer(Message.class, decrypted_msg, 0, decrypted_msg.length); if (ret.getDest() == null) ret.setDest(msg.getDest()); if (ret.getSrc() == null) ret.setSrc(msg.getSrc()); return ret; }
public Object down(final Event evt) { switch (evt.getType()) { case Event.MSG: final Message msg = (Message) evt.getArg(); if (msg.getDest() != null) break; // only process multicast messages if (next == null) // view hasn't been received yet, use the normal transport break; // 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); Executor pool = msg.isFlagSet(Message.Flag.OOB) ? oob_pool : default_pool; pool.execute(() -> up_prot.up(evt)); } return down_prot.down(new Event(Event.MSG, copy)); case Event.VIEW_CHANGE: handleView((View) evt.getArg()); break; case Event.TMP_VIEW: view_size = ((View) evt.getArg()).size(); break; case Event.SET_LOCAL_ADDRESS: local_addr = (Address) evt.getArg(); break; } return down_prot.down(evt); }
/** * Constructs a Message given a destination Address * * @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(3); }
/** * Caller by the layer above this layer. Usually we just put this Message into the send queue and * let one or more worker threads handle it. A worker thread then removes the Message from the * send queue, performs a conversion and adds the modified Message to the send queue of the layer * below it, by calling Down). */ public void down(Event evt) { Message msg; Object dest_addr; if (evt.getType() != Event.MSG) { // unless it is a message handle it and respond handleDownEvent(evt); return; } // ****************** profiling ****************** /*if(num_msgs == 0) { start=System.currentTimeMillis(); num_msgs++; } else if(num_msgs >= 1000) { stop=System.currentTimeMillis(); long total_time=stop-start; double msgs_per_msec=num_msgs / (double)total_time; if(Trace.trace) Trace.info("UDP.down.profile()", "total_time=" + total_time + ", msgs/ms=" + msgs_per_msec); num_msgs=0; } else { num_msgs++; }*/ // ****************** profiling ****************** msg = (Message) evt.getArg(); if (udp_hdr != null && udp_hdr.group_addr != null) { // added patch by Roland Kurmann (March 20 2003) msg.putHeader(name, udp_hdr); } dest_addr = msg.getDest(); // Because we don't call Protocol.passDown(), we notify the observer directly (e.g. // PerfObserver). // This way, we still have performance numbers for UDP if (observer != null) { observer.passDown(evt); } if (dest_addr == null) { // 'null' means send to all group members if (ip_mcast) { if (mcast_addr == null) { Trace.error( "UDP.down()", "dest address of message is null, and " + "sending to default address fails as mcast_addr is null, too !" + " Discarding message " + Util.printEvent(evt)); return; } // if we want to use IP multicast, then set the destination of the message msg.setDest(mcast_addr); } else { // sends a separate UDP message to each address sendMultipleUdpMessages(msg, members); return; } } try { sendUdpMessage(msg); } catch (Exception e) { Trace.error("UDP.down()", "exception=" + e + ", msg=" + msg + ", mcast_addr=" + mcast_addr); } }