[Minor] Log long running observer updates
This commit is contained in:
parent
2aab18c2a2
commit
2668063d97
|
@ -1,5 +1,12 @@
|
||||||
package li.strolch.agent.api;
|
package li.strolch.agent.api;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.groupingBy;
|
||||||
|
import static java.util.stream.Collectors.joining;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import li.strolch.model.StrolchElement;
|
||||||
import li.strolch.model.StrolchRootElement;
|
import li.strolch.model.StrolchRootElement;
|
||||||
import li.strolch.utils.collections.MapOfLists;
|
import li.strolch.utils.collections.MapOfLists;
|
||||||
|
|
||||||
|
@ -7,4 +14,29 @@ public class ObserverEvent {
|
||||||
public MapOfLists<String, StrolchRootElement> added = new MapOfLists<>();
|
public MapOfLists<String, StrolchRootElement> added = new MapOfLists<>();
|
||||||
public MapOfLists<String, StrolchRootElement> updated = new MapOfLists<>();
|
public MapOfLists<String, StrolchRootElement> updated = new MapOfLists<>();
|
||||||
public MapOfLists<String, StrolchRootElement> removed = new MapOfLists<>();
|
public MapOfLists<String, StrolchRootElement> removed = new MapOfLists<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String added = this.added.isEmpty() ? "0" : collectSizes(this.added);
|
||||||
|
String updated = this.updated.isEmpty() ? "0" : collectSizes(this.updated);
|
||||||
|
String removed = this.removed.isEmpty() ? "0" : collectSizes(this.removed);
|
||||||
|
return "ObserverEvent{added=" + added + ", updated=" + updated + ", removed=" + removed + "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String collectSizes(MapOfLists<String, StrolchRootElement> added) {
|
||||||
|
return added.stream()
|
||||||
|
.map(entry -> entry.getKey() + "=[" + collectSizeByType(entry) + "]")
|
||||||
|
.collect(joining(","));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String collectSizeByType(Map.Entry<String, List<StrolchRootElement>> entry) {
|
||||||
|
String sizeByType = entry.getValue()
|
||||||
|
.stream()
|
||||||
|
.collect(groupingBy(StrolchElement::getType))
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(e -> e.getKey() + "=" + e.getValue().size())
|
||||||
|
.collect(joining(","));
|
||||||
|
return sizeByType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package li.strolch.agent.impl;
|
||||||
import static li.strolch.model.Tags.AGENT;
|
import static li.strolch.model.Tags.AGENT;
|
||||||
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
||||||
import static li.strolch.utils.collections.SynchronizedCollections.synchronizedMapOfLists;
|
import static li.strolch.utils.collections.SynchronizedCollections.synchronizedMapOfLists;
|
||||||
|
import static li.strolch.utils.helper.StringHelper.formatNanoDuration;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -87,6 +88,8 @@ public class DefaultObserverHandler implements ObserverHandler {
|
||||||
try {
|
try {
|
||||||
ObserverEvent event = this.eventQueue.takeFirst();
|
ObserverEvent event = this.eventQueue.takeFirst();
|
||||||
|
|
||||||
|
long start = System.nanoTime();
|
||||||
|
|
||||||
for (String key : event.added.keySet()) {
|
for (String key : event.added.keySet()) {
|
||||||
List<StrolchRootElement> list = event.added.getList(key);
|
List<StrolchRootElement> list = event.added.getList(key);
|
||||||
if (list != null)
|
if (list != null)
|
||||||
|
@ -103,6 +106,10 @@ public class DefaultObserverHandler implements ObserverHandler {
|
||||||
notifyRemove(key, list);
|
notifyRemove(key, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long durationNanos = System.nanoTime() - start;
|
||||||
|
if (durationNanos >= 250000000L)
|
||||||
|
logger.warn("Observer update for event " + event + " took " + formatNanoDuration(durationNanos));
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
if (this.run)
|
if (this.run)
|
||||||
logger.error("Failed to do updates!", e);
|
logger.error("Failed to do updates!", e);
|
||||||
|
|
Loading…
Reference in New Issue