protected void addInterceptors(KieSession ksession) { PersistableRunner runner = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); runner.addInterceptor(new OptimisticLockRetryInterceptor()); // even though it's added always TransactionLockInterceptor is by default disabled so won't do anything runner.addInterceptor(new TransactionLockInterceptor(ksession.getEnvironment())); runner.addInterceptor(new ExecutionErrorHandlerInterceptor(ksession.getEnvironment())); }
public void addInterceptor(ChainableRunner interceptor) { addInterceptor(interceptor, true); }
protected void addInterceptors(KieSession ksession) { PersistableRunner runner = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); runner.addInterceptor(new OptimisticLockRetryInterceptor()); // even though it's added always TransactionLockInterceptor is by default disabled so won't do anything runner.addInterceptor(new TransactionLockInterceptor(ksession.getEnvironment())); runner.addInterceptor(new ExecutionErrorHandlerInterceptor(ksession.getEnvironment())); }
public StatefulKnowledgeSession loadKieSession(int id, KieBase kbase, KieSessionConfiguration configuration, Environment environment) { if ( configuration == null ) { configuration = SessionConfiguration.newInstance(); } if ( environment == null ) { throw new IllegalArgumentException( "Environment cannot be null" ); } CommandExecutor commandService = buildCommandService( new Long(id), kbase, mergeConfig( configuration ), environment ); if (commandService instanceof SingleSessionCommandService) { ((PersistableRunner) commandService).addInterceptor(new ManualPersistInterceptor((SingleSessionCommandService) commandService)); try { Class<?> clazz = Class.forName("org.jbpm.persistence.ManualPersistProcessInterceptor"); Constructor<?> c = clazz.getConstructor(PersistableRunner.class); ChainableRunner interceptor = (ChainableRunner) c.newInstance(commandService); ((PersistableRunner) commandService).addInterceptor(interceptor); } catch (ClassNotFoundException e) { //Expected of non-jbpm based projects } catch (Exception e) { //something unexpected happened throw new RuntimeException("Something wrong initializing manual process persistor interceptor", e); } } return new CommandBasedStatefulKnowledgeSession( (ExecutableRunner) commandService ); }
public StatefulKnowledgeSession newKieSession(KieBase kbase, KieSessionConfiguration configuration, Environment environment) { if ( configuration == null ) { configuration = SessionConfiguration.newInstance(); } if ( environment == null ) { throw new IllegalArgumentException( "Environment cannot be null" ); } CommandExecutor commandService = buildCommandService( kbase, mergeConfig( configuration ), environment ); if (commandService instanceof SingleSessionCommandService) { ((PersistableRunner) commandService).addInterceptor(new ManualPersistInterceptor((SingleSessionCommandService) commandService)); try { Class<?> clazz = Class.forName("org.jbpm.persistence.ManualPersistProcessInterceptor"); Constructor<?> c = clazz.getConstructor(SingleSessionCommandService.class); ChainableRunner interceptor = (ChainableRunner) c.newInstance( commandService ); ((PersistableRunner) commandService).addInterceptor((ChainableRunner) interceptor ); } catch (ClassNotFoundException e) { //Expected of non-jbpm based projects } catch (Exception e) { //something unexpected happened throw new RuntimeException("Something wrong initializing manual process persistor interceptor", e); } } return new CommandBasedStatefulKnowledgeSession( (ExecutableRunner) commandService ); }
public StatefulKnowledgeSession loadKieSession(Long id, KieBase kbase, KieSessionConfiguration configuration, Environment environment) { if ( configuration == null ) { configuration = SessionConfiguration.newInstance(); } if ( environment == null ) { throw new IllegalArgumentException( "Environment cannot be null" ); } CommandExecutor commandService = buildCommandService( id, kbase, mergeConfig( configuration ), environment ); if (commandService instanceof SingleSessionCommandService) { ((PersistableRunner) commandService).addInterceptor(new ManualPersistInterceptor((SingleSessionCommandService) commandService)); try { Class<?> clazz = Class.forName("org.jbpm.persistence.ManualPersistProcessInterceptor"); Constructor<?> c = clazz.getConstructor(SingleSessionCommandService.class); ChainableRunner interceptor = (ChainableRunner) c.newInstance(commandService); ((PersistableRunner) commandService).addInterceptor(interceptor); } catch (ClassNotFoundException e) { //Expected of non-jbpm based projects } catch (Exception e) { //something unexpected happened throw new RuntimeException("Something wrong initializing manual process persistor interceptor", e); } } return new CommandBasedStatefulKnowledgeSession( (ExecutableRunner) commandService ); }
sscs.addInterceptor(new LoggingInterceptor()); sscs.addInterceptor(new FireAllRulesInterceptor()); sscs.addInterceptor(new LoggingInterceptor()); List<?> list = new ArrayList<Object>(); ksession.setGlobal( "list", list );
addInterceptor(iterator.next(), false);
@Test public void testInterceptor() { String str = ""; str += "package org.kie.test\n"; str += "global java.util.List list\n"; str += "rule rule1\n"; str += "when\n"; str += " Integer(intValue > 0)\n"; str += "then\n"; str += " list.add( 1 );\n"; str += " System.out.println(\"ADDED\");\n"; str += "end\n"; str += "\n"; KieServices ks = KieServices.Factory.get(); KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/r1.drl", str ); ks.newKieBuilder( kfs ).buildAll(); KieBase kbase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase(); KieSession ksession = InfinispanKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); PersistableRunner sscs = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); sscs.addInterceptor(new LoggingInterceptor()); sscs.addInterceptor(new FireAllRulesInterceptor()); sscs.addInterceptor(new LoggingInterceptor()); List<?> list = new ArrayList<Object>(); ksession.setGlobal( "list", list ); ksession.insert( 1 ); ksession.insert( 2 ); ksession.insert( 3 ); ksession.getWorkItemManager().completeWorkItem(0, null); assertEquals( 3, list.size() ); }