summaryrefslogtreecommitdiffstats
path: root/feature-session-persistence/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'feature-session-persistence/src/main/java/org')
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java10
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java10
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java140
3 files changed, 82 insertions, 78 deletions
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
index 42a638a0..c3f00359 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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,8 +21,6 @@
package org.onap.policy.drools.persistence;
public class DroolsPersistenceProperties {
- private DroolsPersistenceProperties() {
- }
/*
* feature-session-persistence.properties parameter key values
*/
@@ -32,4 +30,8 @@ public class DroolsPersistenceProperties {
public static final String DB_PWD = "javax.persistence.jdbc.password";
public static final String DB_SESSIONINFO_TIMEOUT = "persistence.sessioninfo.timeout";
public static final String JTA_OBJECTSTORE_DIR = "persistence.objectstore.dir";
+
+ private DroolsPersistenceProperties() {
+ super();
+ }
}
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
index 9bb26ac1..47ed221e 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -54,11 +54,7 @@ public class EntityMgrTrans extends EntityMgrCloser {
userTrans.begin();
em.joinTransaction();
- } catch (RuntimeException e) {
- em.close();
- throw new EntityMgrException(e);
-
- } catch (NotSupportedException | SystemException e) {
+ } catch (RuntimeException |NotSupportedException | SystemException e) {
em.close();
throw new EntityMgrException(e);
}
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
index 032383b4..129be8a7 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -148,7 +148,7 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
* {@inheritDoc}
*/
@Override
- public void globalInit(String args[], String configDir) {
+ public void globalInit(String[] args, String configDir) {
kieSvcFact = fact.getKieServices();
@@ -448,21 +448,71 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
ds.close();
}
}
- }
- /* ============================================================ */
+ /**
+ * Configures java system properties for JPA/JTA.
+ */
+ private void configureSysProps() {
+ System.setProperty("com.arjuna.ats.arjuna.coordinator.defaultTimeout", "60");
+ System.setProperty("com.arjuna.ats.arjuna.objectstore.objectStoreDir",
+ persistProps.getProperty(DroolsPersistenceProperties.JTA_OBJECTSTORE_DIR));
+ System.setProperty("ObjectStoreEnvironmentBean.objectStoreDir",
+ persistProps.getProperty(DroolsPersistenceProperties.JTA_OBJECTSTORE_DIR));
+ }
- /**
- * Configures java system properties for JPA/JTA.
- */
- private void configureSysProps() {
- System.setProperty("com.arjuna.ats.arjuna.coordinator.defaultTimeout", "60");
- System.setProperty("com.arjuna.ats.arjuna.objectstore.objectStoreDir",
- persistProps.getProperty(DroolsPersistenceProperties.JTA_OBJECTSTORE_DIR));
- System.setProperty("ObjectStoreEnvironmentBean.objectStoreDir",
- persistProps.getProperty(DroolsPersistenceProperties.JTA_OBJECTSTORE_DIR));
+ /**
+ * Configures a Kie Environment
+ *
+ * @param env
+ * environment to be configured
+ * @param emf
+ * entity manager factory
+ */
+ private void configureKieEnv(Environment env, EntityManagerFactory emf) {
+ env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
+ env.set(EnvironmentName.TRANSACTION, fact.getUserTrans());
+ env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY, fact.getTransSyncReg());
+ env.set(EnvironmentName.TRANSACTION_MANAGER, fact.getTransMgr());
+ }
+
+ /**
+ * Gets a session's ID from the persistent store.
+ *
+ * @param conn
+ * persistence connector
+ * @param sessnm
+ * name of the session
+ * @return the session's id, or {@code -1} if the session is not found
+ */
+ private long getSessionId(DroolsSessionConnector conn, String sessnm) {
+ DroolsSession sess = conn.get(sessnm);
+ return sess != null ? sess.getSessionId() : -1;
+ }
+
+ /**
+ * Replaces a session within the persistent store, if it exists. Adds it
+ * otherwise.
+ *
+ * @param conn
+ * persistence connector
+ * @param sessnm
+ * name of session to be updated
+ * @param kieSession
+ * new session information
+ */
+ private void replaceSession(DroolsSessionConnector conn, String sessnm, KieSession kieSession) {
+
+ DroolsSessionEntity sess = new DroolsSessionEntity();
+
+ sess.setSessionName(sessnm);
+ sess.setSessionId(kieSession.getIdentifier());
+
+ conn.replace(sess);
+ }
}
+ /* ============================================================ */
+
/**
* Gets the data source properties.
*
@@ -485,21 +535,6 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
}
/**
- * Configures a Kie Environment
- *
- * @param env
- * environment to be configured
- * @param emf
- * entity manager factory
- */
- private void configureKieEnv(Environment env, EntityManagerFactory emf) {
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
- env.set(EnvironmentName.TRANSACTION, fact.getUserTrans());
- env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY, fact.getTransSyncReg());
- env.set(EnvironmentName.TRANSACTION_MANAGER, fact.getTransMgr());
- }
-
- /**
* Removes "old" Drools 'sessioninfo' records, so they aren't used to
* restore data to Drools sessions. This also has the useful side-effect of
* removing abandoned records as well.
@@ -543,41 +578,6 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
}
/**
- * Gets a session's ID from the persistent store.
- *
- * @param conn
- * persistence connector
- * @param sessnm
- * name of the session
- * @return the session's id, or {@code -1} if the session is not found
- */
- private long getSessionId(DroolsSessionConnector conn, String sessnm) {
- DroolsSession sess = conn.get(sessnm);
- return sess != null ? sess.getSessionId() : -1;
- }
-
- /**
- * Replaces a session within the persistent store, if it exists. Adds it
- * otherwise.
- *
- * @param conn
- * persistence connector
- * @param sessnm
- * name of session to be updated
- * @param kieSession
- * new session information
- */
- private void replaceSession(DroolsSessionConnector conn, String sessnm, KieSession kieSession) {
-
- DroolsSessionEntity sess = new DroolsSessionEntity();
-
- sess.setSessionName(sessnm);
- sess.setSessionId(kieSession.getIdentifier());
-
- conn.replace(sess);
- }
-
- /**
* Determine whether persistence is enabled for a specific container
*
* @param container
@@ -801,7 +801,8 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
// We want to continue, despite any exceptions that occur
// while rules are fired.
- for (;;) {
+ boolean cont = true;
+ while(cont) {
try {
if (kieSession.fireAllRules() > 0) {
@@ -815,16 +816,17 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
} catch (Exception | LinkageError e) {
logger.error("Exception during kieSession.fireAllRules", e);
}
+
try {
if (stopped.await(sleepTime, TimeUnit.MILLISECONDS)) {
- break;
+ cont = false;
}
} catch (InterruptedException e) {
logger.error("startThread exception: ", e);
Thread.currentThread().interrupt();
- break;
+ cont = false;
}
}
@@ -892,6 +894,10 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
private static class SingletonRegistry {
private static final TransactionSynchronizationRegistry transreg = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();
+
+ private SingletonRegistry() {
+ super();
+ }
}
/**