コード例 #1
0
 synchronized StatelessSession getSession(final RulesData rules, final File folder)
     throws Exception {
   //            if (!MiscUtil.equals(rules.getModified(), timestamp)) {
   //                session = null;
   //            }
   if (session != null) {
     return session;
   }
   ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
   try {
     Thread.currentThread().setContextClassLoader(RuleEngine.class.getClassLoader());
     PackageBuilder builder = new PackageBuilder();
     StringBuilder script = new StringBuilder();
     rules.buildScript(script);
     if (LOG.isDebugEnabled()) {
       LOG.debug("compiling rules script:\r\n" + script);
     }
     builder.addPackageFromDrl(new StringReader(script.toString()));
     RuleBase ruleBase = RuleBaseFactory.newRuleBase();
     ruleBase.addPackage(builder.getPackage());
     session = ruleBase.newStatelessSession();
     LOG.debug("(re-)built rules for " + rules.getUid());
     timestamp = rules.getModified();
   } finally {
     Thread.currentThread().setContextClassLoader(oldCl);
   }
   save(folder);
   return session;
 }
コード例 #2
0
 public void execute(final RulesData rules, final List<? extends RuleProxy<?, ?>> data)
     throws Exception {
   long timing = System.currentTimeMillis();
   ExecutionSetEntry entry;
   synchronized (entries) {
     entry = (ExecutionSetEntry) entries.get(rules.getUid());
     if (entry == null) {
       entry = ExecutionSetEntry.load(folder, rules.getUid());
       if (entry == null) {
         entry = new ExecutionSetEntry(rules.getUid());
       }
       entries.put(entry.getRulesUid(), entry);
     }
   }
   entry.getSession(rules, folder).execute(data);
   // MiscUtil.logTiming(timing, "executed rules " + rules);
 }