From 749a0a0b8b9b19b465b092cfc91e3d461914eb77 Mon Sep 17 00:00:00 2001 From: cfredri4 Date: Thu, 14 Nov 2024 19:52:23 +0100 Subject: [PATCH] Simplify for transports to send to multiple destinations 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 --- src/org/jgroups/protocols/TP.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/org/jgroups/protocols/TP.java b/src/org/jgroups/protocols/TP.java index 8dd53e9be7..e315f029cd 100644 --- a/src/org/jgroups/protocols/TP.java +++ b/src/org/jgroups/protocols/TP.java @@ -1381,6 +1381,7 @@ protected void sendToAll(byte[] buf, int offset, int length) throws Exception { } } + List 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 @@ -1392,19 +1393,27 @@ 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); + } + if (!dests.isEmpty()) + sendUnicasts(dests, buf, offset, length); + if(missing != null) + fetchPhysicalAddrs(missing); + } + + protected void sendUnicasts(List 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); }