diff options
Diffstat (limited to 'feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java')
-rw-r--r-- | feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java | 73 |
1 files changed, 40 insertions, 33 deletions
diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java index e8121f3a..c1d7192f 100644 --- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java +++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java @@ -31,6 +31,7 @@ import java.util.IdentityHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.UUID; @@ -698,47 +699,53 @@ public class Persistence implements PolicySessionFeatureApi, ServerPoolApi { private List<CountDownLatch> restoreBucketDroolsSessions() { List<CountDownLatch> sessionLatches = new LinkedList<>(); for (Map.Entry<String, ReceiverSessionBucketData> entry : sessionData.entrySet()) { - String sessionName = entry.getKey(); - ReceiverSessionBucketData rsbd = entry.getValue(); + restoreBucketDroolsSession(sessionLatches, entry); + } + return sessionLatches; + } - PolicySession policySession = detmPolicySession(sessionName); - if (policySession == null) { - logger.error(RESTORE_BUCKET_ERROR - + "Can't find PolicySession{}", sessionName); - continue; - } + private void restoreBucketDroolsSession(List<CountDownLatch> sessionLatches, + Entry<String, ReceiverSessionBucketData> entry) { - final Map<?, ?> droolsObjects = deserializeMap(sessionName, rsbd, policySession); - if (droolsObjects == null) { - continue; - } + String sessionName = entry.getKey(); + ReceiverSessionBucketData rsbd = entry.getValue(); - // if we reach this point, we have decoded the persistent data + PolicySession policySession = detmPolicySession(sessionName); + if (policySession == null) { + logger.error(RESTORE_BUCKET_ERROR + + "Can't find PolicySession{}", sessionName); + return; + } - // signal when restore is complete - final CountDownLatch sessionLatch = new CountDownLatch(1); + final Map<?, ?> droolsObjects = deserializeMap(sessionName, rsbd, policySession); + if (droolsObjects == null) { + return; + } - // 'KieSession' object - final KieSession kieSession = policySession.getKieSession(); + // if we reach this point, we have decoded the persistent data - // run the following within the Drools session thread - DroolsRunnable insertDroolsObjects = () -> { - try { - // insert all of the Drools objects into the session - for (Object droolsObj : droolsObjects.keySet()) { - kieSession.insert(droolsObj); - } - } finally { - // signal completion - sessionLatch.countDown(); + // signal when restore is complete + final CountDownLatch sessionLatch = new CountDownLatch(1); + + // 'KieSession' object + final KieSession kieSession = policySession.getKieSession(); + + // run the following within the Drools session thread + DroolsRunnable insertDroolsObjects = () -> { + try { + // insert all of the Drools objects into the session + for (Object droolsObj : droolsObjects.keySet()) { + kieSession.insert(droolsObj); } - }; - kieSession.insert(insertDroolsObjects); + } finally { + // signal completion + sessionLatch.countDown(); + } + }; + kieSession.insert(insertDroolsObjects); - // add this to the set of 'CountDownLatch's we are waiting for - sessionLatches.add(sessionLatch); - } - return sessionLatches; + // add this to the set of 'CountDownLatch's we are waiting for + sessionLatches.add(sessionLatch); } private PolicySession detmPolicySession(String sessionName) { |