diff options
author | 2018-06-27 10:12:45 -0400 | |
---|---|---|
committer | 2018-06-27 12:58:08 -0400 | |
commit | ee2313141a40222a83d6bf39a15c3f9d4c3a239e (patch) | |
tree | 38dde92661c2082f8b14afcf7eae93709a99a532 /policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java | |
parent | 7883ff2c523721284612ef5aac2a8a7fc1c1a396 (diff) |
Add time limit to locking facility
Modified the locking facility to add a time limit and remove the
callback parameter. This affected both the default facility as
well as the distributed locking feature. It will also require
a change to the rules for Closed Loop.
Changed testUnlock() to try locking with a different owner.
Default feature API should be OPER_UNHANDLED.
Put a few things back so-as not to break the drools-applications
build. They can be removed once drools-applications is updated.
Fix newlines in API java.
Change-Id: I3ed7835cac6a582493a9bc8f6d1d4f3e6cb6289e
Issue-ID: POLICY-872
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java')
-rw-r--r-- | policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java index 97e7242d..afe1cabe 100644 --- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java +++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java @@ -20,9 +20,6 @@ package org.onap.policy.drools.core.lock; -import static org.onap.policy.drools.core.lock.LockRequestFuture.MSG_NULL_OWNER; -import static org.onap.policy.drools.core.lock.LockRequestFuture.MSG_NULL_RESOURCE_ID; -import static org.onap.policy.drools.core.lock.LockRequestFuture.makeNullArgException; import java.util.List; import java.util.concurrent.Future; import java.util.function.Function; @@ -71,9 +68,22 @@ public class PolicyResourceLockManager extends SimpleLockManager { protected static void setFactory(Factory factory) { PolicyResourceLockManager.factory = factory; } + + /** + * This method is here temporarily so-as not to break the drools-applications + * build. It will be removed once drools-applications has been updated. + * @param resourceId + * @param owner + * @param callback + * @return nothing; always throws an exception + * @throws UnsupportedOperationException + */ + public Future<Boolean> lock(String resourceId, String owner, Callback callback) { + throw new UnsupportedOperationException("lock with callback"); + } @Override - public Future<Boolean> lock(String resourceId, String owner, Callback callback) { + public boolean lock(String resourceId, String owner, int holdSec) { if (resourceId == null) { throw makeNullArgException(MSG_NULL_RESOURCE_ID); } @@ -82,19 +92,16 @@ public class PolicyResourceLockManager extends SimpleLockManager { throw makeNullArgException(MSG_NULL_OWNER); } - Future<Boolean> result = doIntercept(null, impl -> impl.beforeLock(resourceId, owner, callback)); - if (result != null) { - return result; - } - // implementer didn't do the work - use superclass - result = super.lock(resourceId, owner, callback); + return doBoolIntercept(impl -> impl.beforeLock(resourceId, owner, holdSec), () -> { - boolean locked = ((LockRequestFuture) result).isLocked(); + // implementer didn't do the work - defer to the superclass + boolean locked = super.lock(resourceId, owner, holdSec); - doIntercept(false, impl -> impl.afterLock(resourceId, owner, locked)); + doIntercept(false, impl -> impl.afterLock(resourceId, owner, locked)); - return result; + return locked; + }); } @Override |