Skip to content

Commit

Permalink
Simplify for transports to send to multiple destinations
Browse files Browse the repository at this point in the history
This change gives a convenient method to override to allow a transport to convert data (to e.g. a direct buffer) only once before sending to multiple destinations
  • Loading branch information
cfredri4 committed Nov 1, 2024
1 parent 0bd9494 commit e247fa6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/org/jgroups/protocols/TP.java
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,7 @@ protected void sendToAll(byte[] buf, int offset, int length) throws Exception {
}
}

List<PhysicalAddress> dests = new ArrayList<>(mbrs.size());
for(Address mbr: mbrs) {
if(local_send_successful && local_transport != null && local_transport.isLocalMember(mbr))
continue; // skip if local transport sent the message successfully
Expand All @@ -1413,19 +1414,26 @@ protected void sendToAll(byte[] buf, int offset, int length) throws Exception {
missing.add(mbr);
continue;
}
if (!Objects.equals(local_physical_addr, target))
dests.add(target);
}
sendUnicasts(dests, buf, offset, length);
if(missing != null)
fetchPhysicalAddrs(missing);
}

protected void sendUnicasts(List<PhysicalAddress> dests, byte[] data, int offset, int length) throws Exception {
for(PhysicalAddress dest: dests) {
try {
if(!Objects.equals(local_physical_addr, target))
sendUnicast(target, buf, offset, length);
sendUnicast(dest, data, offset, length);
}
catch(SocketException | SocketTimeoutException sock_ex) {
log.debug(Util.getMessage("FailureSendingToPhysAddr"), local_addr, mbr, sock_ex);
log.debug(Util.getMessage("FailureSendingToPhysAddr"), local_addr, dest, sock_ex);
}
catch(Throwable t) {
log.error(Util.getMessage("FailureSendingToPhysAddr"), local_addr, mbr, t);
log.error(Util.getMessage("FailureSendingToPhysAddr"), local_addr, dest, t);
}
}
if(missing != null)
fetchPhysicalAddrs(missing);
}


Expand Down

0 comments on commit e247fa6

Please sign in to comment.