From 6cac817d3968f3d467e407ae94794c0493ec9abf Mon Sep 17 00:00:00 2001 From: Ellis Michael Date: Sun, 17 Mar 2024 14:44:59 -0700 Subject: [PATCH] Prevent duplicate log messages in sub-Nodes. Thanks @dfpetrin! --- framework/src/dslabs/framework/Node.java | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/framework/src/dslabs/framework/Node.java b/framework/src/dslabs/framework/Node.java index 914e168b..eb6dbeff 100644 --- a/framework/src/dslabs/framework/Node.java +++ b/framework/src/dslabs/framework/Node.java @@ -261,14 +261,18 @@ private void send(Message message, Address from, Address to) { return; } + // If this Node is a sub-Node, use the parent to send the message. + if (parentNode != null && messageAdder == null && batchMessageAdder == null) { + parentNode.send(message, from, to); + return; + } + LOG.finest(() -> String.format("MessageSend(%s -> %s, %s)", from, to, message)); if (messageAdder != null) { messageAdder.accept(new ImmutableTriple<>(from, to, message)); } else if (batchMessageAdder != null) { batchMessageAdder.accept(new ImmutableTriple<>(from, new Address[] {to}, message)); - } else if (parentNode != null) { - parentNode.send(message, from, to); } else { LOG.severe( String.format( @@ -299,6 +303,12 @@ private void broadcast(Message message, Address from, Address[] to) { } } + // If this Node is a sub-Node, use the parent to broadcast the message. + if (parentNode != null && messageAdder == null && batchMessageAdder == null) { + parentNode.broadcast(message, from, to); + return; + } + LOG.finest( () -> String.format("MessageSend(%s -> %s, %s)", from, Arrays.toString(to), message)); @@ -308,8 +318,6 @@ private void broadcast(Message message, Address from, Address[] to) { for (Address a : to) { messageAdder.accept(new ImmutableTriple<>(from, a, message)); } - } else if (parentNode != null) { - parentNode.broadcast(message, from, to); } else { LOG.severe( String.format( @@ -324,14 +332,18 @@ private void set(Timer timer, int minTimerLengthMillis, int maxTimerLengthMillis return; } + // If this Node is a sub-Node, use the parent to set the timer. + if (parentNode != null && timerAdder == null) { + parentNode.set(timer, minTimerLengthMillis, maxTimerLengthMillis, from); + return; + } + LOG.finest(() -> String.format("TimerSet(-> %s, %s)", from, timer)); if (timerAdder != null) { timerAdder.accept( new ImmutableTriple<>( from, timer, new ImmutablePair<>(minTimerLengthMillis, maxTimerLengthMillis))); - } else if (parentNode != null) { - parentNode.set(timer, minTimerLengthMillis, maxTimerLengthMillis, from); } else { LOG.severe( String.format(