[jboss-svn-commits] JBL Code SVN: r24744 - in labs/jbossrules/trunk: drools-core/src/main/java/org/drools and 9 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jan 15 19:19:21 EST 2009
Author: KrisVerlaenen
Date: 2009-01-15 19:19:21 -0500 (Thu, 15 Jan 2009)
New Revision: 24744
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java
labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.session.conf
Removed:
labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/CommandBasedStatefulKnowledgeSession.java
labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.rulebase.conf
Modified:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseFactory.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseProvider.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SessionConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseProviderImpl.java
labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/drools.default.rulebase.conf
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java
labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/JPAPersisterManager.java
labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/SingleSessionCommandService.java
labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/resources/META-INF/persistence.xml
labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/java/org/drools/persistence/session/PersistentStatefulSessionTest.java
labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/java/org/drools/persistence/session/SingleSessionCommandServiceTest.java
Log:
JBRULES-1915: Improve process persistence usability
- improved command-based implementation of StatefulKnowledgeSession
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseFactory.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseFactory.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -2,6 +2,8 @@
import java.util.Properties;
+import org.drools.runtime.KnowledgeSessionConfiguration;
+
/**
* <p>
* This factory will create and return a KnowledgeBase instance, an optional KnowledgeBaseConfiguration
@@ -65,6 +67,24 @@
classLoader );
}
+ /**
+ * Create a KnowledgeSessionConfiguration on which properties can be set.
+ * @return
+ * The KnowledgeSessionConfiguration.
+ */
+ public static KnowledgeSessionConfiguration newKnowledgeSessionConfiguration() {
+ return getKnowledgeBaseProvider().newKnowledgeSessionConfiguration();
+ }
+
+ /**
+ * Create a KnowledgeSessionConfiguration on which properties can be set.
+ * @return
+ * The KnowledgeSessionConfiguration.
+ */
+ public static KnowledgeSessionConfiguration newKnowledgeSessionConfiguration(Properties properties) {
+ return getKnowledgeBaseProvider().newKnowledgeSessionConfiguration( properties );
+ }
+
private static synchronized void setKnowledgeBaseProvider(KnowledgeBaseProvider provider) {
KnowledgeBaseFactory.provider = provider;
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseProvider.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseProvider.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -2,6 +2,8 @@
import java.util.Properties;
+import org.drools.runtime.KnowledgeSessionConfiguration;
+
/**
* KnowledgeBaseProvider is used by the KnowledgeBaseFacotry to "provide" it's concrete implementation.
*
@@ -33,6 +35,26 @@
ClassLoader classLoader);
/**
+ * Instantiate and return a new KnowledgeSessionConfiguration
+ *
+ * @return
+ * the KnowledgeSessionConfiguration
+ */
+ public KnowledgeSessionConfiguration newKnowledgeSessionConfiguration();
+
+ /**
+ * Instantiate and return a new KnowledgeSessionConfiguration
+ *
+ * @param properties
+ * Properties file to process, can be null;
+ * @param classLoader
+ * Provided ClassLoader, can be null and then ClassLoader defaults to Thread.currentThread().getContextClassLoader()
+ * @return
+ * The KnowledgeSessionConfiguration
+ */
+ public KnowledgeSessionConfiguration newKnowledgeSessionConfiguration(Properties properties);
+
+ /**
* Instantiate and return a KnowledgeBase using a default KnowledgeBaseConfiguration
*
* @return
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -128,17 +128,12 @@
private ConflictResolver conflictResolver;
- private static final String STAR = "*";
private ContextInstanceFactoryRegistry processContextInstanceFactoryRegistry;
private Map<String, WorkDefinition> workDefinitions;
- private Map<String, WorkItemHandler> workItemHandlers;
private boolean advancedProcessRuleIntegration;
private ProcessInstanceFactoryRegistry processInstanceFactoryRegistry;
private NodeInstanceFactoryRegistry processNodeInstanceFactoryRegistry;
- private ProcessInstanceManagerFactory processInstanceManagerFactory;
- private SignalManagerFactory processSignalManagerFactory;
- private WorkItemManagerFactory workItemManagerFactory;
private transient ClassLoader classLoader;
@@ -830,48 +825,6 @@
}
}
- public Map<String, WorkItemHandler> getWorkItemHandlers() {
- if ( this.workItemHandlers == null ) {
- initWorkItemHandlers();
- }
- return this.workItemHandlers;
-
- }
-
- private void initWorkItemHandlers() {
- this.workItemHandlers = new HashMap<String, WorkItemHandler>();
-
- // split on each space
- String locations[] = this.chainedProperties.getProperty( "drools.workItemHandlers",
- "" ).split( "\\s" );
-
- // load each SemanticModule
- for ( String factoryLocation : locations ) {
- // trim leading/trailing spaces and quotes
- factoryLocation = factoryLocation.trim();
- if ( factoryLocation.startsWith( "\"" ) ) {
- factoryLocation = factoryLocation.substring( 1 );
- }
- if ( factoryLocation.endsWith( "\"" ) ) {
- factoryLocation = factoryLocation.substring( 0,
- factoryLocation.length() - 1 );
- }
- if ( !factoryLocation.equals( "" ) ) {
- loadWorkItemHandlers( factoryLocation );
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private void loadWorkItemHandlers(String location) {
- String content = ConfFileUtils.URLContentsToString( ConfFileUtils.getURL( location,
- null,
- RuleBaseConfiguration.class ) );
- Map<String, WorkItemHandler> workItemHandlers = (Map<String, WorkItemHandler>) MVEL.eval( content,
- new HashMap() );
- this.workItemHandlers.putAll( workItemHandlers );
- }
-
public ContextInstanceFactoryRegistry getProcessContextInstanceFactoryRegistry() {
if ( this.processContextInstanceFactoryRegistry == null ) {
initProcessContextInstanceFactoryRegistry();
@@ -921,112 +874,6 @@
}
}
- public ProcessInstanceManagerFactory getProcessInstanceManagerFactory() {
- if ( this.processInstanceManagerFactory == null ) {
- initProcessInstanceManagerFactory();
- }
- return this.processInstanceManagerFactory;
- }
-
- @SuppressWarnings("unchecked")
- private void initProcessInstanceManagerFactory() {
- String className = this.chainedProperties.getProperty( "processInstanceManagerFactory",
- "org.drools.process.instance.impl.DefaultProcessInstanceManagerFactory" );
- Class<ProcessInstanceManagerFactory> clazz = null;
- try {
- clazz = (Class<ProcessInstanceManagerFactory>) Thread.currentThread().getContextClassLoader().loadClass( className );
- } catch ( ClassNotFoundException e ) {
- }
-
- if ( clazz == null ) {
- try {
- clazz = (Class<ProcessInstanceManagerFactory>) RuleBaseConfiguration.class.getClassLoader().loadClass( className );
- } catch ( ClassNotFoundException e ) {
- }
- }
-
- if ( clazz != null ) {
- try {
- this.processInstanceManagerFactory = clazz.newInstance();
- } catch ( Exception e ) {
- throw new IllegalArgumentException( "Unable to instantiate process instance manager factory '" + className + "'" );
- }
- } else {
- throw new IllegalArgumentException( "Process instance manager factory '" + className + "' not found" );
- }
- }
-
- public SignalManagerFactory getSignalManagerFactory() {
- if ( this.processSignalManagerFactory == null ) {
- initSignalManagerFactory();
- }
- return this.processSignalManagerFactory;
- }
-
- @SuppressWarnings("unchecked")
- private void initSignalManagerFactory() {
- String className = this.chainedProperties.getProperty( "processSignalManagerFactory",
- "org.drools.process.instance.event.DefaultSignalManagerFactory" );
- Class<SignalManagerFactory> clazz = null;
- try {
- clazz = (Class<SignalManagerFactory>) Thread.currentThread().getContextClassLoader().loadClass( className );
- } catch ( ClassNotFoundException e ) {
- }
-
- if ( clazz == null ) {
- try {
- clazz = (Class<SignalManagerFactory>) RuleBaseConfiguration.class.getClassLoader().loadClass( className );
- } catch ( ClassNotFoundException e ) {
- }
- }
-
- if ( clazz != null ) {
- try {
- this.processSignalManagerFactory = clazz.newInstance();
- } catch ( Exception e ) {
- throw new IllegalArgumentException( "Unable to instantiate signal manager factory '" + className + "'" );
- }
- } else {
- throw new IllegalArgumentException( "Signal manager factory '" + className + "' not found" );
- }
- }
-
- public WorkItemManagerFactory getWorkItemManagerFactory() {
- if ( this.workItemManagerFactory == null ) {
- initWorkItemManagerFactory();
- }
- return this.workItemManagerFactory;
- }
-
- @SuppressWarnings("unchecked")
- private void initWorkItemManagerFactory() {
- String className = this.chainedProperties.getProperty( "workItemManagerFactory",
- "org.drools.process.instance.impl.DefaultWorkItemManagerFactory" );
- Class<WorkItemManagerFactory> clazz = null;
- try {
- clazz = (Class<WorkItemManagerFactory>) Thread.currentThread().getContextClassLoader().loadClass( className );
- } catch ( ClassNotFoundException e ) {
- }
-
- if ( clazz == null ) {
- try {
- clazz = (Class<WorkItemManagerFactory>) RuleBaseConfiguration.class.getClassLoader().loadClass( className );
- } catch ( ClassNotFoundException e ) {
- }
- }
-
- if ( clazz != null ) {
- try {
- this.workItemManagerFactory = clazz.newInstance();
- } catch ( Exception e ) {
- throw new IllegalArgumentException( "Unable to instantiate work item manager factory '" + className + "'",
- e );
- }
- } else {
- throw new IllegalArgumentException( "Work item manager factory '" + className + "' not found" );
- }
- }
-
public boolean isAdvancedProcessRuleIntegration() {
return advancedProcessRuleIntegration;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SessionConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SessionConfiguration.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SessionConfiguration.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -20,11 +20,20 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
+import org.drools.process.command.CommandService;
+import org.drools.process.instance.ProcessInstanceManagerFactory;
+import org.drools.process.instance.WorkItemManagerFactory;
+import org.drools.process.instance.event.SignalManagerFactory;
import org.drools.runtime.KnowledgeSessionConfiguration;
+import org.drools.runtime.process.WorkItemHandler;
import org.drools.util.ChainedProperties;
+import org.drools.util.ConfFileUtils;
import org.drools.util.StringUtils;
+import org.mvel2.MVEL;
/**
* SessionConfiguration
@@ -58,6 +67,12 @@
private ClockType clockType;
+ private Map<String, WorkItemHandler> workItemHandlers;
+ private ProcessInstanceManagerFactory processInstanceManagerFactory;
+ private SignalManagerFactory processSignalManagerFactory;
+ private WorkItemManagerFactory workItemManagerFactory;
+ private CommandService commandService;
+
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( chainedProperties );
out.writeBoolean( immutable );
@@ -91,7 +106,7 @@
private void init(Properties properties) {
this.immutable = false;
- this.chainedProperties = new ChainedProperties( "rulebase.conf" );
+ this.chainedProperties = new ChainedProperties( "session.conf" );
if ( properties != null ) {
this.chainedProperties.addProperties( properties );
@@ -174,4 +189,190 @@
this.clockType = clockType;
}
+ public Map<String, WorkItemHandler> getWorkItemHandlers() {
+ if ( this.workItemHandlers == null ) {
+ initWorkItemHandlers();
+ }
+ return this.workItemHandlers;
+
+ }
+
+ private void initWorkItemHandlers() {
+ this.workItemHandlers = new HashMap<String, WorkItemHandler>();
+
+ // split on each space
+ String locations[] = this.chainedProperties.getProperty( "drools.workItemHandlers",
+ "" ).split( "\\s" );
+
+ // load each SemanticModule
+ for ( String factoryLocation : locations ) {
+ // trim leading/trailing spaces and quotes
+ factoryLocation = factoryLocation.trim();
+ if ( factoryLocation.startsWith( "\"" ) ) {
+ factoryLocation = factoryLocation.substring( 1 );
+ }
+ if ( factoryLocation.endsWith( "\"" ) ) {
+ factoryLocation = factoryLocation.substring( 0,
+ factoryLocation.length() - 1 );
+ }
+ if ( !factoryLocation.equals( "" ) ) {
+ loadWorkItemHandlers( factoryLocation );
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void loadWorkItemHandlers(String location) {
+ String content = ConfFileUtils.URLContentsToString( ConfFileUtils.getURL( location,
+ null,
+ RuleBaseConfiguration.class ) );
+ Map<String, WorkItemHandler> workItemHandlers = (Map<String, WorkItemHandler>) MVEL.eval( content,
+ new HashMap() );
+ this.workItemHandlers.putAll( workItemHandlers );
+ }
+
+ public ProcessInstanceManagerFactory getProcessInstanceManagerFactory() {
+ if ( this.processInstanceManagerFactory == null ) {
+ initProcessInstanceManagerFactory();
+ }
+ return this.processInstanceManagerFactory;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initProcessInstanceManagerFactory() {
+ String className = this.chainedProperties.getProperty( "drools.processInstanceManagerFactory",
+ "org.drools.process.instance.impl.DefaultProcessInstanceManagerFactory" );
+ Class<ProcessInstanceManagerFactory> clazz = null;
+ try {
+ clazz = (Class<ProcessInstanceManagerFactory>) Thread.currentThread().getContextClassLoader().loadClass( className );
+ } catch ( ClassNotFoundException e ) {
+ }
+
+ if ( clazz == null ) {
+ try {
+ clazz = (Class<ProcessInstanceManagerFactory>) SessionConfiguration.class.getClassLoader().loadClass( className );
+ } catch ( ClassNotFoundException e ) {
+ }
+ }
+
+ if ( clazz != null ) {
+ try {
+ this.processInstanceManagerFactory = clazz.newInstance();
+ } catch ( Exception e ) {
+ throw new IllegalArgumentException( "Unable to instantiate process instance manager factory '" + className + "'" );
+ }
+ } else {
+ throw new IllegalArgumentException( "Process instance manager factory '" + className + "' not found" );
+ }
+ }
+
+ public SignalManagerFactory getSignalManagerFactory() {
+ if ( this.processSignalManagerFactory == null ) {
+ initSignalManagerFactory();
+ }
+ return this.processSignalManagerFactory;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initSignalManagerFactory() {
+ String className = this.chainedProperties.getProperty( "drools.processSignalManagerFactory",
+ "org.drools.process.instance.event.DefaultSignalManagerFactory" );
+ Class<SignalManagerFactory> clazz = null;
+ try {
+ clazz = (Class<SignalManagerFactory>) Thread.currentThread().getContextClassLoader().loadClass( className );
+ } catch ( ClassNotFoundException e ) {
+ }
+
+ if ( clazz == null ) {
+ try {
+ clazz = (Class<SignalManagerFactory>) SessionConfiguration.class.getClassLoader().loadClass( className );
+ } catch ( ClassNotFoundException e ) {
+ }
+ }
+
+ if ( clazz != null ) {
+ try {
+ this.processSignalManagerFactory = clazz.newInstance();
+ } catch ( Exception e ) {
+ throw new IllegalArgumentException( "Unable to instantiate signal manager factory '" + className + "'" );
+ }
+ } else {
+ throw new IllegalArgumentException( "Signal manager factory '" + className + "' not found" );
+ }
+ }
+
+ public WorkItemManagerFactory getWorkItemManagerFactory() {
+ if ( this.workItemManagerFactory == null ) {
+ initWorkItemManagerFactory();
+ }
+ return this.workItemManagerFactory;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initWorkItemManagerFactory() {
+ String className = this.chainedProperties.getProperty( "drools.workItemManagerFactory",
+ "org.drools.process.instance.impl.DefaultWorkItemManagerFactory" );
+ Class<WorkItemManagerFactory> clazz = null;
+ try {
+ clazz = (Class<WorkItemManagerFactory>) Thread.currentThread().getContextClassLoader().loadClass( className );
+ } catch ( ClassNotFoundException e ) {
+ }
+
+ if ( clazz == null ) {
+ try {
+ clazz = (Class<WorkItemManagerFactory>) SessionConfiguration.class.getClassLoader().loadClass( className );
+ } catch ( ClassNotFoundException e ) {
+ }
+ }
+
+ if ( clazz != null ) {
+ try {
+ this.workItemManagerFactory = clazz.newInstance();
+ } catch ( Exception e ) {
+ throw new IllegalArgumentException( "Unable to instantiate work item manager factory '" + className + "'",
+ e );
+ }
+ } else {
+ throw new IllegalArgumentException( "Work item manager factory '" + className + "' not found" );
+ }
+ }
+
+ public CommandService getCommandService(RuleBase ruleBase) {
+ if ( this.commandService == null ) {
+ initCommandService(ruleBase);
+ }
+ return this.commandService;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initCommandService(RuleBase ruleBase) {
+ String className = this.chainedProperties.getProperty( "drools.commandService", null );
+ if (className == null) {
+ return;
+ }
+
+ Class<CommandService> clazz = null;
+ try {
+ clazz = (Class<CommandService>) Thread.currentThread().getContextClassLoader().loadClass( className );
+ } catch ( ClassNotFoundException e ) {
+ }
+
+ if ( clazz == null ) {
+ try {
+ clazz = (Class<CommandService>) SessionConfiguration.class.getClassLoader().loadClass( className );
+ } catch ( ClassNotFoundException e ) {
+ }
+ }
+
+ if ( clazz != null ) {
+ try {
+ this.commandService = clazz.getConstructor(RuleBase.class, SessionConfiguration.class).newInstance(ruleBase, this);
+ } catch ( Exception e ) {
+ throw new IllegalArgumentException( "Unable to instantiate work item manager factory '" + className + "'",
+ e );
+ }
+ } else {
+ throw new IllegalArgumentException( "Command service '" + className + "' not found" );
+ }
+ }
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -269,13 +269,13 @@
this.__ruleBaseEventListeners = new LinkedList();
this.lock = new ReentrantLock();
this.liaPropagations = Collections.EMPTY_LIST;
- this.processInstanceManager = conf.getProcessInstanceManagerFactory().createProcessInstanceManager( this );
+ this.processInstanceManager = config.getProcessInstanceManagerFactory().createProcessInstanceManager( this );
this.timeMachine = new TimeMachine();
TimerService timerService = TimerServiceFactory.getTimerService( this.config.getClockType() );
this.timerManager = new TimerManager( this,
timerService );
- this.signalManager = conf.getSignalManagerFactory().createSignalManager( this );
+ this.signalManager = config.getSignalManagerFactory().createSignalManager( this );
this.nodeMemories = new ConcurrentNodeMemories( this.ruleBase );
@@ -1581,8 +1581,8 @@
public WorkItemManager getWorkItemManager() {
if ( workItemManager == null ) {
- workItemManager = ruleBase.getConfiguration().getWorkItemManagerFactory().createWorkItemManager( this );
- Map<String, WorkItemHandler> workItemHandlers = ((InternalRuleBase) getRuleBase()).getConfiguration().getWorkItemHandlers();
+ workItemManager = config.getWorkItemManagerFactory().createWorkItemManager( this );
+ Map<String, WorkItemHandler> workItemHandlers = config.getWorkItemHandlers();
if ( workItemHandlers != null ) {
for ( Map.Entry<String, WorkItemHandler> entry : workItemHandlers.entrySet() ) {
workItemManager.registerWorkItemHandler( entry.getKey(),
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseImpl.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseImpl.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -47,6 +47,8 @@
import org.drools.event.knowlegebase.impl.BeforeKnowledgePackageRemovedEventImpl;
import org.drools.event.knowlegebase.impl.BeforeRuleAddedEventImpl;
import org.drools.event.knowlegebase.impl.BeforeRuleRemovedEventImpl;
+import org.drools.process.command.CommandService;
+import org.drools.process.command.impl.CommandBasedStatefulKnowledgeSession;
import org.drools.reteoo.ReteooRuleBase;
import org.drools.reteoo.ReteooStatefulSession;
import org.drools.rule.Package;
@@ -125,15 +127,17 @@
}
public StatefulKnowledgeSession newStatefulKnowledgeSession() {
- ReteooStatefulSession session = (ReteooStatefulSession) this.ruleBase.newStatefulSession();
- return new StatefulKnowledgeSessionImpl( session,
- this );
+ return newStatefulKnowledgeSession(new SessionConfiguration());
}
- public StatefulKnowledgeSession newStatefulKnowledgeSession(KnowledgeSessionConfiguration conf) {
- ReteooStatefulSession session = (ReteooStatefulSession) this.ruleBase.newStatefulSession( (SessionConfiguration) conf );
- return new StatefulKnowledgeSessionImpl( session,
- this );
+ public StatefulKnowledgeSession newStatefulKnowledgeSession(KnowledgeSessionConfiguration conf) {
+ CommandService commandService = ((SessionConfiguration) conf).getCommandService(this.ruleBase);
+ if (commandService != null) {
+ return new CommandBasedStatefulKnowledgeSession(commandService);
+ } else {
+ ReteooStatefulSession session = (ReteooStatefulSession) this.ruleBase.newStatefulSession( (SessionConfiguration) conf );
+ return new StatefulKnowledgeSessionImpl( session, this );
+ }
}
public StatelessKnowledgeSession newStatelessKnowledgeSession() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseProviderImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseProviderImpl.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseProviderImpl.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -7,6 +7,8 @@
import org.drools.KnowledgeBaseProvider;
import org.drools.RuleBaseConfiguration;
import org.drools.RuleBaseFactory;
+import org.drools.SessionConfiguration;
+import org.drools.runtime.KnowledgeSessionConfiguration;
public class KnowledgeBaseProviderImpl implements KnowledgeBaseProvider {
@@ -18,6 +20,14 @@
return new RuleBaseConfiguration(classLoader, properties);
}
+ public KnowledgeSessionConfiguration newKnowledgeSessionConfiguration() {
+ return new SessionConfiguration();
+ }
+
+ public KnowledgeSessionConfiguration newKnowledgeSessionConfiguration(Properties properties) {
+ return new SessionConfiguration(properties);
+ }
+
public KnowledgeBase newKnowledgeBase() {
return new KnowledgeBaseImpl( RuleBaseFactory.newRuleBase() );
}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -0,0 +1,225 @@
+package org.drools.process.command.impl;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.drools.KnowledgeBase;
+import org.drools.event.process.ProcessEventListener;
+import org.drools.event.rule.AgendaEventListener;
+import org.drools.event.rule.WorkingMemoryEventListener;
+import org.drools.process.command.AbortWorkItemCommand;
+import org.drools.process.command.CommandService;
+import org.drools.process.command.CompleteWorkItemCommand;
+import org.drools.process.command.GetProcessInstanceCommand;
+import org.drools.process.command.SignalEventCommand;
+import org.drools.process.command.StartProcessCommand;
+import org.drools.runtime.ExitPoint;
+import org.drools.runtime.GlobalResolver;
+import org.drools.runtime.ObjectFilter;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.process.ProcessInstance;
+import org.drools.runtime.process.WorkItemHandler;
+import org.drools.runtime.process.WorkItemManager;
+import org.drools.runtime.rule.Agenda;
+import org.drools.runtime.rule.AgendaFilter;
+import org.drools.runtime.rule.FactHandle;
+import org.drools.runtime.rule.WorkingMemoryEntryPoint;
+import org.drools.time.SessionClock;
+
+public class CommandBasedStatefulKnowledgeSession implements StatefulKnowledgeSession {
+
+ private CommandService commandService;
+ private transient WorkItemManager workItemManager;
+
+ public CommandBasedStatefulKnowledgeSession(CommandService commandService) {
+ this.commandService = commandService;
+ }
+
+ public ProcessInstance getProcessInstance(long id) {
+ GetProcessInstanceCommand command = new GetProcessInstanceCommand();
+ command.setProcessInstanceId(id);
+ return commandService.execute(command);
+ }
+
+ public Collection<ProcessInstance> getProcessInstances() {
+ throw new UnsupportedOperationException();
+ }
+
+ public WorkItemManager getWorkItemManager() {
+ if (workItemManager == null) {
+ workItemManager = new WorkItemManager() {
+ public void completeWorkItem(long id, Map<String, Object> results) {
+ CompleteWorkItemCommand command = new CompleteWorkItemCommand();
+ command.setWorkItemId(id);
+ command.setResults(results);
+ commandService.execute(command);
+ }
+ public void abortWorkItem(long id) {
+ AbortWorkItemCommand command = new AbortWorkItemCommand();
+ command.setWorkItemId(id);
+ commandService.execute(command);
+ }
+ public void registerWorkItemHandler(String workItemName, WorkItemHandler handler) {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+ return workItemManager;
+ }
+
+ public void signalEvent(String type, Object event) {
+ SignalEventCommand command = new SignalEventCommand();
+ command.setEventType(type);
+ command.setEvent(event);
+ commandService.execute(command);
+ }
+
+ public ProcessInstance startProcess(String processId) {
+ return startProcess(processId, null);
+ }
+
+ public ProcessInstance startProcess(String processId,
+ Map<String, Object> parameters) {
+ StartProcessCommand command = new StartProcessCommand();
+ command.setProcessId(processId);
+ command.setParameters(parameters);
+ return commandService.execute(command);
+ }
+
+ public void dispose() {
+ commandService.dispose();
+ }
+
+ public int fireAllRules() {
+ throw new UnsupportedOperationException();
+ }
+
+ public int fireAllRules(int max) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int fireAllRules(AgendaFilter agendaFilter) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void fireUntilHalt() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void fireUntilHalt(AgendaFilter agendaFilter) {
+ throw new UnsupportedOperationException();
+ }
+
+ public KnowledgeBase getKnowledgeBase() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void registerExitPoint(String name, ExitPoint exitPoint) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setGlobal(String identifier, Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setGlobalResolver(GlobalResolver globalResolver) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void unregisterExitPoint(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Agenda getAgenda() {
+ throw new UnsupportedOperationException();
+ }
+
+ public FactHandle getFactHandle(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<? extends FactHandle> getFactHandles() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<? extends FactHandle> getFactHandles(ObjectFilter filter) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<?> getObjects() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<?> getObjects(ObjectFilter filter) {
+ throw new UnsupportedOperationException();
+ }
+
+ public SessionClock getSessionClock() {
+ throw new UnsupportedOperationException();
+ }
+
+ public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void halt() {
+ throw new UnsupportedOperationException();
+ }
+
+ public FactHandle insert(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void retract(FactHandle handle) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void update(FactHandle handle, Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addEventListener(WorkingMemoryEventListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addEventListener(AgendaEventListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<AgendaEventListener> getAgendaEventListeners() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<WorkingMemoryEventListener> getWorkingMemoryEventListeners() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeEventListener(WorkingMemoryEventListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeEventListener(AgendaEventListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addEventListener(ProcessEventListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<ProcessEventListener> getProcessEventListeners() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeEventListener(ProcessEventListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getGlobal(String identifier) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getObject(FactHandle factHandle) {
+ throw new UnsupportedOperationException();
+ }
+
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/drools.default.rulebase.conf
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/drools.default.rulebase.conf 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/drools.default.rulebase.conf 2009-01-16 00:19:21 UTC (rev 24744)
@@ -17,6 +17,4 @@
drools.conflictResolver = org.drools.conflict.DepthConflictResolver
drools.consequenceExceptionHandler = org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler
drools.ruleBaseUpdateHandler = org.drools.base.FireAllRulesRuleBaseUpdateListener
-drools.workDefinitions = WorkDefinitions.conf
-drools.processInstanceManagerFactory = org.drools.process.instance.impl.DefaultProcessInstanceManagerFactory
-drools.workItemManagerFactory = org.drools.process.instance.impl.DefaultWorkItemManagerFactory
+drools.workDefinitions = WorkDefinitions.conf
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -102,7 +102,7 @@
public void testWorkItemHandlers() {
Properties properties = new Properties();
properties.setProperty( "drools.workItemHandlers", "WorkItemHandlers1.conf WorkItemHandlers2.conf" );
- RuleBaseConfiguration cfg = new RuleBaseConfiguration(properties);
+ SessionConfiguration cfg = new SessionConfiguration(properties);
assertEquals(cfg.getWorkItemHandlers().size(), 3);
assertEquals(cfg.getWorkItemHandlers().get("MyWork").getClass(), SystemOutWorkItemHandler.class);
assertEquals(cfg.getWorkItemHandlers().get("UIWork").getClass(), SystemOutWorkItemHandler.class);
Deleted: labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/CommandBasedStatefulKnowledgeSession.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/CommandBasedStatefulKnowledgeSession.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/CommandBasedStatefulKnowledgeSession.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -1,225 +0,0 @@
-package org.drools.persistence.session;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.drools.KnowledgeBase;
-import org.drools.event.process.ProcessEventListener;
-import org.drools.event.rule.AgendaEventListener;
-import org.drools.event.rule.WorkingMemoryEventListener;
-import org.drools.process.command.AbortWorkItemCommand;
-import org.drools.process.command.CommandService;
-import org.drools.process.command.CompleteWorkItemCommand;
-import org.drools.process.command.GetProcessInstanceCommand;
-import org.drools.process.command.SignalEventCommand;
-import org.drools.process.command.StartProcessCommand;
-import org.drools.runtime.ExitPoint;
-import org.drools.runtime.GlobalResolver;
-import org.drools.runtime.ObjectFilter;
-import org.drools.runtime.StatefulKnowledgeSession;
-import org.drools.runtime.process.ProcessInstance;
-import org.drools.runtime.process.WorkItemHandler;
-import org.drools.runtime.process.WorkItemManager;
-import org.drools.runtime.rule.Agenda;
-import org.drools.runtime.rule.AgendaFilter;
-import org.drools.runtime.rule.FactHandle;
-import org.drools.runtime.rule.WorkingMemoryEntryPoint;
-import org.drools.time.SessionClock;
-
-public class CommandBasedStatefulKnowledgeSession implements StatefulKnowledgeSession {
-
- private CommandService commandService;
- private transient WorkItemManager workItemManager;
-
- public CommandBasedStatefulKnowledgeSession(CommandService commandService) {
- this.commandService = commandService;
- }
-
- public ProcessInstance getProcessInstance(long id) {
- GetProcessInstanceCommand command = new GetProcessInstanceCommand();
- command.setProcessInstanceId(id);
- return commandService.execute(command);
- }
-
- public Collection<ProcessInstance> getProcessInstances() {
- throw new UnsupportedOperationException();
- }
-
- public WorkItemManager getWorkItemManager() {
- if (workItemManager == null) {
- workItemManager = new WorkItemManager() {
- public void completeWorkItem(long id, Map<String, Object> results) {
- CompleteWorkItemCommand command = new CompleteWorkItemCommand();
- command.setWorkItemId(id);
- command.setResults(results);
- commandService.execute(command);
- }
- public void abortWorkItem(long id) {
- AbortWorkItemCommand command = new AbortWorkItemCommand();
- command.setWorkItemId(id);
- commandService.execute(command);
- }
- public void registerWorkItemHandler(String workItemName, WorkItemHandler handler) {
- throw new UnsupportedOperationException();
- }
- };
- }
- return workItemManager;
- }
-
- public void signalEvent(String type, Object event) {
- SignalEventCommand command = new SignalEventCommand();
- command.setEventType(type);
- command.setEvent(event);
- commandService.execute(command);
- }
-
- public ProcessInstance startProcess(String processId) {
- return startProcess(processId, null);
- }
-
- public ProcessInstance startProcess(String processId,
- Map<String, Object> parameters) {
- StartProcessCommand command = new StartProcessCommand();
- command.setProcessId(processId);
- command.setParameters(parameters);
- return commandService.execute(command);
- }
-
- public void dispose() {
- commandService.dispose();
- }
-
- public int fireAllRules() {
- throw new UnsupportedOperationException();
- }
-
- public int fireAllRules(int max) {
- throw new UnsupportedOperationException();
- }
-
- public int fireAllRules(AgendaFilter agendaFilter) {
- throw new UnsupportedOperationException();
- }
-
- public void fireUntilHalt() {
- throw new UnsupportedOperationException();
- }
-
- public void fireUntilHalt(AgendaFilter agendaFilter) {
- throw new UnsupportedOperationException();
- }
-
- public KnowledgeBase getKnowledgeBase() {
- throw new UnsupportedOperationException();
- }
-
- public void registerExitPoint(String name, ExitPoint exitPoint) {
- throw new UnsupportedOperationException();
- }
-
- public void setGlobal(String identifier, Object object) {
- throw new UnsupportedOperationException();
- }
-
- public Object getGlobal(String identifier) {
- throw new UnsupportedOperationException();
- }
-
- public void setGlobalResolver(GlobalResolver globalResolver) {
- throw new UnsupportedOperationException();
- }
-
- public void unregisterExitPoint(String name) {
- throw new UnsupportedOperationException();
- }
-
- public Agenda getAgenda() {
- throw new UnsupportedOperationException();
- }
-
- public FactHandle getFactHandle(Object object) {
- throw new UnsupportedOperationException();
- }
-
- public Object getObject(FactHandle factHandle) {
- throw new UnsupportedOperationException();
- }
-
- public Collection<? extends FactHandle> getFactHandles() {
- throw new UnsupportedOperationException();
- }
-
- public Collection<? extends FactHandle> getFactHandles(ObjectFilter filter) {
- throw new UnsupportedOperationException();
- }
-
- public Collection<?> getObjects() {
- throw new UnsupportedOperationException();
- }
-
- public Collection<?> getObjects(ObjectFilter filter) {
- throw new UnsupportedOperationException();
- }
-
- public SessionClock getSessionClock() {
- throw new UnsupportedOperationException();
- }
-
- public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String name) {
- throw new UnsupportedOperationException();
- }
-
- public void halt() {
- throw new UnsupportedOperationException();
- }
-
- public FactHandle insert(Object object) {
- throw new UnsupportedOperationException();
- }
-
- public void retract(FactHandle handle) {
- throw new UnsupportedOperationException();
- }
-
- public void update(FactHandle handle, Object object) {
- throw new UnsupportedOperationException();
- }
-
- public void addEventListener(WorkingMemoryEventListener listener) {
- throw new UnsupportedOperationException();
- }
-
- public void addEventListener(AgendaEventListener listener) {
- throw new UnsupportedOperationException();
- }
-
- public Collection<AgendaEventListener> getAgendaEventListeners() {
- throw new UnsupportedOperationException();
- }
-
- public Collection<WorkingMemoryEventListener> getWorkingMemoryEventListeners() {
- throw new UnsupportedOperationException();
- }
-
- public void removeEventListener(WorkingMemoryEventListener listener) {
- throw new UnsupportedOperationException();
- }
-
- public void removeEventListener(AgendaEventListener listener) {
- throw new UnsupportedOperationException();
- }
-
- public void addEventListener(ProcessEventListener listener) {
- throw new UnsupportedOperationException();
- }
-
- public Collection<ProcessEventListener> getProcessEventListeners() {
- throw new UnsupportedOperationException();
- }
-
- public void removeEventListener(ProcessEventListener listener) {
- throw new UnsupportedOperationException();
- }
-
-}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/JPAPersisterManager.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/JPAPersisterManager.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/JPAPersisterManager.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -4,6 +4,7 @@
import javax.persistence.Persistence;
import org.drools.RuleBase;
+import org.drools.SessionConfiguration;
import org.drools.StatefulSession;
import org.drools.marshalling.PlaceholderResolverStrategyFactory;
import org.drools.persistence.Persister;
@@ -35,6 +36,10 @@
return new JPAPersister<StatefulSession>(emf, new StatefulSessionSnapshotter(ruleBase.newStatefulSession(), factory));
}
+ public Persister<StatefulSession> getSessionPersister(RuleBase ruleBase, SessionConfiguration conf) {
+ return new JPAPersister<StatefulSession>(emf, new StatefulSessionSnapshotter(ruleBase.newStatefulSession(conf), factory));
+ }
+
public Persister<StatefulSession> getSessionPersister(String uniqueId, RuleBase ruleBase) {
Persister<StatefulSession> persister = new JPAPersister<StatefulSession>(
emf, new StatefulSessionSnapshotter(ruleBase, factory));
Modified: labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/SingleSessionCommandService.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/SingleSessionCommandService.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/session/SingleSessionCommandService.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -5,6 +5,7 @@
import org.drools.KnowledgeBase;
import org.drools.RuleBase;
+import org.drools.SessionConfiguration;
import org.drools.StatefulSession;
import org.drools.common.InternalWorkingMemory;
import org.drools.impl.KnowledgeBaseImpl;
@@ -26,11 +27,20 @@
this(ruleBase, (PlaceholderResolverStrategyFactory) null);
}
+ public SingleSessionCommandService(RuleBase ruleBase, SessionConfiguration conf) {
+ this(ruleBase, conf, (PlaceholderResolverStrategyFactory) null);
+ }
+
public SingleSessionCommandService(RuleBase ruleBase, PlaceholderResolverStrategyFactory factory) {
persister = new JPAPersisterManager(factory).getSessionPersister(ruleBase);
init();
}
+ public SingleSessionCommandService(RuleBase ruleBase, SessionConfiguration conf, PlaceholderResolverStrategyFactory factory) {
+ persister = new JPAPersisterManager(factory).getSessionPersister(ruleBase, conf);
+ init();
+ }
+
public SingleSessionCommandService(RuleBase ruleBase, EntityManagerFactory emf) {
this(ruleBase, (PlaceholderResolverStrategyFactory)null, emf);
}
Modified: labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/resources/META-INF/persistence.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/resources/META-INF/persistence.xml 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/main/resources/META-INF/persistence.xml 2009-01-16 00:19:21 UTC (rev 24744)
@@ -36,7 +36,7 @@
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
- <property name="hibernate.show_sql" value="true" />
+ <property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
Modified: labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/java/org/drools/persistence/session/PersistentStatefulSessionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/java/org/drools/persistence/session/PersistentStatefulSessionTest.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/java/org/drools/persistence/session/PersistentStatefulSessionTest.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -1,5 +1,7 @@
package org.drools.persistence.session;
+import java.util.Properties;
+
import junit.framework.TestCase;
import org.drools.KnowledgeBase;
@@ -8,82 +10,66 @@
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.impl.ClassPathResource;
-import org.drools.process.command.impl.LoggingInterceptor;
+import org.drools.runtime.KnowledgeSessionConfiguration;
+import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkItem;
public class PersistentStatefulSessionTest extends TestCase {
public void testPersistenceWorkItems() {
+ Properties properties = new Properties();
+ properties.setProperty("drools.commandService", "org.drools.persistence.session.SingleSessionCommandService");
+ properties.setProperty("drools.processInstanceManagerFactory", "org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory");
+ properties.setProperty("drools.workItemManagerFactory", "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
+ properties.setProperty("drools.processSignalManagerFactory", "org.drools.persistence.processinstance.JPASignalManagerFactory");
+ KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
+
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
- LoggingInterceptor interceptor = new LoggingInterceptor();
- SingleSessionCommandService commandService = new SingleSessionCommandService(kbase);
- interceptor.setNext(commandService);
- CommandBasedStatefulKnowledgeSession session = new CommandBasedStatefulKnowledgeSession(interceptor);
+ StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession(config);
ProcessInstance processInstance = session.startProcess("org.drools.test.TestProcess");
System.out.println("Started process instance " + processInstance.getId());
- String sessionId = commandService.getSessionId();
+// String sessionId = commandService.getSessionId();
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
- interceptor = new LoggingInterceptor();
- commandService = new SingleSessionCommandService(kbase, sessionId);
- interceptor.setNext(commandService);
- session = new CommandBasedStatefulKnowledgeSession(interceptor);
+ session = kbase.newStatefulKnowledgeSession(config);
processInstance = session.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
- interceptor = new LoggingInterceptor();
- commandService = new SingleSessionCommandService(kbase, sessionId);
- interceptor.setNext(commandService);
- session = new CommandBasedStatefulKnowledgeSession(interceptor);
+ session = kbase.newStatefulKnowledgeSession(config);
session.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNotNull(workItem);
- interceptor = new LoggingInterceptor();
- commandService = new SingleSessionCommandService(kbase, sessionId);
- interceptor.setNext(commandService);
- session = new CommandBasedStatefulKnowledgeSession(interceptor);
+ session = kbase.newStatefulKnowledgeSession(config);
processInstance = session.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
- interceptor = new LoggingInterceptor();
- commandService = new SingleSessionCommandService(kbase, sessionId);
- interceptor.setNext(commandService);
- session = new CommandBasedStatefulKnowledgeSession(interceptor);
+ session = kbase.newStatefulKnowledgeSession(config);
session.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNotNull(workItem);
- interceptor = new LoggingInterceptor();
- commandService = new SingleSessionCommandService(kbase, sessionId);
- interceptor.setNext(commandService);
- session = new CommandBasedStatefulKnowledgeSession(interceptor);
+ session = kbase.newStatefulKnowledgeSession(config);
processInstance = session.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
- interceptor = new LoggingInterceptor();
- commandService = new SingleSessionCommandService(kbase, sessionId);
- interceptor.setNext(commandService);
- session = new CommandBasedStatefulKnowledgeSession(interceptor);
+ session = kbase.newStatefulKnowledgeSession(config);
session.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNull(workItem);
- interceptor = new LoggingInterceptor();
- commandService = new SingleSessionCommandService(kbase, sessionId);
- interceptor.setNext(commandService);
- session = new CommandBasedStatefulKnowledgeSession(interceptor);
+ session = kbase.newStatefulKnowledgeSession(config);
processInstance = session.getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
Modified: labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/java/org/drools/persistence/session/SingleSessionCommandServiceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/java/org/drools/persistence/session/SingleSessionCommandServiceTest.java 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/java/org/drools/persistence/session/SingleSessionCommandServiceTest.java 2009-01-16 00:19:21 UTC (rev 24744)
@@ -8,9 +8,11 @@
import junit.framework.TestCase;
+import org.drools.KnowledgeBaseFactory;
import org.drools.RuleBase;
import org.drools.RuleBaseConfiguration;
import org.drools.RuleBaseFactory;
+import org.drools.SessionConfiguration;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.ProcessBuilder;
import org.drools.process.command.CompleteWorkItemCommand;
@@ -22,6 +24,7 @@
import org.drools.rule.Package;
import org.drools.ruleflow.core.RuleFlowProcess;
import org.drools.ruleflow.instance.RuleFlowProcessInstance;
+import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.process.NodeInstance;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkItem;
@@ -49,22 +52,18 @@
}
public void testPersistenceWorkItems() {
- Properties properties = new Properties();
- properties.put(
- "processInstanceManagerFactory",
- "org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory");
- properties.put(
- "workItemManagerFactory",
- "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
- properties.put(
- "processSignalManagerFactory",
- "org.drools.persistence.processinstance.JPASignalManagerFactory");
- RuleBaseConfiguration conf = new RuleBaseConfiguration(properties);
- RuleBase ruleBase = RuleBaseFactory.newRuleBase(conf);
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
Package pkg = getProcessWorkItems();
ruleBase.addPackage(pkg);
- SingleSessionCommandService service = new SingleSessionCommandService(ruleBase);
+ Properties properties = new Properties();
+ properties.setProperty("drools.commandService", "org.drools.persistence.session.SingleSessionCommandService");
+ properties.setProperty("drools.processInstanceManagerFactory", "org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory");
+ properties.setProperty("drools.workItemManagerFactory", "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
+ properties.setProperty("drools.processSignalManagerFactory", "org.drools.persistence.processinstance.JPASignalManagerFactory");
+ SessionConfiguration config = new SessionConfiguration(properties);
+
+ SingleSessionCommandService service = new SingleSessionCommandService(ruleBase, config);
StartProcessCommand startProcessCommand = new StartProcessCommand();
startProcessCommand.setProcessId("org.drools.test.TestProcess");
ProcessInstance processInstance = (ProcessInstance) service.execute(startProcessCommand);
@@ -74,13 +73,13 @@
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = (ProcessInstance) service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
@@ -88,13 +87,13 @@
workItem = handler.getWorkItem();
assertNotNull(workItem);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = (ProcessInstance) service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
@@ -102,13 +101,13 @@
workItem = handler.getWorkItem();
assertNotNull(workItem);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = (ProcessInstance) service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
@@ -116,7 +115,7 @@
workItem = handler.getWorkItem();
assertNull(workItem);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = (ProcessInstance) service.execute(getProcessInstanceCommand);
@@ -179,21 +178,17 @@
public void testPersistenceSubProcess() {
Properties properties = new Properties();
- properties.put(
- "processInstanceManagerFactory",
- "org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory");
- properties.put(
- "workItemManagerFactory",
- "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
- properties.put(
- "processSignalManagerFactory",
- "org.drools.persistence.processinstance.JPASignalManagerFactory");
- RuleBaseConfiguration conf = new RuleBaseConfiguration(properties);
- RuleBase ruleBase = RuleBaseFactory.newRuleBase(conf);
+ properties.setProperty("drools.commandService", "org.drools.persistence.session.SingleSessionCommandService");
+ properties.setProperty("drools.processInstanceManagerFactory", "org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory");
+ properties.setProperty("drools.workItemManagerFactory", "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
+ properties.setProperty("drools.processSignalManagerFactory", "org.drools.persistence.processinstance.JPASignalManagerFactory");
+ SessionConfiguration config = new SessionConfiguration(properties);
+
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
Package pkg = getProcessSubProcess();
ruleBase.addPackage(pkg);
- SingleSessionCommandService service = new SingleSessionCommandService(ruleBase);
+ SingleSessionCommandService service = new SingleSessionCommandService(ruleBase, config);
StartProcessCommand startProcessCommand = new StartProcessCommand();
startProcessCommand.setProcessId("org.drools.test.TestProcess");
RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) service.execute(startProcessCommand);
@@ -204,7 +199,7 @@
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstanceId);
processInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
@@ -219,13 +214,12 @@
RuleFlowProcessInstance subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
assertNotNull(subProcessInstance);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
- service = new SingleSessionCommandService(ruleBase);
-
+ service = new SingleSessionCommandService(ruleBase, config);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(subProcessInstanceId);
subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
@@ -308,33 +302,29 @@
public void testPersistenceTimer() throws Exception {
Properties properties = new Properties();
- properties.put(
- "processInstanceManagerFactory",
- "org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory");
- properties.put(
- "workItemManagerFactory",
- "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
- properties.put(
- "processSignalManagerFactory",
- "org.drools.persistence.processinstance.JPASignalManagerFactory");
- RuleBaseConfiguration conf = new RuleBaseConfiguration(properties);
- RuleBase ruleBase = RuleBaseFactory.newRuleBase(conf);
+ properties.setProperty("drools.commandService", "org.drools.persistence.session.SingleSessionCommandService");
+ properties.setProperty("drools.processInstanceManagerFactory", "org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory");
+ properties.setProperty("drools.workItemManagerFactory", "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
+ properties.setProperty("drools.processSignalManagerFactory", "org.drools.persistence.processinstance.JPASignalManagerFactory");
+ SessionConfiguration config = new SessionConfiguration(properties);
+
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
Package pkg = getProcessTimer();
ruleBase.addPackage(pkg);
- SingleSessionCommandService service = new SingleSessionCommandService(ruleBase);
+ SingleSessionCommandService service = new SingleSessionCommandService(ruleBase, config);
StartProcessCommand startProcessCommand = new StartProcessCommand();
startProcessCommand.setProcessId("org.drools.test.TestProcess");
ProcessInstance processInstance = (ProcessInstance) service.execute(startProcessCommand);
System.out.println("Started process instance " + processInstance.getId());
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = (ProcessInstance) service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
Thread.sleep(2000);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
@@ -382,33 +372,29 @@
// @FIXME krisv this fails due to nested transactions
public void FIXME_testPersistenceTimer2() throws Exception {
Properties properties = new Properties();
- properties.put(
- "processInstanceManagerFactory",
- "org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory");
- properties.put(
- "workItemManagerFactory",
- "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
- properties.put(
- "processSignalManagerFactory",
- "org.drools.persistence.processinstance.JPASignalManagerFactory");
- RuleBaseConfiguration conf = new RuleBaseConfiguration(properties);
- RuleBase ruleBase = RuleBaseFactory.newRuleBase(conf);
+ properties.setProperty("drools.commandService", "org.drools.persistence.session.SingleSessionCommandService");
+ properties.setProperty("drools.processInstanceManagerFactory", "org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory");
+ properties.setProperty("drools.workItemManagerFactory", "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
+ properties.setProperty("drools.processSignalManagerFactory", "org.drools.persistence.processinstance.JPASignalManagerFactory");
+ SessionConfiguration config = new SessionConfiguration(properties);
+
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
Package pkg = getProcessTimer2();
ruleBase.addPackage(pkg);
- SingleSessionCommandService service = new SingleSessionCommandService(ruleBase);
+ SingleSessionCommandService service = new SingleSessionCommandService(ruleBase, config);
StartProcessCommand startProcessCommand = new StartProcessCommand();
startProcessCommand.setProcessId("org.drools.test.TestProcess");
ProcessInstance processInstance = (ProcessInstance) service.execute(startProcessCommand);
System.out.println("Started process instance " + processInstance.getId());
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = (ProcessInstance) service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
- service = new SingleSessionCommandService(ruleBase);
+ service = new SingleSessionCommandService(ruleBase, config);
Thread.sleep(2000);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
Deleted: labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.rulebase.conf
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.rulebase.conf 2009-01-16 00:12:53 UTC (rev 24743)
+++ labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.rulebase.conf 2009-01-16 00:19:21 UTC (rev 24744)
@@ -1,4 +0,0 @@
-drools.workItemHandlers = MyWorkItemHandlers.conf
-processInstanceManagerFactory = org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory
-workItemManagerFactory = org.drools.persistence.processinstance.JPAWorkItemManagerFactory
-processSignalManagerFactory = org.drools.persistence.processinstance.JPASignalManagerFactory
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.session.conf (from rev 24677, labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.rulebase.conf)
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.session.conf (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.session.conf 2009-01-16 00:19:21 UTC (rev 24744)
@@ -0,0 +1,5 @@
+drools.workItemHandlers = MyWorkItemHandlers.conf
+#drools.commandService = org.drools.persistence.session.SingleSessionCommandService
+#drools.processInstanceManagerFactory = org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory
+#drools.workItemManagerFactory = org.drools.persistence.processinstance.JPAWorkItemManagerFactory
+#drools.processSignalManagerFactory = org.drools.persistence.processinstance.JPASignalManagerFactory
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-process/drools-process-enterprise/src/test/resources/META-INF/drools.session.conf
___________________________________________________________________
Name: svn:mergeinfo
+
More information about the jboss-svn-commits
mailing list