summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-10-15 16:19:01 +0000
committerGerrit Code Review <gerrit@onap.org>2019-10-15 16:19:01 +0000
commit1528214803af722cd660b7c4a3129f3de5b4ea7f (patch)
treea0fc34c24e1a500106dda787c1ce5254995ce527
parente9b60c3d6c9ae7b8fd4bf94a7897b2ea3dbfaeda (diff)
parent33ec206449c190cb6fbd5e9ae186b04c15a5576c (diff)
Merge "Add 'PolicySession.insertDrools' method"
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java4
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java23
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java15
3 files changed, 40 insertions, 2 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 bd97ddb1..4e1b1d6c 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
@@ -489,7 +489,7 @@ public class PolicyContainer implements Startable {
synchronized (sessions) {
PolicySession session = sessions.get(name);
if (session != null) {
- session.getKieSession().insert(object);
+ session.insertDrools(object);
return true;
}
}
@@ -506,7 +506,7 @@ public class PolicyContainer implements Startable {
boolean rval = false;
synchronized (sessions) {
for (PolicySession session : sessions.values()) {
- session.getKieSession().insert(object);
+ session.insertDrools(object);
rval = true;
}
}
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 6352eaa2..c2b72fb5 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
@@ -232,6 +232,29 @@ public class PolicySession
}
}
+ /**
+ * This method will insert an object into the Drools memory associated
+ * with this 'PolicySession' instance. Features are given the opportunity
+ * to handle the insert, and a distributed host feature could use this to
+ * send the object to another host, and insert it in the corresponding
+ * Drools session.
+ *
+ * @param object the object to insert in Drools memory
+ */
+ public void insertDrools(Object object) {
+ for (PolicySessionFeatureApi feature :
+ PolicySessionFeatureApiConstants.getImpl().getList()) {
+ if (feature.insertDrools(this, object)) {
+ // feature is performing the insert
+ return;
+ }
+ }
+ // no feature has intervened -- do the insert locally
+ if (kieSession != null) {
+ kieSession.insert(object);
+ }
+ }
+
/*=================================*/
/* 'AgendaEventListener' interface */
/*=================================*/
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 dd9ec154..331cebe8 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
@@ -78,6 +78,21 @@ public interface PolicySessionFeatureApi extends OrderedService {
}
/**
+ * This method is called when 'PolicySession.insertDrools' is called.
+ * In a distributed host environment, features have the ability to send
+ * the object do a different host, and do the insert.
+ *
+ * @param policySession the 'PolicySession' object associated with the
+ * Drools session
+ * @param object the object to insert in Drools memory
+ * @return 'true' if this feature is handling the operation,
+ * and 'false' if not.
+ */
+ public default boolean insertDrools(PolicySession session, Object object) {
+ return false;
+ }
+
+ /**
* This method is called after 'KieSession.dispose()' is called.
*
* @param policySession the 'PolicySession' object that wrapped the