private KieRuntime extractIfNeeded(KieRuntime ksession) { if (ksession instanceof CommandBasedStatefulKnowledgeSession) { return ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession(); } return ksession; }
cmds.add(new InsertObjectCommand(new String("Hi!"), "handle")); ExecuteCommand execCmd = new ExecuteCommand(batchCmd,true); ExecutionResults results = execCmd.execute( context ); cmds.add(new InsertObjectCommand(new String("Hi!"), "handle")); batchCmd = CommandFactory.newBatchExecution(cmds, "kresults"); execCmd = new ExecuteCommand(batchCmd); results = execCmd.execute( context );
protected TimerManager getTimerManager(KieSession ksession) { KieSession internal = ksession; if (ksession instanceof CommandBasedStatefulKnowledgeSession) { internal = ( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession(); } return ((InternalProcessRuntime) ((StatefulKnowledgeSessionImpl) internal).getProcessRuntime()).getTimerManager(); }
protected TimerManager getTimerManager(KieSession ksession) { KieSession internal = ksession; if (ksession instanceof CommandBasedStatefulKnowledgeSession) { internal = ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession(); } return ((InternalProcessRuntime) ((StatefulKnowledgeSessionImpl) internal).getProcessRuntime()).getTimerManager(); }
private TimerManager getTimerManager(KieSession ksession) { KieSession internal = ksession; if (ksession instanceof CommandBasedStatefulKnowledgeSession) { internal = ( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession();; } return ((InternalProcessRuntime)((StatefulKnowledgeSessionImpl)internal).getProcessRuntime()).getTimerManager(); }
if (manager.hasEnvironmentEntry("IS_JTA_TRANSACTION", false)) { if (initialKsession instanceof CommandBasedStatefulKnowledgeSession) { ExecutableRunner commandService = ((CommandBasedStatefulKnowledgeSession) initialKsession).getRunner(); ((SingleSessionCommandService) commandService).destroy(); } else { ((RegistryContext) context).lookup( KieSession.class ).destroy();
public Integer execute(Context context) { SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession(); ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime .getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER); ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext(); List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal"); return processInstancesToSignalList.size(); } });
if (manager.hasEnvironmentEntry("IS_JTA_TRANSACTION", false)) { if (initialKsession instanceof CommandBasedStatefulKnowledgeSession) { ExecutableRunner commandService = ((CommandBasedStatefulKnowledgeSession) initialKsession).getRunner(); ((SingleSessionCommandService) commandService).destroy(); } else { ((RegistryContext) context).lookup( KieSession.class ).destroy();
public Integer execute(Context context) { SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession(); ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime .getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER); ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext(); List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal"); return processInstancesToSignalList.size(); } });
public Integer execute(Context context) { SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession(); ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime .getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER); ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext(); List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal"); return processInstancesToSignalList.size(); } });
protected ExecutableRunner getRunner( Long processInstanceId, ProcessJobContext ctx ) { RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); if (runtime == null) { throw new RuntimeException("No runtime engine found, could not be initialized yet"); } try { if (runtime.getKieSession() instanceof CommandBasedStatefulKnowledgeSession) { CommandBasedStatefulKnowledgeSession cmd = (CommandBasedStatefulKnowledgeSession) runtime.getKieSession(); if (ctx != null) { ctx.setKnowledgeRuntime((InternalKnowledgeRuntime) ( (SingleSessionCommandService) cmd.getRunner() ).getKieSession() ); } return new DisposableCommandService(cmd.getRunner(), manager, runtime, schedulerService.retryEnabled()); } else if (runtime.getKieSession() instanceof InternalKnowledgeRuntime && ctx != null) { ctx.setKnowledgeRuntime((InternalKnowledgeRuntime) runtime.getKieSession()); } return new DisposableCommandService(getRunner(), manager, runtime, schedulerService.retryEnabled()); } catch (Throwable e) { // since the DisposableCommandService was not created dispose runtime engine directly manager.disposeRuntimeEngine(runtime); throw new RuntimeException(e); } }
@Test @RequirePersistence public void testRuleTaskWithFactsWithPersistence() throws Exception { KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTaskWithFact.bpmn2", "BPMN2-RuleTask3.drl"); ksession = createKnowledgeSession(kbase); ( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession() .addEventListener(new TriggerRulesEventListener(ksession)); ksession.addEventListener(new DebugAgendaEventListener()); Map<String, Object> params = new HashMap<String, Object>(); params.put("x", "SomeString"); ProcessInstance processInstance = ksession.startProcess("RuleTask", params); assertProcessInstanceFinished(processInstance, ksession); params = new HashMap<String, Object>(); try { processInstance = ksession.startProcess("RuleTask", params); fail("Should fail"); } catch (Exception e) { e.printStackTrace(); } params = new HashMap<String, Object>(); params.put("x", "SomeString"); processInstance = ksession.startProcess("RuleTask", params); assertProcessInstanceFinished(processInstance, ksession); }
@Test @Ignore("beta4 phreak") public void testStartTimerCycleFromDiscDRL() throws Exception { KieBase kbase = createKnowledgeBaseFromDisc("rules-timer.drl"); StatefulKnowledgeSession ksession = createKnowledgeSession(kbase); long sessionId = ksession.getIdentifier(); Environment env = ksession.getEnvironment(); final List<String> list = new ArrayList<String>(); ksession.setGlobal("list", list); ( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession() .addEventListener(new TriggerRulesEventListener(ksession)); ksession.fireAllRules(); Thread.sleep(5000); assertEquals(2, list.size()); logger.info("dispose"); ksession.dispose(); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env); AuditLoggerFactory.newInstance(Type.JPA, ksession, null); final List<String> list2 = new ArrayList<String>(); ksession.setGlobal("list", list2); ( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession() .addEventListener(new TriggerRulesEventListener(ksession)); ksession.fireAllRules(); Thread.sleep(6000); assertEquals(3, list2.size()); }
@Test @Ignore("beta4 phreak") public void testStartTimerCycleFromClasspathDRL() throws Exception { KieBase kbase = createKnowledgeBaseWithoutDumper("rules-timer.drl"); StatefulKnowledgeSession ksession = createKnowledgeSession(kbase); long sessionId = ksession.getIdentifier(); Environment env = ksession.getEnvironment(); final List<String> list = new ArrayList<String>(); ksession.setGlobal("list", list); ( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession() .addEventListener(new TriggerRulesEventListener(ksession)); ksession.fireAllRules(); Thread.sleep(5000); assertEquals(2, list.size()); logger.info("dispose"); ksession.dispose(); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env); AuditLoggerFactory.newInstance(Type.JPA, ksession, null); final List<String> list2 = new ArrayList<String>(); ksession.setGlobal("list", list2); ( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession() .addEventListener(new TriggerRulesEventListener(ksession)); ksession.fireAllRules(); Thread.sleep(5000); assertEquals(3, list2.size()); }
( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession() .addEventListener(new TriggerRulesEventListener(ksession)); ( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession() .addEventListener(new TriggerRulesEventListener(ksession));
( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession() .addEventListener(new TriggerRulesEventListener(ksession)); ( (SingleSessionCommandService) ( (CommandBasedStatefulKnowledgeSession) ksession ).getRunner() ).getKieSession() .addEventListener(new TriggerRulesEventListener(ksession));