aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahoo-inc.com>2017-05-30 09:55:33 +0200
committerBjørn Christian Seime <bjorncs@yahoo-inc.com>2017-05-30 11:19:44 +0200
commit70e8ea955b7a349408c92fd6b8aeeddcccc8df59 (patch)
tree05e6f91e9d720ccc039e289125677d506cac6757 /jdisc_core
parent606acc8e051d983698099f9ec1bcbfcde10a2690 (diff)
Misc fixes to ActiveContainerStatistics
Diffstat (limited to 'jdisc_core')
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerStatistics.java54
1 files changed, 25 insertions, 29 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerStatistics.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerStatistics.java
index 43a57aece64..e5404d58ab8 100644
--- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerStatistics.java
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerStatistics.java
@@ -27,23 +27,9 @@ public class ActiveContainerStatistics {
private final WeakHashMap<ActiveContainer, ActiveContainerStats> activeContainers = new WeakHashMap<>();
private final Object lock = new Object();
- public void onActivated(ActiveContainer activeContainer) {
- synchronized (lock) {
- activeContainers.put(activeContainer, new ActiveContainerStats(Instant.now()));
- }
- }
+ ActiveContainerStatistics() {} // Make class only constructible from this package
- public void onDeactivated(ActiveContainer activeContainer) {
- synchronized (lock) {
- ActiveContainerStats containerStats = activeContainers.get(activeContainer);
- if (containerStats == null) {
- throw new IllegalStateException("onActivated() has not been called for container: " + activeContainer);
- }
- containerStats.setTimeDeactived(Instant.now());
- }
- }
-
- public void outputMetrics(Metric metric) {
+ public void emitMetrics(Metric metric) {
synchronized (lock) {
DeactivatedContainerMetrics metrics = deactivatedContainerStream()
.collect(
@@ -56,12 +42,27 @@ public class ActiveContainerStatistics {
}
}
- public void printSummaryToLog() {
+ void onActivated(ActiveContainer activeContainer) {
synchronized (lock) {
- List<DeactivatedContainer> deactivatedContainers = deactivatedContainerStream().collect(toList());
- if (deactivatedContainers.isEmpty()) {
- return;
+ activeContainers.put(activeContainer, new ActiveContainerStats(Instant.now()));
+ }
+ }
+
+ void onDeactivated(ActiveContainer activeContainer) {
+ synchronized (lock) {
+ ActiveContainerStats containerStats = activeContainers.get(activeContainer);
+ if (containerStats == null) {
+ throw new IllegalStateException("onActivated() has not been called for container: " + activeContainer);
}
+ containerStats.timeDeactivated = Instant.now();
+ }
+ }
+
+ void printSummaryToLog() {
+ synchronized (lock) {
+ List<DeactivatedContainer> deactivatedContainers = deactivatedContainerStream().collect(toList());
+ if (deactivatedContainers.isEmpty()) return;
+
log.warning(
"Multiple instances of ActiveContainer leaked! " + deactivatedContainers.size() +
" instances are still present.");
@@ -74,26 +75,21 @@ public class ActiveContainerStatistics {
private Stream<DeactivatedContainer> deactivatedContainerStream() {
synchronized (lock) {
return activeContainers.entrySet().stream()
- .filter(e -> e.getKey() != null)
- .filter(e -> !e.getValue().isDeactivated())
- .map(e -> new DeactivatedContainer(e.getKey(), e.getValue().timeActivated, e.getValue().timeDeactived));
+ .filter(e -> e.getValue().isDeactivated())
+ .map(e -> new DeactivatedContainer(e.getKey(), e.getValue().timeActivated, e.getValue().timeDeactivated));
}
}
private static class ActiveContainerStats {
public final Instant timeActivated;
- public Instant timeDeactived;
+ public Instant timeDeactivated;
public ActiveContainerStats(Instant timeActivated) {
this.timeActivated = timeActivated;
}
- public void setTimeDeactived(Instant instant) {
- this.timeDeactived = instant;
- }
-
public boolean isDeactivated() {
- return timeDeactived == null;
+ return timeDeactivated != null;
}
}