summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjrh3 <jrh3@att.com>2019-07-31 15:31:06 -0400
committerjrh3 <jrh3@att.com>2019-07-31 18:52:38 -0400
commitd0fd49a0b212d79d248d1bc9e23e978c2af2f03b (patch)
tree342e4a4ee8630ff0330ed0c13a1db2c25d8233c9
parentbccd3a9b4d86c582f2065907a51ac2cade366691 (diff)
Adjust timer manager logging
Add a few more logging statements to the timer manager. Also changed logger.debug() to logger.info(). Replaced map.computeIfPresent() with map.remove(), as it simplified the relevant code block significantly. Change-Id: I211e9f07bd6df6a01532b1ecabdde5ae1585cc18 Issue-ID: POLICY-1960 Signed-off-by: jrh3 <jrh3@att.com>
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/TimerManager.java32
1 files changed, 10 insertions, 22 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/TimerManager.java b/main/src/main/java/org/onap/policy/pap/main/comm/TimerManager.java
index 99677fb8..0565e90a 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/TimerManager.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/TimerManager.java
@@ -25,7 +25,6 @@ import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -110,10 +109,13 @@ public class TimerManager implements Runnable {
public Timer register(String timerName, Consumer<String> action) {
synchronized (lockit) {
- Timer timer = new Timer(timerName, action);
-
// always remove existing entry so that new entry goes at the end of the map
- name2timer.remove(timerName);
+ Timer timer = name2timer.remove(timerName);
+ if (timer != null) {
+ logger.info("{} timer replaced {}", name, timer);
+ }
+
+ timer = new Timer(timerName, action);
name2timer.put(timerName, timer);
logger.info("{} timer registered {}", name, timer);
@@ -203,6 +205,7 @@ public class TimerManager implements Runnable {
// run the timer
try {
+ logger.info("{} timer firing {}", TimerManager.this.name, timer);
timer.runner.accept(timer.name);
} catch (RuntimeException e) {
logger.warn("{} timer threw an exception {}", TimerManager.this.name, timer, e);
@@ -265,28 +268,13 @@ public class TimerManager implements Runnable {
private boolean cancel(String cancelMsg) {
synchronized (lockit) {
- AtomicBoolean wasPresent = new AtomicBoolean(false);
-
- name2timer.computeIfPresent(name, (key, val) -> {
-
- if (val == this) {
- wasPresent.set(true);
- return null;
-
- } else {
- // different timer is in the map - leave it
- return val;
- }
- });
-
- if (!wasPresent.get()) {
+ if (!name2timer.remove(name, this)) {
// have a new timer in the map - ignore "this" timer
- logger.info("{} timer replaced {}", TimerManager.this.name, this);
+ logger.info("{} timer discarded ({}) {}", TimerManager.this.name, cancelMsg, this);
return false;
}
- logger.debug("{} timer {} {}", TimerManager.this.name, cancelMsg, this);
-
+ logger.info("{} timer {} {}", TimerManager.this.name, cancelMsg, this);
return true;
}
}