aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java96
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java24
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java6
3 files changed, 66 insertions, 60 deletions
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 9fc2c837..2da53468 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
@@ -51,11 +51,11 @@ public class PolicyContainer implements Startable
// set of all 'PolicyContainer' instances
static private HashSet<PolicyContainer> containers =
- new HashSet<PolicyContainer>();
+ new HashSet<>();
// maps feature objects to per-PolicyContainer data
private ConcurrentHashMap<Object, Object> adjuncts =
- new ConcurrentHashMap<Object, Object>();
+ new ConcurrentHashMap<>();
// 'KieContainer' associated with this 'PolicyContainer'
private KieContainer kieContainer;
@@ -66,7 +66,7 @@ public class PolicyContainer implements Startable
// maps session name into the associated 'PolicySession' instance
private HashMap<String, PolicySession> sessions =
- new HashMap<String, PolicySession>();
+ new HashMap<>();
// if not null, this is a 'KieScanner' looking for updates
private KieScanner scanner = null;
@@ -104,21 +104,22 @@ public class PolicyContainer implements Startable
*/
public PolicyContainer(ReleaseId releaseId)
{
- if (releaseId.getVersion().contains(","))
+ ReleaseId newReleaseId = releaseId;
+ if (newReleaseId.getVersion().contains(","))
{
// this is actually a comma-separated list of release ids
- releaseId = loadArtifact(releaseId.getGroupId(),
- releaseId.getArtifactId(),
- releaseId.getVersion());
+ newReleaseId = loadArtifact(newReleaseId.getGroupId(),
+ newReleaseId.getArtifactId(),
+ newReleaseId.getVersion());
}
else
{
- kieContainer = kieServices.newKieContainer(releaseId);
+ kieContainer = kieServices.newKieContainer(newReleaseId);
}
synchronized(containers)
{
- if(releaseId != null){
- logger.info("Add a new kieContainer in containers: releaseId: " + releaseId.toString());
+ if(newReleaseId != null){
+ logger.info("Add a new kieContainer in containers: releaseId: " + newReleaseId.toString());
}else{
logger.warn("input releaseId is null");
}
@@ -182,9 +183,9 @@ public class PolicyContainer implements Startable
{
// all of the 'newKieContainer' invocations failed -- throw the
// most recent exception
- throw(exception);
+ throw exception;
}
- return(releaseId);
+ return releaseId;
}
/**
@@ -198,7 +199,7 @@ public class PolicyContainer implements Startable
*/
public String getName()
{
- return(kieContainer.getReleaseId().toString());
+ return kieContainer.getReleaseId().toString();
}
/**
@@ -206,7 +207,7 @@ public class PolicyContainer implements Startable
*/
public KieContainer getKieContainer()
{
- return(kieContainer);
+ return kieContainer;
}
/**
@@ -214,7 +215,7 @@ public class PolicyContainer implements Startable
*/
public ClassLoader getClassLoader()
{
- return(kieContainer.getClassLoader());
+ return kieContainer.getClassLoader();
}
/**
@@ -223,7 +224,7 @@ public class PolicyContainer implements Startable
*/
public String getGroupId()
{
- return(kieContainer.getReleaseId().getGroupId());
+ return kieContainer.getReleaseId().getGroupId();
}
/**
@@ -232,7 +233,7 @@ public class PolicyContainer implements Startable
*/
public String getArtifactId()
{
- return(kieContainer.getReleaseId().getArtifactId());
+ return kieContainer.getReleaseId().getArtifactId();
}
/**
@@ -241,7 +242,7 @@ public class PolicyContainer implements Startable
*/
public String getVersion()
{
- return(kieContainer.getReleaseId().getVersion());
+ return kieContainer.getReleaseId().getVersion();
}
/**
@@ -253,7 +254,7 @@ public class PolicyContainer implements Startable
*/
public PolicySession getPolicySession(String name)
{
- return(sessions.get(name));
+ return sessions.get(name);
}
/**
@@ -325,7 +326,7 @@ public class PolicyContainer implements Startable
logger.info("activatePolicySession:session - "
+ (session == null ? "null" : session.getFullName())
+ " is returned.");
- return(session);
+ return session;
}
}
@@ -352,14 +353,14 @@ public class PolicyContainer implements Startable
if(name == null){
logger.warn("adoptKieSession:input name is null");
- throw(new IllegalArgumentException
+ throw new IllegalArgumentException
("KieSession input name is null "
- + getName()));
+ + getName());
}else if(kieSession == null){
logger.warn("adoptKieSession:input kieSession is null");
- throw(new IllegalArgumentException
+ throw new IllegalArgumentException
("KieSession '" + name + "' is null "
- + getName()));
+ + getName());
}else {
logger.info("adoptKieSession:name: " + name + " kieSession: " + kieSession);
}
@@ -381,17 +382,17 @@ public class PolicyContainer implements Startable
// default KieBase, if it exists
if (!match && kieBase != kieContainer.getKieBase())
{
- throw(new IllegalArgumentException
+ throw new IllegalArgumentException
("KieSession '" + name + "' does not reside within container "
- + getName()));
+ + getName());
}
synchronized (sessions)
{
if (sessions.get(name) != null)
{
- throw(new IllegalStateException
- ("PolicySession '" + name + "' already exists"));
+ throw new IllegalStateException
+ ("PolicySession '" + name + "' already exists");
}
// create the new 'PolicySession', add it to the table,
@@ -415,7 +416,7 @@ public class PolicyContainer implements Startable
+ feature.getClass().getName(), e);
}
}
- return(policySession);
+ return policySession;
}
}
@@ -437,8 +438,8 @@ public class PolicyContainer implements Startable
releaseId.getArtifactId(),
newVersion));
- List<Message> messages = (results == null ? null : results.getMessages());
- return(messages == null ? null : messages.toString());
+ List<Message> messages = results == null ? null : results.getMessages();
+ return messages == null ? null : messages.toString();
}
/**
@@ -473,7 +474,7 @@ public class PolicyContainer implements Startable
session.updated();
}
- return(results);
+ return results;
}
/**
@@ -483,7 +484,7 @@ public class PolicyContainer implements Startable
{
synchronized(containers)
{
- return(new HashSet<PolicyContainer>(containers));
+ return new HashSet<>(containers);
}
}
@@ -495,7 +496,7 @@ public class PolicyContainer implements Startable
// KLUDGE WARNING: this is a temporary workaround -- if there are
// no features, we don't have persistence, and 'activate' is never
// called. In this case, make sure the container is started.
- if (PolicySessionFeatureAPI.impl.getList().size() == 0)
+ if (PolicySessionFeatureAPI.impl.getList().isEmpty())
{
start();
}
@@ -503,7 +504,7 @@ public class PolicyContainer implements Startable
// return current set of PolicySessions
synchronized(sessions)
{
- return(new HashSet<PolicySession>(sessions.values()));
+ return new HashSet<>(sessions.values());
}
}
@@ -518,7 +519,7 @@ public class PolicyContainer implements Startable
{
String version = releaseId.getVersion();
if (scannerStarted == false && scanner == null && version != null
- && (version.equals("LATEST") || version.equals("RELEASE")
+ && ("LATEST".equals(version) || "RELEASE".equals(version)
|| version.endsWith("-SNAPSHOT")))
{
// create the scanner, and poll at 60 second intervals
@@ -529,6 +530,7 @@ public class PolicyContainer implements Startable
// start this in a separate thread -- it can block for a long time
new Thread("Scanner Starter " + getName())
{
+ @Override
public void run()
{
scanner = kieServices.newKieScanner(kieContainer);
@@ -562,10 +564,10 @@ public class PolicyContainer implements Startable
if (session != null)
{
session.getKieSession().insert(object);
- return(true);
+ return true;
}
}
- return(false);
+ return false;
}
/**
@@ -586,7 +588,7 @@ public class PolicyContainer implements Startable
rval = true;
}
}
- return(rval);
+ return rval;
}
/*************************/
@@ -596,6 +598,7 @@ public class PolicyContainer implements Startable
/**
* {@inheritDoc}
*/
+ @Override
public synchronized boolean start()
{
if (!isStarted)
@@ -619,12 +622,13 @@ public class PolicyContainer implements Startable
}
isStarted = true;
}
- return(true);
+ return true;
}
/**
* {@inheritDoc}
*/
+ @Override
public synchronized boolean stop()
{
if (isStarted)
@@ -634,7 +638,7 @@ public class PolicyContainer implements Startable
synchronized (sessions)
{
// local set containing all of the sessions
- localSessions = new HashSet<PolicySession>(sessions.values());
+ localSessions = new HashSet<>(sessions.values());
// clear the 'name->session' map in 'PolicyContainer'
sessions.clear();
@@ -664,12 +668,13 @@ public class PolicyContainer implements Startable
}
isStarted = false;
}
- return(true);
+ return true;
}
/**
* {@inheritDoc}
*/
+ @Override
public synchronized void shutdown()
{
// Note that this method does not call 'destroy' on the 'KieSession'
@@ -689,9 +694,10 @@ public class PolicyContainer implements Startable
/**
* {@inheritDoc}
*/
+ @Override
public boolean isAlive()
{
- return(isStarted);
+ return isStarted;
}
/*************************/
@@ -710,7 +716,7 @@ public class PolicyContainer implements Startable
synchronized (sessions)
{
// local set containing all of the sessions
- localSessions = new HashSet<PolicySession>(sessions.values());
+ localSessions = new HashSet<>(sessions.values());
// clear the 'name->session' map in 'PolicyContainer'
sessions.clear();
@@ -831,7 +837,7 @@ public class PolicyContainer implements Startable
*/
public Object getAdjunct(Object object)
{
- return(adjuncts.get(object));
+ return adjuncts.get(object);
}
/**
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 c18c1343..2a949c0b 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
@@ -62,7 +62,7 @@ public class PolicySession
// maps feature objects to per-PolicyContainer data
private ConcurrentHashMap<Object, Object> adjuncts =
- new ConcurrentHashMap<Object, Object>();
+ new ConcurrentHashMap<>();
// associated 'KieSession' instance
private KieSession kieSession;
@@ -72,7 +72,7 @@ public class PolicySession
// supports 'getCurrentSession()' method
static private ThreadLocal<PolicySession> policySession =
- new ThreadLocal<PolicySession>();
+ new ThreadLocal<>();
/**
* Internal constructor - create a 'PolicySession' instance
@@ -96,7 +96,7 @@ public class PolicySession
*/
public PolicyContainer getPolicyContainer()
{
- return(container);
+ return container;
}
/**
@@ -104,7 +104,7 @@ public class PolicySession
*/
public KieSession getKieSession()
{
- return(kieSession);
+ return kieSession;
}
/**
@@ -114,7 +114,7 @@ public class PolicySession
*/
public String getName()
{
- return(name);
+ return name;
}
/**
@@ -123,7 +123,7 @@ public class PolicySession
*/
public String getFullName()
{
- return(container.getName() + ":" + name);
+ return container.getName() + ":" + name;
}
/**
@@ -204,7 +204,7 @@ public class PolicySession
*/
public static PolicySession getCurrentSession()
{
- return(policySession.get());
+ return policySession.get();
}
/**
@@ -218,7 +218,7 @@ public class PolicySession
*/
public Object getAdjunct(Object object)
{
- return(adjuncts.get(object));
+ return adjuncts.get(object);
}
/**
@@ -555,19 +555,19 @@ public class PolicySession
// We want to continue looping, despite any exceptions that occur
// while rules are fired.
- KieSession kieSession = session.getKieSession();
+ KieSession kieSession1 = session.getKieSession();
while (repeat)
{
try
{
- kieSession.fireUntilHalt();
+ kieSession1.fireUntilHalt();
- // if we fall through, it means 'KieSession.halt()' was called,
+ // if we fall through, it means 'kieSession1.halt()' was called,
// but this may be a result of 'KieScanner' doing an update
}
catch (Exception | LinkageError e)
{
- logger.error("startThread error in kieSession.fireUntilHalt", e);
+ logger.error("startThread error in kieSession1.fireUntilHalt", e);
}
}
logger.info("fireUntilHalt() returned");
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java
index 6777eb59..39377ab7 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java
@@ -39,7 +39,7 @@ public interface PolicySessionFeatureAPI extends OrderedService
* implementing the 'FeatureAPI' interface.
*/
static public OrderedServiceImpl<PolicySessionFeatureAPI> impl =
- new OrderedServiceImpl<PolicySessionFeatureAPI>(PolicySessionFeatureAPI.class);
+ new OrderedServiceImpl<>(PolicySessionFeatureAPI.class);
/**
* This method is called during initialization at a point right after
@@ -68,7 +68,7 @@ public interface PolicySessionFeatureAPI extends OrderedService
default public KieSession activatePolicySession
(PolicyContainer policyContainer, String name, String kieBaseName)
{
- return(null);
+ return null;
}
/**
@@ -86,7 +86,7 @@ public interface PolicySessionFeatureAPI extends OrderedService
default public PolicySession.ThreadModel selectThreadModel
(PolicySession session)
{
- return(null);
+ return null;
}
/**