Skip to content

Commit

Permalink
Fix log ordering
Browse files Browse the repository at this point in the history
nano time is not enough, rather use a "sequence"
  • Loading branch information
cstamas authored and gnodet committed Nov 25, 2024
1 parent 1c55095 commit 8c77069
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion common/src/main/java/org/mvndaemon/mvnd/common/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;

public abstract class Message {
public static final int BUILD_REQUEST = 1;
Expand Down Expand Up @@ -125,10 +126,13 @@ public static Message read(DataInputStream input) throws IOException {
throw new IllegalStateException("Unexpected message type: " + type);
}

private static final AtomicLong sequence = new AtomicLong();

final long seq = sequence.incrementAndGet();
final long timestamp = System.nanoTime();

public static Comparator<Message> getMessageComparator() {
return Comparator.comparingInt(Message::getClassOrder).thenComparingLong(Message::timestamp);
return Comparator.comparingInt(Message::getClassOrder).thenComparingLong(Message::seq);
}

public static int getClassOrder(Message m) {
Expand Down Expand Up @@ -178,6 +182,10 @@ public static int getClassOrder(Message m) {
}
}

public long seq() {
return seq;
}

public long timestamp() {
return timestamp;
}
Expand Down

0 comments on commit 8c77069

Please sign in to comment.