@Override protected StatefulKnowledgeSession createSession(KieBase kbase) { EnvironmentBuilder envBuilder = new ProcessStorageEnvironmentBuilder( storage ); Environment env = KieServices.get().newEnvironment(); env.set( EnvironmentName.TRANSACTION_MANAGER, envBuilder.getTransactionManager() ); env.set( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, envBuilder.getPersistenceContextManager() ); return JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); }
@Override protected StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSession ksession, long ksessionId, KieBase kbase) { ksession.dispose(); EnvironmentBuilder envBuilder = new ProcessStorageEnvironmentBuilder( storage ); Environment env = KieServices.get().newEnvironment(); env.set( EnvironmentName.TRANSACTION_MANAGER, envBuilder.getTransactionManager() ); env.set( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, envBuilder.getPersistenceContextManager() ); return JPAKnowledgeService.loadStatefulKnowledgeSession( ksessionId, kbase, null, env ); }
private void readWrite(KieBase knowledgeBase, KieSession ksession, KieSessionConfiguration config) { try { Marshaller marshaller = MarshallerFactory.newMarshaller( knowledgeBase ); ByteArrayOutputStream o = new ByteArrayOutputStream(); marshaller.marshall( o, ksession ); ksession = marshaller.unmarshall( new ByteArrayInputStream( o.toByteArray() ), config, KieServices.get().newEnvironment() ); ksession.fireAllRules(); //scheduler = ksession.<SessionClock>getSessionClock(); } catch ( Exception e ) { throw new RuntimeException( e ); } }
@Override public Environment newEnvironment() { return kieServices.newEnvironment(); }
SessionConfiguration config = SessionConfiguration.newInstance(); config.setClockType( ClockType.PSEUDO_CLOCK ); KieSession ksession = knowledgeBase.newKieSession( config, KieServices.get().newEnvironment() ); PseudoClockScheduler scheduler = (PseudoClockScheduler) ksession.<SessionClock> getSessionClock(); Marshaller marshaller = MarshallerFactory.newMarshaller( knowledgeBase );
private Environment mergeEnvironment(Environment env) { if (env == null) { env = KieServices.get().newEnvironment(); } if (env.get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER) == null) { try { Class<?> clazz = Class.forName("org.jbpm.persistence.InfinispanProcessPersistenceContextManager"); Constructor<?> c = clazz.getConstructor(Environment.class); env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, c.newInstance(env)); } catch (ClassNotFoundException e) { env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, new InfinispanPersistenceContextManager(env)); } catch (Exception e) { e.printStackTrace(); env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, new InfinispanPersistenceContextManager(env)); } } Object tm = env.get(EnvironmentName.TRANSACTION_MANAGER); if (tm instanceof javax.transaction.TransactionManager) { Object ut = env.get(EnvironmentName.TRANSACTION); if (ut == null && tm instanceof javax.transaction.UserTransaction) { env.set(EnvironmentName.TRANSACTION, tm); } env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerFactory.get().newTransactionManager(env)); } return env; }
@Test public void testPersistenceTimer2() throws Exception { KieBase kBase = (KieBase) ctx.getBean("kb_persistence"); //KieSession service = kBase.newKieSession();//(KieSession) ctx.getBean("jpaSingleSessionCommandService"); KieSession service = (KieSession) ctx.getBean("jpaSingleSessionCommandService"); long sessionId = service.getIdentifier(); ProcessInstance processInstance = service.startProcess("org.drools.test.ProcessTimer2"); log.debug("Started process instance {}", processInstance.getId()); waitForTimer(); // wait for timer process to complete Thread.sleep(500); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf")); env.set(EnvironmentName.TRANSACTION_MANAGER, ctx.getBean("txManager")); KieStoreServices kstore = (KieStoreServices) ctx.getBean("kstore1"); KieBase kbase1 = (KieBase) ctx.getBean("kb_persistence"); service = kstore.loadKieSession(sessionId, kbase1, null, env); processInstance = service.getProcessInstance(processInstance.getId()); assertNull(processInstance); }
log.debug("---> session disposed"); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf")); env.set(EnvironmentName.TRANSACTION_MANAGER, ctx.getBean("txManager"));
@Test public void testPersistenceTimer2() throws Exception { KieBase kBase = (KieBase) ctx.getBean("kb_persistence"); //KieSession service = kBase.newKieSession();//(KieSession) ctx.getBean("jpaSingleSessionCommandService"); KieSession service = (KieSession) ctx.getBean("jpaSingleSessionCommandService"); long sessionId = service.getIdentifier(); ProcessInstance processInstance = service.startProcess("org.drools.test.ProcessTimer2"); log.debug("Started process instance {}", processInstance.getId()); waitForTimer(); // wait for timer process to complete Thread.sleep(500); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf")); env.set(EnvironmentName.TRANSACTION_MANAGER, ctx.getBean("txManager")); KieStoreServices kstore = (KieStoreServices) ctx.getBean("kstore1"); KieBase kbase1 = (KieBase) ctx.getBean("kb_persistence"); service = kstore.loadKieSession(sessionId, kbase1, null, env); processInstance = service.getProcessInstance(processInstance.getId()); assertNull(processInstance); }
log.debug("---> session disposed"); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf")); env.set(EnvironmentName.TRANSACTION_MANAGER, ctx.getBean("txManager"));
private Environment getEnvironment() { Environment environment = KieServices.get().newEnvironment(); environment.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf); environment.set(EnvironmentName.TRANSACTION_MANAGER, txm); environment.set(EnvironmentName.GLOBALS, new MapGlobalResolver()); return environment; }
private Environment getEnvironment() { Environment environment = KieServices.get().newEnvironment(); environment.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf); environment.set(EnvironmentName.TRANSACTION_MANAGER, txm); environment.set(EnvironmentName.GLOBALS, new MapGlobalResolver()); return environment; }
@Test public void testSimulationCommand() { PathFinder finder = PathFinderFactory.getInstance(this.getClass().getResourceAsStream("/BPMN2-ExclusiveSplit.bpmn2")); List<SimulationPath> paths = finder.findPaths(new SimulationFilterPathFormatConverter()); SimulationContext context = SimulationContextFactory.newContext(new HardCodedSimulationDataProvider()); KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(); builder.add(ResourceFactory.newClassPathResource("BPMN2-ExclusiveSplit.bpmn2"), ResourceType.BPMN2); KieBase kbase = builder.newKieBase(); KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); config.setOption(ClockTypeOption.get("pseudo") ); for (SimulationPath sp : paths) { KieSession session = kbase.newKieSession(config, KieServices.get().newEnvironment()); ((SessionPseudoClock) session.getSessionClock()).advanceTime(System.currentTimeMillis(), TimeUnit.MILLISECONDS); session.execute(new SimulateProcessPathCommand("com.sample.test", context, sp)); } } }
@Test public void testSimulationCommand() { PathFinder finder = PathFinderFactory.getInstance(this.getClass().getResourceAsStream("/BPMN2-ExclusiveSplit.bpmn2")); List<SimulationPath> paths = finder.findPaths(new SimulationFilterPathFormatConverter()); SimulationContext context = SimulationContextFactory.newContext(new HardCodedSimulationDataProvider()); KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(); builder.add(ResourceFactory.newClassPathResource("BPMN2-ExclusiveSplit.bpmn2"), ResourceType.BPMN2); KieBase kbase = builder.newKieBase(); KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); config.setOption(ClockTypeOption.get("pseudo") ); for (SimulationPath sp : paths) { KieSession session = kbase.newKieSession(config, KieServices.get().newEnvironment()); ((SessionPseudoClock) session.getSessionClock()).advanceTime(System.currentTimeMillis(), TimeUnit.MILLISECONDS); session.execute(new SimulateProcessPathCommand("com.sample.test", context, sp)); } } }
service.dispose(); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf"));
service.dispose(); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf"));
service.dispose(); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf"));
service.dispose(); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf"));
service.dispose(); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf")); env.set(EnvironmentName.TRANSACTION_MANAGER, ctx.getBean("txManager"));
service.dispose(); Environment env = KieServices.get().newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, ctx.getBean("myEmf")); env.set(EnvironmentName.TRANSACTION_MANAGER, ctx.getBean("txManager"));