-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
LogStreamBroadcaster.java
42 lines (32 loc) · 1.17 KB
/
LogStreamBroadcaster.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package io.quarkus.devui.runtime.logstream;
import java.util.concurrent.LinkedBlockingQueue;
import jakarta.enterprise.context.ApplicationScoped;
import io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor;
import io.vertx.core.json.JsonObject;
@ApplicationScoped
public class LogStreamBroadcaster {
private final LinkedBlockingQueue<JsonObject> history = new LinkedBlockingQueue<>(60);
private final BroadcastProcessor<JsonObject> logStream = BroadcastProcessor.create();
public BroadcastProcessor<JsonObject> getLogStream() {
return this.logStream;
}
public void onNext(JsonObject message) {
recordHistory(message);
this.logStream.onNext(message);
}
public LinkedBlockingQueue<JsonObject> getHistory() {
return history;
}
private void recordHistory(final JsonObject message) {
synchronized (this) {
try {
if (history.remainingCapacity() == 0) {
history.take();
}
history.add(message);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}