Add 'PolicySession.insertDrools' method 84/96884/2
authorStraubs, Ralph (rs8887) <rs8887@att.com>
Thu, 10 Oct 2019 12:48:14 +0000 (07:48 -0500)
committerStraubs, Ralph (rs8887) <rs8887@att.com>
Tue, 15 Oct 2019 11:17:37 +0000 (06:17 -0500)
This change includes feature hooks, so a "smart insert" could forward
the object to a remote host, and do the insert there. The methods 'insert'
and 'insertAll' in 'PolicyContainer' now make use of this smart insert.

Change-Id: I69f0e874b6fda09d1f457e4353e4b30d63696210
Issue-ID: POLICY-2160
Signed-off-by: Straubs, Ralph (rs8887) <rs8887@att.com>
policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java

index bd97ddb..4e1b1d6 100644 (file)
@@ -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;
             }
         }
index 6352eaa..c2b72fb 100644 (file)
@@ -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 */
     /*=================================*/
index dd9ec15..331cebe 100644 (file)
@@ -77,6 +77,21 @@ public interface PolicySessionFeatureApi extends OrderedService {
         return null;
     }
 
+    /**
+     * 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.
      *