setUp(); Properties properties = new Properties(); properties.setProperty( "drools.commandService", PersistableRunner.class.getName() ); properties.setProperty( "drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName() ); properties.setProperty( "drools.workItemManagerFactory", JPASignalManagerFactory.class.getName() ); SessionConfiguration config = SessionConfiguration.newInstance( properties ); config.setOption( TimerJobFactoryOption.get(TimerJobFactoryType.JPA.getId()) ); InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); Collection<KiePackage> kpkgs = getProcessTimer2(); kbase.addPackages( kpkgs );
private void initProcessInstanceManager() { String processInstanceManagerClass = ((SessionConfiguration) kruntime.getSessionConfiguration()).getProcessInstanceManagerFactory(); try { processInstanceManager = ((ProcessInstanceManagerFactory) loadClass(processInstanceManagerClass).newInstance()) .createProcessInstanceManager(kruntime); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addPackages(Arrays.asList(builder.getPackages())); SessionConfiguration conf = SessionConfiguration.newInstance(); conf.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); session = kbase.newKieSession(conf, null); SessionPseudoClock clock = ( SessionPseudoClock) session.getSessionClock(); clock.advanceTime( 300, TimeUnit.MILLISECONDS ); session.setGlobal("myList", myList); ProcessInstance processInstance = ( ProcessInstance ) session.startProcess("org.drools.timer"); assertEquals(0, myList.size()); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
@Override public ProcessInstance startProcess(String processId) { if (session == null) { // load the process KieBase kbase = createKnowledgeBase(); // create a new session Properties properties = new Properties(); properties.put("drools.processInstanceManagerFactory", "org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory"); properties.put("drools.processSignalManagerFactory", "org.jbpm.process.instance.event.DefaultSignalManagerFactory"); SessionConfiguration config = SessionConfiguration.newInstance(properties); session = kbase.newKieSession(config, createEnvironment(context)); new JPAWorkingMemoryDbLogger(session); session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); } return session.startProcess(processId); }
StatefulKnowledgeSession result; if (conf == null) { conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); Properties defaultProps = new Properties(); defaultProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName()); defaultProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName()); conf = SessionConfiguration.newInstance(defaultProps); conf.setOption(ForceEagerActivationOption.YES); result = (StatefulKnowledgeSession) kbase.newKieSession(conf, env);
@Test public void testRegisterHandlerWithKsessionUsingConfiguration() { KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); Properties props = new Properties(); props.setProperty("drools.workItemHandlers", "CustomWorkItemHandlers.conf"); KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(props); KieSession ksession = kbase.newKieSession(config, EnvironmentFactory.newEnvironment()); assertNotNull(ksession); // this test would fail on creation of the work item manager if injecting session is not supported WorkItemManager manager = ksession.getWorkItemManager(); assertNotNull(manager); Map<String, WorkItemHandler> handlers = ((SessionConfiguration)config).getWorkItemHandlers(); assertNotNull(handlers); assertEquals(1, handlers.size()); assertTrue(handlers.containsKey("Custom")); }
private static KieSession createKnowledgeSession(String processFile) throws Exception { KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); KieFileSystem kfs = ks.newKieFileSystem(); if (processFile != null) { Resource process = ResourceFactory.newClassPathResource(processFile); kfs.write(process); } KieBuilder kb = ks.newKieBuilder(kfs); kb.buildAll(); if (kb.getResults().hasMessages(Level.ERROR)) { throw new RuntimeException("Build Errors:\n" + kb.getResults().toString()); } KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId()); KieBase kbase = kContainer.getKieBase(); Environment env = EnvironmentFactory.newEnvironment(); Properties defaultProps = new Properties(); defaultProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName()); defaultProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName()); SessionConfiguration conf = new SessionConfiguration(defaultProps); KieSession ksession = (StatefulKnowledgeSession) kbase.newKieSession(conf, env); return ksession; }
@Test public void testMergeConfig() { // JBRULES-3155 KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); Properties properties = new Properties(); properties.put("drools.processInstanceManagerFactory", "com.example.CustomInfinispanProcessInstanceManagerFactory"); KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties); StatefulKnowledgeSession ksession = InfinispanKnowledgeService.newStatefulKnowledgeSession( kbase, config, env ); SessionConfiguration sessionConfig = (SessionConfiguration)ksession.getSessionConfiguration(); assertEquals("com.example.CustomInfinispanProcessInstanceManagerFactory", sessionConfig.getProcessInstanceManagerFactory()); }
Properties properties = new Properties(); properties.put("drools.processInstanceManagerFactory", "com.example.CustomInfinispanProcessInstanceManagerFactory"); KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties); SessionConfiguration sessionConfig = (SessionConfiguration)ksession.getSessionConfiguration(); assertEquals("com.example.CustomInfinispanProcessInstanceManagerFactory", sessionConfig.getProcessInstanceManagerFactory());
KieSessionConfiguration ksc = SessionConfiguration.newInstance(); final KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( kbconf ); KieSession ks = kbase.newKieSession( ksc, env); ks.insert( entityOne ); ks.insert( entityTwo ); ksession2 = marshaller.unmarshall(bais, ks.getSessionConfiguration(), ks.getEnvironment()); Collection items = ksession2.getFactHandles(); Assert.assertTrue( items.size() == 2 );
KieSessionConfiguration ksc = SessionConfiguration.newInstance(); final KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( kbconf ); KieSession ks = kbase.newKieSession( ksc, env); ks.insert( entityOne ); ks.insert( entityTwo );
@Test @Ignore("This test is suspicious to say the least...") public void testScheduledActivation() { KnowledgeBaseImpl knowledgeBase = (KnowledgeBaseImpl) KnowledgeBaseFactory.newKnowledgeBase(); KnowledgePackageImpl impl = new KnowledgePackageImpl( "test" ); 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 ); ksession.insert( "cheese" ); assertTrue( fired.isEmpty() );
/** * This test can take a while (> 1 minute). * @throws Exception */ @Test @Ignore public void testStatefulSessionsCreation() throws Exception { KieBase kbase = loadKnowledgeBase("test_OutOfMemoryError.drl"); int i = 0; SessionConfiguration conf = SessionConfiguration.newInstance(); conf.setKeepReference( true ); // this is just for documentation purposes, since the default value is "true" try { for ( i = 0; i < 300000; i++ ) { KieSession ksession = kbase.newKieSession( conf, null ); ksession.dispose(); } } catch ( Throwable e ) { logger.info( "Error at: " + i ); e.printStackTrace(); fail( "Should not raise any error or exception." ); } }
@Override protected void internalAfterPropertiesSet() { if ( getConf() != null && getWorkItems() != null && !getWorkItems().isEmpty() ) { Map<String, WorkItemHandler> map = ((SessionConfiguration) getConf()).getWorkItemHandlers(); map.putAll( getWorkItems() ); ksession.execute( cmd ); ksession.addEventListener(agendaEventListener); ksession.addEventListener(processEventListener);
@Test public void testSingleExecutionJob() throws Exception { SessionConfiguration config = SessionConfiguration.newInstance(); config.setClockType(ClockType.REALTIME_CLOCK); TimerService timeService = TimerServiceFactory.getTimerService( config ); Trigger trigger = new DelayedTrigger( 100 ); HelloWorldJobContext ctx = new HelloWorldJobContext( "hello world", timeService); timeService.scheduleJob( new HelloWorldJob(), ctx, trigger); Thread.sleep( 500 ); timeService.shutdown(); assertEquals( 1, ctx.getList().size() ); }
public static StatefulKnowledgeSession deserializeKnowledgeSession(Marshaller marshaller, byte [] serializedKsession) throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream( serializedKsession ); StatefulKnowledgeSession deserializedKsession = (StatefulKnowledgeSession) marshaller.unmarshall( bais, SessionConfiguration.newInstance(), EnvironmentFactory.newEnvironment() ); bais.close(); return deserializedKsession; }
assertTrue( sconf.isKeepReference() ); assertEquals( ClockType.REALTIME_CLOCK, sconf.getClockType() ); Map<String, WorkItemHandler> wih = sconf.getWorkItemHandlers(); assertEquals( 4, wih.size() ); assertFalse( sconf.isKeepReference() ); assertEquals( ClockType.PSEUDO_CLOCK, sconf.getClockType() );
public DefaultKieSessionBean(KieServicesBean kieServices, KieContainerBean kieContainer, Properties droolsProperties) { log.info("Initialising session..."); KieSessionConfiguration conf; if (droolsProperties == null) { conf = SessionConfiguration.getDefaultInstance(); } else { conf = new SessionConfiguration(droolsProperties); } this.kieSession = kieContainer.newKieSession(conf); }
@Override protected void internalAfterPropertiesSet() { if ( getConf() != null && getWorkItems() != null && !getWorkItems().isEmpty() ) { Map<String, WorkItemHandler> map = ((SessionConfiguration) getConf()).getWorkItemHandlers(); map.putAll( getWorkItems() );
private KieSessionConfiguration mergeConfig(KieSessionConfiguration configuration) { return ((SessionConfiguration) configuration).addDefaultProperties(configProps); }