I saw some old thread about caching the rule base on your own. I have a singleton which
contains a hashmap to do the caching. I am using the Guvnor to pull my rules from. This
works fine except when the rules change on the Guvnor. When the rule base tries to
refresh in my application, I am getting a ClassCastException. Any ideas?
RuleAgent(Assembly) EXCEPTION (Fri Feb 26 12:02:32 EST 2010):
java.lang.ClassCastException: org.drools.util.ObjectHashMap cannot be cast to
org.drools.reteoo.BetaMemory. Stack trace should follow.
org.drools.RuntimeDroolsException: java.lang.ClassCastException:
org.drools.util.ObjectHashMap cannot be cast to org.drools.reteoo.BetaMemory
My code to do the caching is below:
private HashMap<String, RuleBase> ruleBaseMap = new HashMap<String,
RuleBase>();
// check to see if we already set up this rule base
if (ruleBaseMap.containsKey(product.getConfigurationRule())) {
rb = ruleBaseMap.get(product.getConfigurationRule());
} else {
try {
InitialContext context = new InitialContext();
url = (String) context.lookup("java:comp/env/rules.url");
url = url + product.getConfigurationRule() + "/LATEST";
} catch (NamingException e1) {
}
Properties config = new Properties();
config.setProperty("newInstance", "false");
config.setProperty("url", url);
config.setProperty("poll", "300");
config.setProperty("name", "Assembly");
RuleAgent agent = RuleAgent.newRuleAgent(config);
rb = agent.getRuleBase();
ruleBaseMap.put(product.getConfigurationRule(), rb);
}