[jboss-svn-commits] JBL Code SVN: r7534 - labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Nov 10 12:05:13 EST 2006
Author: kurt.stam at jboss.com
Date: 2006-11-10 12:05:12 -0500 (Fri, 10 Nov 2006)
New Revision: 7534
Modified:
labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
Log:
Adding in Dave's patch. This is good feedback.
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2006-11-10 16:07:09 UTC (rev 7533)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2006-11-10 17:05:12 UTC (rev 7534)
@@ -25,12 +25,13 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
+import org.drools.FactHandle;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
@@ -49,7 +50,7 @@
*/
public class JBossRulesRouter extends ContentBasedRouter
{
- private static Map<String,WorkingMemory> workingMemories=new HashMap<String,WorkingMemory>();
+ private static Map<String,WorkingMemory> workingMemories=new ConcurrentHashMap<String,WorkingMemory>();
private static Logger logger = Logger.getLogger(JBossRulesRouter.class);
/**
* Route the message, where the routing rules are supplied as part of
@@ -87,24 +88,26 @@
{
List<String> destinationServices = new ArrayList<String>();
try {
- if (!workingMemories.containsKey(ruleSet)) {
+ WorkingMemory workingMemory = workingMemories.get(ruleSet);
+ if (workingMemory==null) {
logger.log(Priority.INFO, "Reading ruleSet from file=" + ruleSet);
RuleBase ruleBase = readRuleBase(ruleSet, ruleLanguage);
- WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+ workingMemory = ruleBase.newWorkingMemory();
workingMemories.put(ruleSet, workingMemory);
}
logger.log(Priority.DEBUG, "Obtained message=" + message + " with ruleSet=" + ruleSet);
- WorkingMemory workingMemory = workingMemories.get(ruleSet);
- workingMemory.setGlobal("destinationServices", destinationServices);
- workingMemory.assertObject(message);
- logger.log(Priority.INFO, "Fire the rules engine");
- workingMemory.fireAllRules();
- //Now route there, later we will implement an option to place a callback.
+ synchronized(workingMemory) {
+ workingMemory.setGlobal("destinationServices", destinationServices);
+ FactHandle factHandle = workingMemory.assertObject(message);
+ logger.log(Priority.INFO, "Fire the JBossRules Engine");
+ workingMemory.fireAllRules();
+ workingMemory.retractObject(factHandle);
+ }
destinationServices = (List) workingMemory.getGlobal("destinationServices");
logger.log(Priority.DEBUG, "Destination Services List: " + destinationServices);
- Boolean deliverMessages = (Boolean) message.getProperties().getProperty(MessageRouter.DELIVER_MESSAGES);
- //Only actuall deliver the message if this is set in the message
- if (!Boolean.FALSE.equals(deliverMessages)) {
+ Boolean isDeliverMessages = (Boolean) message.getProperties().getProperty(MessageRouter.DELIVER_MESSAGES);
+ //Deliver the message to their desitinations unless told not to.
+ if (!Boolean.FALSE.equals(isDeliverMessages)) {
deliverMessages(destinationServices, message);
}
} catch (Exception e) {
More information about the jboss-svn-commits
mailing list