Skip to content

Commit

Permalink
Prevent duplicate log messages in sub-Nodes. Thanks @dfpetrin!
Browse files Browse the repository at this point in the history
  • Loading branch information
emichael committed Mar 17, 2024
1 parent 69d8e31 commit 6cac817
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions framework/src/dslabs/framework/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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));

Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 6cac817

Please sign in to comment.