summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'a1-policy-management/src/main/java')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java34
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java3
2 files changed, 28 insertions, 9 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java
index 18507ac2..46033a4a 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java
@@ -45,6 +45,7 @@ public class Lock {
private int lockCounter = 0;
final Queue<LockRequest> lockRequestQueue = new LinkedList<>();
private static AsynchCallbackExecutor callbackProcessor = new AsynchCallbackExecutor();
+ private final String label;
public enum LockType {
EXCLUSIVE, SHARED
@@ -63,6 +64,7 @@ public class Lock {
Grant(Lock lock, String label) {
this.lock = lock;
this.label = label;
+ logger.trace("Lock granted {}:{}", lock.label, this.label);
}
/**
@@ -71,27 +73,42 @@ public class Lock {
* @return the lock
*/
public Mono<Lock> unlock() {
- check();
- return this.lock.unlock();
+ if (!isUnlocked()) {
+ logger.trace("Unlocking lock {}:{}", lock.label, this.label);
+ return this.lock.unlock();
+ }
+ return Mono.just(this.lock);
}
/**
* Synchronuous unlocking
*/
public void unlockBlocking() {
- check();
- this.lock.unlockBlocking();
+ if (!isUnlocked()) {
+ logger.trace("Unlocking lock {}:{}", lock.label, this.label);
+ this.lock.unlockBlocking();
+ }
}
- private void check() {
+ private boolean isUnlocked() {
if (unlocked) {
- logger.error("Lock already unlocked");
+ logger.debug("Lock {}:{} already unlocked", lock.label, this.label);
+ return true;
}
unlocked = true;
+ return false;
}
}
/**
+ *
+ * @param label a label attached to the lock. For troubleshooting.
+ */
+ public Lock(String label) {
+ this.label = label;
+ }
+
+ /**
* Reactive lock. The Lock will be emitted when the lock is granted
*
* @param lockType type of lock (exclusive/shared)
@@ -140,7 +157,7 @@ public class Lock {
@Override
public synchronized String toString() {
- return "Lock cnt: " + this.lockCounter + " exclusive: " + this.isExclusive + " queued: "
+ return "Lock " + this.label + ", cnt: " + this.lockCounter + ", exclusive: " + this.isExclusive + ", queued: "
+ this.lockRequestQueue.size();
}
@@ -164,6 +181,7 @@ public class Lock {
}
private synchronized void addToQueue(MonoSink<Grant> callback, LockType lockType, String label) {
+ logger.trace("Lock request queued {}:{}", label, this.label);
lockRequestQueue.add(new LockRequest(callback, lockType, this, label));
}
@@ -172,7 +190,7 @@ public class Lock {
try {
this.wait();
} catch (InterruptedException e) {
- logger.warn("waitForUnlock interrupted", e);
+ logger.warn("waitForUnlock interrupted " + this.label, e);
Thread.currentThread().interrupt();
}
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java
index 8eca6be9..f43737f5 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java
@@ -45,7 +45,7 @@ public class Ric {
private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN;
@Getter
- private final Lock lock = new Lock();
+ private final Lock lock;
/**
* Creates the Ric. Initial state is {@link RicState.UNDEFINED}.
@@ -54,6 +54,7 @@ public class Ric {
*/
public Ric(RicConfig ricConfig) {
this.ricConfig = ricConfig;
+ this.lock = new Lock(ricConfig.ricId());
}
public String id() {