aboutsummaryrefslogtreecommitdiffstats
path: root/policy-core/src/main/java/org/onap/policy/drools/core
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2021-08-09 13:10:52 +0000
committerGerrit Code Review <gerrit@onap.org>2021-08-09 13:10:52 +0000
commit51a81cbdb39a4d15764e2d28c32b9161a1f5d76c (patch)
treec0ba33cd57352b71ce9a54b721ecbc36787426d7 /policy-core/src/main/java/org/onap/policy/drools/core
parentaabb9e500132bbcd639bc4b8bda34e8fde3a3676 (diff)
parentda1b7d9f04453e94fb77ebe4213f456a0be63fc2 (diff)
Merge "Use lombok in drools-pdp #2"
Diffstat (limited to 'policy-core/src/main/java/org/onap/policy/drools/core')
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/DroolsExecutor.java13
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java34
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java42
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java9
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java13
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmxListener.java13
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java11
7 files changed, 44 insertions, 91 deletions
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/DroolsExecutor.java b/policy-core/src/main/java/org/onap/policy/drools/core/DroolsExecutor.java
index 538970d6..d996d5a3 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/DroolsExecutor.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/DroolsExecutor.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,24 +21,17 @@
package org.onap.policy.drools.core;
import java.util.concurrent.Executor;
+import lombok.AllArgsConstructor;
import org.drools.core.WorkingMemory;
/**
* An executor that executes its tasks by inserting {@link DroolsRunnable} objects into
* the working memory of a running session.
*/
+@AllArgsConstructor
public class DroolsExecutor implements Executor {
private final WorkingMemory workingMemory;
- /**
- * Constructs the object.
- *
- * @param workingMemory where tasks should be injected
- */
- public DroolsExecutor(WorkingMemory workingMemory) {
- this.workingMemory = workingMemory;
- }
-
@Override
public void execute(Runnable command) {
DroolsRunnable runnable = command::run;
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
index 5bce3505..1eab676f 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-core
* ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +26,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
-import org.kie.api.KieBase;
+import lombok.Getter;
import org.kie.api.KieServices;
import org.kie.api.builder.KieScanner;
import org.kie.api.builder.Message;
@@ -57,6 +57,7 @@ public class PolicyContainer implements Startable {
private ConcurrentHashMap<Object, Object> adjuncts = new ConcurrentHashMap<>();
// 'KieContainer' associated with this 'PolicyContainer'
+ @Getter
private KieContainer kieContainer;
// indicates whether the PolicyContainer is 'started'
@@ -106,7 +107,7 @@ public class PolicyContainer implements Startable {
* @param releaseId indicates the artifact that is to be installed in this container
*/
public PolicyContainer(ReleaseId releaseId) {
- ReleaseId newReleaseId = releaseId;
+ var newReleaseId = releaseId;
if (newReleaseId.getVersion().contains(",")) {
// this is actually a comma-separated list of release ids
newReleaseId =
@@ -193,15 +194,6 @@ public class PolicyContainer implements Startable {
}
/**
- * Get kie container.
- *
- * @return the associated 'KieContainer' instance
- */
- public KieContainer getKieContainer() {
- return kieContainer;
- }
-
- /**
* Get class loader.
*
* @return the 'ClassLoader' associated with the 'KieContainer' instance
@@ -332,8 +324,8 @@ public class PolicyContainer implements Startable {
logger.info("adoptKieSession:name: {} kieSession: {}", name, kieSession);
}
// fetch KieBase, and verify it belongs to this KieContainer
- boolean match = false;
- KieBase kieBase = kieSession.getKieBase();
+ var match = false;
+ var kieBase = kieSession.getKieBase();
logger.info("adoptKieSession:kieBase: {}", kieBase);
for (String kieBaseName : kieContainer.getKieBaseNames()) {
logger.info("adoptKieSession:kieBaseName: {}", kieBaseName);
@@ -358,7 +350,7 @@ public class PolicyContainer implements Startable {
// create the new 'PolicySession', add it to the table,
// and return the object to the caller
logger.info("adoptKieSession:create a new policySession with name {}", name);
- PolicySession policySession = new PolicySession(name, this, kieSession);
+ var policySession = new PolicySession(name, this, kieSession);
sessions.put(name, policySession);
// notify features
@@ -383,8 +375,8 @@ public class PolicyContainer implements Startable {
* how to determine success/failure)
*/
public String updateToVersion(String newVersion) {
- ReleaseId releaseId = kieContainer.getReleaseId();
- Results results = this.updateToVersion(
+ var releaseId = kieContainer.getReleaseId();
+ var results = this.updateToVersion(
kieServices.newReleaseId(releaseId.getGroupId(), releaseId.getArtifactId(), newVersion));
List<Message> messages = results == null ? null : results.getMessages();
@@ -411,7 +403,7 @@ public class PolicyContainer implements Startable {
}
// update the version
- Results results = kieContainer.updateToVersion(releaseId);
+ var results = kieContainer.updateToVersion(releaseId);
// add common KiePackage instances
@@ -519,7 +511,7 @@ public class PolicyContainer implements Startable {
* @return 'true' if the fact was inserted into at least one session, 'false' if not
*/
public boolean insertAll(Object object) {
- boolean rval = false;
+ var rval = false;
synchronized (sessions) {
for (PolicySession session : sessions.values()) {
session.insertDrools(object);
@@ -553,7 +545,7 @@ public class PolicyContainer implements Startable {
for (String kieSessionName : kieContainer.getKieSessionNamesInKieBase(kieBaseName)) {
// if the 'PolicySession' does not currently exist, this method
// call will attempt to create it
- PolicySession session = activatePolicySession(kieSessionName, kieBaseName);
+ var session = activatePolicySession(kieSessionName, kieBaseName);
if (session != null) {
session.startThread();
}
@@ -708,7 +700,7 @@ public class PolicyContainer implements Startable {
* @param args standard 'main' arguments, which are currently ignored
*/
public static void globalInit(String[] args) {
- String configDir = "config";
+ var configDir = "config";
logger.info("PolicyContainer.main: configDir={}", configDir);
// invoke 'globalInit' on all of the features
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
index fb17b10a..1f8a61c6 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
@@ -22,6 +22,7 @@
package org.onap.policy.drools.core;
import java.util.concurrent.ConcurrentHashMap;
+import lombok.Getter;
import org.kie.api.event.rule.AfterMatchFiredEvent;
import org.kie.api.event.rule.AgendaEventListener;
import org.kie.api.event.rule.AgendaGroupPoppedEvent;
@@ -52,11 +53,18 @@ public class PolicySession
implements AgendaEventListener, RuleRuntimeEventListener {
// get an instance of logger
private static Logger logger = LoggerFactory.getLogger(PolicySession.class);
+
+ // supports 'getCurrentSession()' method
+ private static ThreadLocal<PolicySession> policySess =
+ new ThreadLocal<>();
+
// name of the 'PolicySession' and associated 'KieSession'
+ @Getter
private String name;
// the associated 'PolicyContainer', which may have additional
// 'PolicySession' instances in addition to this one
+ @Getter
private PolicyContainer container;
// maps feature objects to per-PolicyContainer data
@@ -64,15 +72,12 @@ public class PolicySession
new ConcurrentHashMap<>();
// associated 'KieSession' instance
+ @Getter
private KieSession kieSession;
// if not 'null', this is the thread model processing the 'KieSession'
private ThreadModel threadModel = null;
- // supports 'getCurrentSession()' method
- private static ThreadLocal<PolicySession> policySess =
- new ThreadLocal<>();
-
/**
* Internal constructor - create a 'PolicySession' instance.
*
@@ -90,35 +95,6 @@ public class PolicySession
}
/**
- * Get policy container.
- *
- * @return the 'PolicyContainer' object containing this session
- */
- public PolicyContainer getPolicyContainer() {
- return container;
- }
-
- /**
- * Get Kie Session.
- *
- * @return the associated 'KieSession' instance
- */
- public KieSession getKieSession() {
- return kieSession;
- }
-
- /**
- * Get name.
- *
- * @return the local name of this session, which should either match the
- * name specified in 'kmodule.xml' file associated with this session, or the
- * name passed on the 'PolicyContainer.adoptKieSession' method.
- */
- public String getName() {
- return name;
- }
-
- /**
* Get full name.
*
* @return the 'PolicyContainer' name, followed by ':', followed by the
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java
index 174ac794..98808848 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-core
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,9 +20,12 @@
package org.onap.policy.drools.core;
+import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import org.onap.policy.common.utils.services.OrderedServiceImpl;
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PolicySessionFeatureApiConstants {
/**
* 'FeatureAPI.impl.getList()' returns an ordered list of objects
@@ -31,8 +34,4 @@ public class PolicySessionFeatureApiConstants {
@Getter
private static final OrderedServiceImpl<PolicySessionFeatureApi> impl =
new OrderedServiceImpl<>(PolicySessionFeatureApi.class);
-
- private PolicySessionFeatureApiConstants() {
- // do nothing
- }
}
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java b/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java
index e1a89752..0f4add77 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* policy-core
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,17 +21,16 @@
package org.onap.policy.drools.core.jmx;
import java.util.concurrent.atomic.AtomicLong;
+import lombok.Getter;
public class PdpJmx implements PdpJmxMBean {
+ @Getter
private static PdpJmx instance = new PdpJmx();
+
private final AtomicLong updates = new AtomicLong();
private final AtomicLong actions = new AtomicLong();
- public static PdpJmx getInstance() {
- return instance;
- }
-
@Override
public long getUpdates() {
return updates.longValue();
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmxListener.java b/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmxListener.java
index 924f2b00..4a39173c 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmxListener.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmxListener.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-core
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,25 +24,24 @@ import java.lang.management.ManagementFactory;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
-import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PdpJmxListener {
public static final Logger logger = LoggerFactory.getLogger(PdpJmxListener.class);
- private PdpJmxListener() {
- }
-
/**
* Stop the listener.
*/
public static void stop() {
- final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ final var server = ManagementFactory.getPlatformMBeanServer();
try {
server.unregisterMBean(new ObjectName("PolicyEngine:type=PdpJmx"));
} catch (MBeanRegistrationException | InstanceNotFoundException
@@ -58,7 +57,7 @@ public class PdpJmxListener {
* Start.
*/
public static void start() {
- final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ final var server = ManagementFactory.getPlatformMBeanServer();
try {
server.registerMBean(PdpJmx.getInstance(), new ObjectName("PolicyEngine:type=PdpJmx"));
} catch (InstanceAlreadyExistsException | MBeanRegistrationException
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java
index 03024f52..dbb20883 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,22 +20,17 @@
package org.onap.policy.drools.core.lock;
+import lombok.NoArgsConstructor;
/**
* Lock implementation whose operations always fail.
*/
+@NoArgsConstructor
public class AlwaysFailLock extends LockImpl {
private static final long serialVersionUID = 1L;
/**
* Constructs the object.
- */
- public AlwaysFailLock() {
- super();
- }
-
- /**
- * Constructs the object.
*
* @param resourceId identifier of the resource to be locked
* @param ownerKey information identifying the owner requesting the lock