[jboss-svn-commits] JBL Code SVN: r25419 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: process/command and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Feb 25 04:45:03 EST 2009
Author: Rikkola
Date: 2009-02-25 04:45:03 -0500 (Wed, 25 Feb 2009)
New Revision: 25419
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/AddEventListenerCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetAgendaEventListenersCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetFactHandlesCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetProcessEventListenersCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetWorkingMemoryEventListenersCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/RegisterExitPointCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/RemoveEventListenerCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/UnregisterExitPointCommand.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java
Log:
JBRULES-1915: Improve process persistence usability
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java 2009-02-25 03:47:07 UTC (rev 25418)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -27,6 +27,7 @@
import org.drools.event.ObjectRetractedEvent;
import org.drools.event.ObjectUpdatedEvent;
import org.drools.event.RuleFlowCompletedEvent;
+import org.drools.event.RuleFlowEventListener;
import org.drools.event.RuleFlowGroupActivatedEvent;
import org.drools.event.RuleFlowGroupDeactivatedEvent;
import org.drools.event.RuleFlowNodeTriggeredEvent;
@@ -66,7 +67,7 @@
implements
StatefulKnowledgeSession,
InternalWorkingMemoryEntryPoint {
- public ReteooWorkingMemory session;
+ public ReteooWorkingMemory session;
public KnowledgeBaseImpl kbase;
public Map<WorkingMemoryEventListener, WorkingMemoryEventListenerWrapper> mappedWorkingMemoryListeners;
@@ -87,10 +88,10 @@
this.mappedAgendaListeners = new IdentityHashMap<AgendaEventListener, AgendaEventListenerWrapper>();
this.mappedProcessListeners = new IdentityHashMap<ProcessEventListener, ProcessEventListenerWrapper>();
}
-
+
public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String name) {
- return session.getWorkingMemoryEntryPoint( name );
- }
+ return session.getWorkingMemoryEntryPoint( name );
+ }
public void addEventListener(WorkingMemoryEventListener listener) {
WorkingMemoryEventListenerWrapper wrapper = new WorkingMemoryEventListenerWrapper( listener );
@@ -150,22 +151,22 @@
public int fireAllRules() {
return this.session.fireAllRules();
}
-
+
public int fireAllRules(int max) {
return this.session.fireAllRules( max );
}
-
+
public int fireAllRules(AgendaFilter agendaFilter) {
return this.session.fireAllRules( new AgendaFilterWrapper( agendaFilter ) );
}
public void fireUntilHalt() {
- this.session.fireUntilHalt( );
+ this.session.fireUntilHalt();
}
public void fireUntilHalt(AgendaFilter agendaFilter) {
this.session.fireUntilHalt( new AgendaFilterWrapper( agendaFilter ) );
- }
+ }
public SessionClock getSessionClock() {
return this.session.getSessionClock();
@@ -174,11 +175,11 @@
public void halt() {
this.session.halt();
}
-
+
public void dispose() {
this.session.dispose();
}
-
+
public FactHandle insert(Object object) {
return this.session.insert( object );
}
@@ -202,7 +203,7 @@
public FactHandle getFactHandle(Object object) {
return this.session.getFactHandle( object );
}
-
+
public Object getObject(FactHandle factHandle) {
return this.session.getObject( factHandle );
}
@@ -212,9 +213,9 @@
}
public Collection<ProcessInstance> getProcessInstances() {
- List<ProcessInstance> result = new ArrayList<ProcessInstance>();
- result.addAll(this.session.getProcessInstances());
- return result;
+ List<ProcessInstance> result = new ArrayList<ProcessInstance>();
+ result.addAll( this.session.getProcessInstances() );
+ return result;
}
public WorkItemManager getWorkItemManager() {
@@ -242,30 +243,30 @@
this.session.setGlobal( identifier,
object );
}
-
+
public Object getGlobal(String identifier) {
return this.session.getGlobal( identifier );
}
-
+
public Globals getGlobals() {
- return ( Globals ) this.session.getGlobalResolver();
- }
+ return (Globals) this.session.getGlobalResolver();
+ }
-// public Future<Object> asyncInsert(Object object) {
-// return new FutureAdapter( this.session.asyncInsert( object ) );
-// }
-//
-// public Future<Object> asyncInsert(Object[] array) {
-// return new FutureAdapter( this.session.asyncInsert( array ) );
-// }
-//
-// public Future<Object> asyncInsert(Iterable< ? > iterable) {
-// return new FutureAdapter( this.session.asyncInsert( iterable ) );
-// }
-//
-// public Future< ? > asyncFireAllRules() {
-// return new FutureAdapter( this.session.asyncFireAllRules() );
-// }
+ // public Future<Object> asyncInsert(Object object) {
+ // return new FutureAdapter( this.session.asyncInsert( object ) );
+ // }
+ //
+ // public Future<Object> asyncInsert(Object[] array) {
+ // return new FutureAdapter( this.session.asyncInsert( array ) );
+ // }
+ //
+ // public Future<Object> asyncInsert(Iterable< ? > iterable) {
+ // return new FutureAdapter( this.session.asyncInsert( iterable ) );
+ // }
+ //
+ // public Future< ? > asyncFireAllRules() {
+ // return new FutureAdapter( this.session.asyncFireAllRules() );
+ // }
public Collection< ? extends FactHandle> getFactHandles() {
return new ObjectStoreWrapper( session.getObjectStore(),
@@ -321,11 +322,11 @@
}
public static class ObjectStoreWrapper extends AbstractImmutableCollection {
- public ObjectStore store;
- public org.drools.runtime.ObjectFilter filter;
- public int type; // 0 == object, 1 == facthandle
- public static final int OBJECT = 0;
- public static final int FACT_HANDLE = 1;
+ public ObjectStore store;
+ public org.drools.runtime.ObjectFilter filter;
+ public int type; // 0 == object, 1 == facthandle
+ public static final int OBJECT = 0;
+ public static final int FACT_HANDLE = 1;
public ObjectStoreWrapper(ObjectStore store,
org.drools.runtime.ObjectFilter filter,
@@ -430,12 +431,16 @@
public void objectUpdated(ObjectUpdatedEvent event) {
listener.objectUpdated( new ObjectUpdatedEventImpl( event ) );
}
+
+ public WorkingMemoryEventListener unWrap() {
+ return listener;
+ }
}
public static class AgendaEventListenerWrapper
implements
org.drools.event.AgendaEventListener {
- private AgendaEventListener listener;
+ private AgendaEventListener listener;
public AgendaEventListenerWrapper(AgendaEventListener listener) {
this.listener = listener;
@@ -445,41 +450,45 @@
WorkingMemory workingMemory) {
listener.activationCancelled( new ActivationCancelledEventImpl( event.getActivation(),
- ((InternalWorkingMemory)workingMemory).getKnowledgeRuntime(),
- event.getCause() ) );
+ ((InternalWorkingMemory) workingMemory).getKnowledgeRuntime(),
+ event.getCause() ) );
}
public void activationCreated(ActivationCreatedEvent event,
WorkingMemory workingMemory) {
listener.activationCreated( new ActivationCreatedEventImpl( event.getActivation(),
- ((InternalWorkingMemory)workingMemory).getKnowledgeRuntime() ) );
+ ((InternalWorkingMemory) workingMemory).getKnowledgeRuntime() ) );
}
public void beforeActivationFired(BeforeActivationFiredEvent event,
WorkingMemory workingMemory) {
listener.beforeActivationFired( new BeforeActivationFiredEventImpl( event.getActivation(),
- ((InternalWorkingMemory)workingMemory).getKnowledgeRuntime() ) );
+ ((InternalWorkingMemory) workingMemory).getKnowledgeRuntime() ) );
}
public void afterActivationFired(AfterActivationFiredEvent event,
WorkingMemory workingMemory) {
listener.afterActivationFired( new AfterActivationFiredEventImpl( event.getActivation(),
- ((InternalWorkingMemory)workingMemory).getKnowledgeRuntime() ) );
+ ((InternalWorkingMemory) workingMemory).getKnowledgeRuntime() ) );
}
public void agendaGroupPopped(AgendaGroupPoppedEvent event,
WorkingMemory workingMemory) {
listener.agendaGroupPopped( new AgendaGroupPoppedEventImpl( event.getAgendaGroup(),
- ((InternalWorkingMemory)workingMemory).getKnowledgeRuntime() ) );
+ ((InternalWorkingMemory) workingMemory).getKnowledgeRuntime() ) );
}
public void agendaGroupPushed(AgendaGroupPushedEvent event,
WorkingMemory workingMemory) {
listener.agendaGroupPushed( new AgendaGroupPushedEventImpl( event.getAgendaGroup(),
- ((InternalWorkingMemory)workingMemory).getKnowledgeRuntime() ) );
+ ((InternalWorkingMemory) workingMemory).getKnowledgeRuntime() ) );
}
+ public AgendaEventListener unWrap() {
+ return listener;
+ }
+
}
public static class ProcessEventListenerWrapper
@@ -555,31 +564,39 @@
workingMemory ) );
}
+ public ProcessEventListener unWrap() {
+ return listener;
+ }
+
}
-
- public static class AgendaFilterWrapper implements org.drools.spi.AgendaFilter {
- private AgendaFilter filter;
-
+
+ public static class AgendaFilterWrapper
+ implements
+ org.drools.spi.AgendaFilter {
+ private AgendaFilter filter;
+
public AgendaFilterWrapper(AgendaFilter filter) {
this.filter = filter;
}
public boolean accept(Activation activation) {
return filter.accept( activation );
- }
+ }
}
public Agenda getAgenda() {
- return new AgendaImpl( ( InternalAgenda ) this.session.getAgenda() );
+ return new AgendaImpl( (InternalAgenda) this.session.getAgenda() );
}
- public void registerExitPoint(String name, ExitPoint exitPoint) {
- this.session.registerExitPoint(name, exitPoint);
- }
+ public void registerExitPoint(String name,
+ ExitPoint exitPoint) {
+ this.session.registerExitPoint( name,
+ exitPoint );
+ }
- public void unregisterExitPoint(String name) {
- this.session.unregisterExitPoint(name);
- }
+ public void unregisterExitPoint(String name) {
+ this.session.unregisterExitPoint( name );
+ }
public ObjectTypeConfigurationRegistry getObjectTypeConfigurationRegistry() {
return this.session.getObjectTypeConfigurationRegistry();
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/AddEventListenerCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/AddEventListenerCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/AddEventListenerCommand.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -0,0 +1,48 @@
+package org.drools.process.command;
+
+import org.drools.StatefulSession;
+import org.drools.event.AgendaEventListener;
+import org.drools.event.RuleFlowEventListener;
+import org.drools.event.WorkingMemoryEventListener;
+
+public class AddEventListenerCommand
+ implements
+ Command<Object> {
+
+ private WorkingMemoryEventListener workingMemoryEventlistener = null;
+ private AgendaEventListener agendaEventlistener = null;
+ private RuleFlowEventListener ruleFlowEventlistener = null;
+
+ public AddEventListenerCommand(WorkingMemoryEventListener listener) {
+ this.workingMemoryEventlistener = listener;
+ }
+
+ public AddEventListenerCommand(AgendaEventListener listener) {
+ this.agendaEventlistener = listener;
+ }
+
+ public AddEventListenerCommand(RuleFlowEventListener listener) {
+ this.ruleFlowEventlistener = listener;
+ }
+
+ public Object execute(StatefulSession session) {
+ if ( workingMemoryEventlistener != null ) {
+ session.addEventListener( workingMemoryEventlistener );
+ } else if ( agendaEventlistener != null ) {
+ session.addEventListener( agendaEventlistener );
+ } else {
+ session.addEventListener( ruleFlowEventlistener );
+ }
+ return null;
+ }
+
+ public String toString() {
+ if ( workingMemoryEventlistener != null ) {
+ return "session.addEventListener( " + workingMemoryEventlistener + " );";
+ } else if ( agendaEventlistener != null ) {
+ return "session.addEventListener( " + agendaEventlistener + " );";
+ } else {
+ return "session.addEventListener( " + ruleFlowEventlistener + " );";
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetAgendaEventListenersCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetAgendaEventListenersCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetAgendaEventListenersCommand.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -0,0 +1,19 @@
+package org.drools.process.command;
+
+import java.util.Collection;
+
+import org.drools.StatefulSession;
+import org.drools.event.AgendaEventListener;
+
+public class GetAgendaEventListenersCommand
+ implements
+ Command<Collection<AgendaEventListener>> {
+
+ public Collection<AgendaEventListener> execute(StatefulSession session) {
+ return session.getAgendaEventListeners();
+ }
+
+ public String toString() {
+ return "session.getAgendaEventListeners();";
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetFactHandlesCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetFactHandlesCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetFactHandlesCommand.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -0,0 +1,45 @@
+package org.drools.process.command;
+
+import java.util.Collection;
+
+import org.drools.StatefulSession;
+import org.drools.impl.StatefulKnowledgeSessionImpl.ObjectStoreWrapper;
+import org.drools.reteoo.ReteooStatefulSession;
+import org.drools.runtime.ObjectFilter;
+import org.drools.runtime.rule.FactHandle;
+
+public class GetFactHandlesCommand
+ implements
+ Command<Collection< ? extends FactHandle>> {
+
+ private ObjectFilter filter = null;
+
+ public GetFactHandlesCommand() {
+ }
+
+ public GetFactHandlesCommand(ObjectFilter filter) {
+ this.filter = filter;
+ }
+
+ public Collection< ? extends FactHandle> execute(StatefulSession session) {
+ ReteooStatefulSession reteooStatefulSession = (ReteooStatefulSession) session;
+
+ if ( filter != null ) {
+ return new ObjectStoreWrapper( reteooStatefulSession.getObjectStore(),
+ null,
+ ObjectStoreWrapper.FACT_HANDLE );
+ } else {
+ return new ObjectStoreWrapper( reteooStatefulSession.getObjectStore(),
+ filter,
+ ObjectStoreWrapper.FACT_HANDLE );
+ }
+ }
+
+ public String toString() {
+ if ( filter != null ) {
+ return "new ObjectStoreWrapper( reteooStatefulSession.getObjectStore(), null, ObjectStoreWrapper.FACT_HANDLE )";
+ } else {
+ return "new ObjectStoreWrapper( reteooStatefulSession.getObjectStore(), filter, ObjectStoreWrapper.FACT_HANDLE )";
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetProcessEventListenersCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetProcessEventListenersCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetProcessEventListenersCommand.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -0,0 +1,19 @@
+package org.drools.process.command;
+
+import java.util.Collection;
+
+import org.drools.StatefulSession;
+import org.drools.event.RuleFlowEventListener;
+
+public class GetProcessEventListenersCommand
+ implements
+ Command<Collection<RuleFlowEventListener>> {
+
+ public Collection<RuleFlowEventListener> execute(StatefulSession session) {
+ return session.getRuleFlowEventListeners();
+ }
+
+ public String toString() {
+ return "session.getRuleFlowEventListeners();";
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetWorkingMemoryEventListenersCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetWorkingMemoryEventListenersCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/GetWorkingMemoryEventListenersCommand.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -0,0 +1,20 @@
+package org.drools.process.command;
+
+import java.util.Collection;
+
+import org.drools.StatefulSession;
+import org.drools.event.WorkingMemoryEventListener;
+
+public class GetWorkingMemoryEventListenersCommand
+ implements
+ Command<Collection<WorkingMemoryEventListener>> {
+
+ public Collection<WorkingMemoryEventListener> execute(StatefulSession session) {
+ return session.getWorkingMemoryEventListeners();
+ }
+
+ public String toString() {
+ return "session.getWorkingMemoryEventListeners();";
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/RegisterExitPointCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/RegisterExitPointCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/RegisterExitPointCommand.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -0,0 +1,32 @@
+package org.drools.process.command;
+
+import org.drools.StatefulSession;
+import org.drools.reteoo.ReteooStatefulSession;
+import org.drools.runtime.ExitPoint;
+
+public class RegisterExitPointCommand
+ implements
+ Command<Object> {
+
+ private String name;
+ private ExitPoint exitPoint;
+
+ public RegisterExitPointCommand(String name,
+ ExitPoint exitPoint) {
+ this.name = name;
+ this.exitPoint = exitPoint;
+ }
+
+ public Object execute(StatefulSession session) {
+ ReteooStatefulSession reteooStatefulSession = (ReteooStatefulSession) session;
+
+ reteooStatefulSession.registerExitPoint( name,
+ exitPoint );
+
+ return null;
+ }
+
+ public String toString() {
+ return "reteooStatefulSession.registerExitPoint( " + name + ", " + exitPoint + " );";
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/RemoveEventListenerCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/RemoveEventListenerCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/RemoveEventListenerCommand.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -0,0 +1,48 @@
+package org.drools.process.command;
+
+import org.drools.StatefulSession;
+import org.drools.event.AgendaEventListener;
+import org.drools.event.RuleFlowEventListener;
+import org.drools.event.WorkingMemoryEventListener;
+
+public class RemoveEventListenerCommand
+ implements
+ Command<Object> {
+
+ private WorkingMemoryEventListener workingMemoryEventListener = null;
+ private AgendaEventListener agendaEventListener = null;
+ private RuleFlowEventListener ruleFlowEventListener = null;
+
+ public RemoveEventListenerCommand(WorkingMemoryEventListener listener) {
+ this.workingMemoryEventListener = listener;
+ }
+
+ public RemoveEventListenerCommand(AgendaEventListener listener) {
+ this.agendaEventListener = listener;
+ }
+
+ public RemoveEventListenerCommand(RuleFlowEventListener listener) {
+ this.ruleFlowEventListener = listener;
+ }
+
+ public Object execute(StatefulSession session) {
+ if ( workingMemoryEventListener != null ) {
+ session.removeEventListener( workingMemoryEventListener );
+ } else if ( agendaEventListener != null ) {
+ session.removeEventListener( agendaEventListener );
+ } else {
+ session.removeEventListener( ruleFlowEventListener );
+ }
+ return null;
+ }
+
+ public String toString() {
+ if ( workingMemoryEventListener != null ) {
+ return "session.removeEventListener( " + workingMemoryEventListener + " );";
+ } else if ( agendaEventListener != null ) {
+ return "session.removeEventListener( " + agendaEventListener + " );";
+ } else {
+ return "session.removeEventListener( " + ruleFlowEventListener + " );";
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/UnregisterExitPointCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/UnregisterExitPointCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/UnregisterExitPointCommand.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -0,0 +1,27 @@
+package org.drools.process.command;
+
+import org.drools.StatefulSession;
+import org.drools.reteoo.ReteooStatefulSession;
+
+public class UnregisterExitPointCommand
+ implements
+ Command<Object> {
+
+ private String name;
+
+ public UnregisterExitPointCommand(String name) {
+ this.name = name;
+ }
+
+ public Object execute(StatefulSession session) {
+ ReteooStatefulSession reteooStatefulSession = (ReteooStatefulSession) session;
+
+ reteooStatefulSession.unregisterExitPoint( name );
+
+ return null;
+ }
+
+ public String toString() {
+ return "reteooStatefulSession.unregisterExitPoint( " + name + " );";
+ }
+}
Modified: 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 2009-02-25 03:47:07 UTC (rev 25418)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java 2009-02-25 09:45:03 UTC (rev 25419)
@@ -9,30 +9,42 @@
import org.drools.event.process.ProcessEventListener;
import org.drools.event.rule.AgendaEventListener;
import org.drools.event.rule.WorkingMemoryEventListener;
+import org.drools.impl.StatefulKnowledgeSessionImpl;
+import org.drools.impl.StatefulKnowledgeSessionImpl.AgendaEventListenerWrapper;
+import org.drools.impl.StatefulKnowledgeSessionImpl.ProcessEventListenerWrapper;
+import org.drools.impl.StatefulKnowledgeSessionImpl.WorkingMemoryEventListenerWrapper;
import org.drools.process.command.AbortWorkItemCommand;
+import org.drools.process.command.AddEventListenerCommand;
import org.drools.process.command.CommandService;
import org.drools.process.command.CompleteWorkItemCommand;
import org.drools.process.command.FireAllRulesCommand;
import org.drools.process.command.FireUntilHaltCommand;
import org.drools.process.command.GetAgendaCommand;
+import org.drools.process.command.GetAgendaEventListenersCommand;
import org.drools.process.command.GetEnvironmentCommand;
import org.drools.process.command.GetFactHandleCommand;
+import org.drools.process.command.GetFactHandlesCommand;
import org.drools.process.command.GetGlobalCommand;
import org.drools.process.command.GetGlobalsCommand;
import org.drools.process.command.GetKnowledgeBaseCommand;
import org.drools.process.command.GetObjectCommand;
import org.drools.process.command.GetObjectsCommand;
+import org.drools.process.command.GetProcessEventListenersCommand;
import org.drools.process.command.GetProcessInstanceCommand;
import org.drools.process.command.GetProcessInstancesCommand;
import org.drools.process.command.GetSessionClockCommand;
import org.drools.process.command.GetWorkingMemoryEntryPointCommand;
+import org.drools.process.command.GetWorkingMemoryEventListenersCommand;
import org.drools.process.command.HaltCommand;
import org.drools.process.command.InsertObjectCommand;
+import org.drools.process.command.RegisterExitPointCommand;
import org.drools.process.command.RegisterWorkItemHandlerCommand;
+import org.drools.process.command.RemoveEventListenerCommand;
import org.drools.process.command.RetractCommand;
import org.drools.process.command.SetGlobalCommand;
import org.drools.process.command.SignalEventCommand;
import org.drools.process.command.StartProcessCommand;
+import org.drools.process.command.UnregisterExitPointCommand;
import org.drools.process.command.UpdateCommand;
import org.drools.runtime.Environment;
import org.drools.runtime.ExitPoint;
@@ -52,9 +64,13 @@
implements
StatefulKnowledgeSession {
- private CommandService commandService;
- private transient WorkItemManager workItemManager;
+ private CommandService commandService;
+ private transient WorkItemManager workItemManager;
+ public Map<WorkingMemoryEventListener, WorkingMemoryEventListenerWrapper> mappedWorkingMemoryListeners;
+ public Map<AgendaEventListener, AgendaEventListenerWrapper> mappedAgendaListeners;
+ public Map<ProcessEventListener, ProcessEventListenerWrapper> mappedProcessListeners;
+
public CommandBasedStatefulKnowledgeSession(CommandService commandService) {
this.commandService = commandService;
}
@@ -153,12 +169,12 @@
public void registerExitPoint(String name,
ExitPoint exitPoint) {
- throw new UnsupportedOperationException();
-
+ this.commandService.execute( new RegisterExitPointCommand( name,
+ exitPoint ) );
}
public void unregisterExitPoint(String name) {
- throw new UnsupportedOperationException();
+ this.commandService.execute( new UnregisterExitPointCommand( name ) );
}
@@ -171,12 +187,12 @@
}
public Collection< ? extends FactHandle> getFactHandles() {
- throw new UnsupportedOperationException();
+ return this.commandService.execute( new GetFactHandlesCommand() );
}
public Collection< ? extends FactHandle> getFactHandles(ObjectFilter filter) {
- throw new UnsupportedOperationException();
+ return this.commandService.execute( new GetFactHandlesCommand( filter ) );
}
public Collection< ? > getObjects() {
@@ -228,39 +244,84 @@
}
public void addEventListener(WorkingMemoryEventListener listener) {
- throw new UnsupportedOperationException();
+ WorkingMemoryEventListenerWrapper wrapper = new StatefulKnowledgeSessionImpl.WorkingMemoryEventListenerWrapper( listener );
+
+ this.mappedWorkingMemoryListeners.put( listener,
+ wrapper );
+
+ commandService.execute( new AddEventListenerCommand( wrapper ) );
}
public void addEventListener(AgendaEventListener listener) {
- throw new UnsupportedOperationException();
+ AgendaEventListenerWrapper wrapper = new StatefulKnowledgeSessionImpl.AgendaEventListenerWrapper( listener );
+
+ this.mappedAgendaListeners.put( listener,
+ wrapper );
+
+ commandService.execute( new AddEventListenerCommand( wrapper ) );
}
public Collection<AgendaEventListener> getAgendaEventListeners() {
- throw new UnsupportedOperationException();
+ Collection<org.drools.event.AgendaEventListener> listeners = commandService.execute( new GetAgendaEventListenersCommand() );
+ Collection<AgendaEventListener> result = new ArrayList<AgendaEventListener>();
+
+ for ( org.drools.event.AgendaEventListener listener : listeners ) {
+ AgendaEventListenerWrapper wrapper = (AgendaEventListenerWrapper) listener;
+ result.add( wrapper.unWrap() );
+ }
+
+ return result;
}
public Collection<WorkingMemoryEventListener> getWorkingMemoryEventListeners() {
- throw new UnsupportedOperationException();
+ Collection<org.drools.event.WorkingMemoryEventListener> listeners = commandService.execute( new GetWorkingMemoryEventListenersCommand() );
+ Collection<WorkingMemoryEventListener> result = new ArrayList<WorkingMemoryEventListener>();
+
+ for ( org.drools.event.WorkingMemoryEventListener listener : listeners ) {
+ WorkingMemoryEventListenerWrapper wrapper = (WorkingMemoryEventListenerWrapper) listener;
+ result.add( wrapper.unWrap() );
+ }
+
+ return result;
}
public void removeEventListener(WorkingMemoryEventListener listener) {
- throw new UnsupportedOperationException();
+ WorkingMemoryEventListenerWrapper wrapper = this.mappedWorkingMemoryListeners.remove( listener );
+
+ commandService.execute( new RemoveEventListenerCommand( wrapper ) );
}
public void removeEventListener(AgendaEventListener listener) {
- throw new UnsupportedOperationException();
+ AgendaEventListenerWrapper wrapper = this.mappedAgendaListeners.remove( listener );
+
+ commandService.execute( new RemoveEventListenerCommand( wrapper ) );
}
public void addEventListener(ProcessEventListener listener) {
- throw new UnsupportedOperationException();
+ ProcessEventListenerWrapper wrapper = new StatefulKnowledgeSessionImpl.ProcessEventListenerWrapper( listener );
+
+ this.mappedProcessListeners.put( listener,
+ wrapper );
+
+ commandService.execute( new AddEventListenerCommand( wrapper ) );
}
public Collection<ProcessEventListener> getProcessEventListeners() {
- throw new UnsupportedOperationException();
+ Collection<org.drools.event.RuleFlowEventListener> listeners = commandService.execute( new GetProcessEventListenersCommand() );
+ Collection<ProcessEventListener> result = new ArrayList<ProcessEventListener>();
+
+ for ( org.drools.event.RuleFlowEventListener listener : listeners ) {
+ ProcessEventListenerWrapper wrapper = (ProcessEventListenerWrapper) listener;
+ result.add( wrapper.unWrap() );
+ }
+
+ return result;
}
public void removeEventListener(ProcessEventListener listener) {
- throw new UnsupportedOperationException();
+ WorkingMemoryEventListenerWrapper wrapper = this.mappedWorkingMemoryListeners.remove( listener );
+
+ commandService.execute( new RemoveEventListenerCommand( wrapper ) );
}
public Object getGlobal(String identifier) {
More information about the jboss-svn-commits
mailing list