Skip to content

Commit

Permalink
[LOGMGR-226] Atomic addHandler/replay op for QueueHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Dec 4, 2018
1 parent 4c93f0e commit eb596af
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions core/src/main/java/org/jboss/logmanager/handlers/QueueHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Deque;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
import org.wildfly.common.Assert;

import java.util.logging.ErrorManager;
import java.util.logging.Formatter;
Expand Down Expand Up @@ -119,6 +120,33 @@ public void setLimit(final int limit) {
}
}

@Override
public void addHandler(Handler handler) throws SecurityException {
addHandler(handler, false);
}

/**
* Add the given handler, optionally atomically replaying the queue, allowing the delegate handler to receive
* all queued messages as well as all subsequent messages with no loss or reorder in between.
*
* @param handler the handler to add (must not be {@code null})
* @param replay {@code true} to replay the prior messages, or {@code false} to add the handler without replaying
* @throws SecurityException if the handler was not allowed to be added
*/
public void addHandler(Handler handler, boolean replay) throws SecurityException {
Assert.checkNotNullParam("handler", handler);
if (replay) {
synchronized (buffer) {
super.addHandler(handler);
for (ExtLogRecord record : buffer) {
handler.publish(record);
}
}
} else {
super.addHandler(handler);
}
}

/**
* Get a copy of the queue as it is at an exact moment in time.
*
Expand Down

0 comments on commit eb596af

Please sign in to comment.