コード例 #1
0
 @Override
 public void run() {
   ClassLoader originalLoader = Classes.setTCCL(_loader);
   try {
     _session.getStateful().fireUntilHalt();
   } finally {
     try {
       _handler.disposeStatefulSession();
     } finally {
       Classes.setTCCL(originalLoader);
     }
   }
 }
コード例 #2
0
 /** {@inheritDoc} */
 @Override
 public void handleAction(Exchange exchange, KnowledgeAction action) throws HandlerException {
   RulesActionType actionType = (RulesActionType) action.getType();
   switch (actionType) {
     case EXECUTE:
       {
         KnowledgeSession session = newStatelessSession();
         setGlobals(exchange, action, session, true);
         List<Object> input = getInputList(exchange, action);
         session.getStateless().execute(input);
         break;
       }
     case INSERT:
     case FIRE_ALL_RULES:
       {
         /*
         if (!isContinue(exchange)) {
             disposeStatefulSession();
         }
         */
         KnowledgeSession session = getStatefulSession();
         setGlobals(exchange, action, session, true);
         List<Object> input = getInputList(exchange, action);
         for (Object fact : input) {
           session.getStateful().insert(fact);
         }
         if (RulesActionType.FIRE_ALL_RULES.equals(actionType)) {
           session.getStateful().fireAllRules();
         }
         if (isDispose(exchange)) {
           disposeStatefulSession();
         }
         break;
       }
     case FIRE_UNTIL_HALT:
       {
         /*
         if (!isContinue(exchange)) {
             disposeStatefulSession();
         }
         */
         KnowledgeSession session = getStatefulSession();
         setGlobals(exchange, action, session, false);
         if (_fireUntilHaltThread == null) {
           FireUntilHalt fireUntilHalt = new FireUntilHalt(this, session, getLoader());
           session.addDisposals(fireUntilHalt);
           _fireUntilHaltThread = fireUntilHalt.startThread();
         }
         final String undefinedVariable = toVariable(exchange);
         Map<String, List<Object>> listMap =
             getListMap(exchange, action.getInputExpressionMappings(), true, undefinedVariable);
         if (listMap.size() > 0) {
           for (Entry<String, List<Object>> entry : listMap.entrySet()) {
             String key = entry.getKey();
             if (undefinedVariable.equals(key)) {
               String id = Strings.trimToNull(action.getId());
               if (id != null) {
                 key = id;
               }
             }
             List<Object> input = entry.getValue();
             if (undefinedVariable.equals(key)) {
               for (Object fact : input) {
                 session.getStateful().insert(fact);
               }
             } else {
               SessionEntryPoint sep = session.getStateful().getEntryPoint(key);
               if (sep != null) {
                 for (Object fact : input) {
                   sep.insert(fact);
                 }
               } else {
                 throw new HandlerException(
                     "Unknown entry point: " + sep + "; please check your rules source.");
               }
             }
           }
         } else {
           Object content = exchange.getMessage().getContent();
           if (content != null) {
             session.getStateful().insert(content);
           }
         }
         if (isDispose(exchange)) {
           disposeStatefulSession();
         }
         break;
       }
     default:
       {
         throw new HandlerException("Unsupported action type: " + actionType);
       }
   }
   Object output = getOutput(exchange, action);
   if (ExchangePattern.IN_OUT.equals(
       exchange.getContract().getProviderOperation().getExchangePattern())) {
     Message message = exchange.createMessage().setContent(output);
     exchange.send(message);
   }
 }