[jboss-svn-commits] JBL Code SVN: r10807 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/common and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Apr 7 08:06:36 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-04-07 08:06:36 -0400 (Sat, 07 Apr 2007)
New Revision: 10807

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupEvent.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupPoppedEvent.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupPushedEvent.java
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/audit/WorkingMemoryFileLogger.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/audit/WorkingMemoryLogger.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventListener.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/DebugAgendaEventListener.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/DefaultAgendaEventListener.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java
Log:
JBRULES-771 Expose agenda group events
-added support for events on pushed/popped agenda groups with integration test, although still needs unit test.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/audit/WorkingMemoryFileLogger.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/audit/WorkingMemoryFileLogger.java	2007-04-07 12:06:27 UTC (rev 10806)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/audit/WorkingMemoryFileLogger.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -24,6 +24,8 @@
 
 import org.drools.WorkingMemory;
 import org.drools.audit.event.LogEvent;
+import org.drools.event.AgendaGroupPoppedEvent;
+import org.drools.event.AgendaGroupPushedEvent;
 
 import com.thoughtworks.xstream.XStream;
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/audit/WorkingMemoryLogger.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/audit/WorkingMemoryLogger.java	2007-04-07 12:06:27 UTC (rev 10806)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/audit/WorkingMemoryLogger.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -31,6 +31,8 @@
 import org.drools.event.ActivationCreatedEvent;
 import org.drools.event.AfterActivationFiredEvent;
 import org.drools.event.AgendaEventListener;
+import org.drools.event.AgendaGroupPoppedEvent;
+import org.drools.event.AgendaGroupPushedEvent;
 import org.drools.event.BeforeActivationFiredEvent;
 import org.drools.event.ObjectAssertedEvent;
 import org.drools.event.ObjectModifiedEvent;
@@ -268,4 +270,14 @@
         }
         return result.append( "]" ).toString();
     }
+    
+    public void agendaGroupPopped(AgendaGroupPoppedEvent event,
+                                  WorkingMemory workingMemory) {
+        // we don't audit this yet     
+    }
+
+    public void agendaGroupPushed(AgendaGroupPushedEvent event,
+                                  WorkingMemory workingMemory) {
+        // we don't audit this yet        
+    }    
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java	2007-04-07 12:06:27 UTC (rev 10806)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -169,6 +169,10 @@
             this.focusStack.add( agendaGroup );
             return true;
         }
+        
+        final EventSupport eventsupport = (EventSupport) this.workingMemory;
+        eventsupport.getAgendaEventSupport().fireAgendaGroupPushed( agendaGroup );
+        
         return false;
     }
 
@@ -207,6 +211,8 @@
             // No populated queus found so pop the focusStack and repeat            
             if ( empty && (this.focusStack.size() > 1) ) {
                 this.focusStack.removeLast();
+                final EventSupport eventsupport = (EventSupport) this.workingMemory;
+                eventsupport.getAgendaEventSupport().fireAgendaGroupPopped( agendaGroup );                
             } else {
                 agendaGroup = (empty) ? null : agendaGroup;
                 break;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java	2007-04-07 12:06:27 UTC (rev 10806)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -22,7 +22,7 @@
     /**
      * 
      */
-    private static final long serialVersionUID = -3765849430015366508L;
+    private static final long serialVersionUID = 320L;
 
     public ActivationCancelledEvent(final Activation activation) {
         super( activation );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventListener.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventListener.java	2007-04-07 12:06:27 UTC (rev 10806)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventListener.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -23,11 +23,21 @@
 public interface AgendaEventListener
     extends
     EventListener {
-    void activationCreated(ActivationCreatedEvent event, WorkingMemory workingMemory);
+    void activationCreated(ActivationCreatedEvent event,
+                           WorkingMemory workingMemory);
 
-    void activationCancelled(ActivationCancelledEvent event, WorkingMemory workingMemory);
+    void activationCancelled(ActivationCancelledEvent event,
+                             WorkingMemory workingMemory);
 
-    void beforeActivationFired(BeforeActivationFiredEvent event, WorkingMemory workingMemory);
+    void beforeActivationFired(BeforeActivationFiredEvent event,
+                               WorkingMemory workingMemory);
 
-    void afterActivationFired(AfterActivationFiredEvent event, WorkingMemory workingMemory);
+    void afterActivationFired(AfterActivationFiredEvent event,
+                              WorkingMemory workingMemory);
+    
+    void agendaGroupPopped(AgendaGroupPoppedEvent event,
+                           WorkingMemory workingMemory);
+    
+    void agendaGroupPushed(AgendaGroupPushedEvent event,
+                           WorkingMemory workingMemory);    
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java	2007-04-07 12:06:27 UTC (rev 10806)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -23,6 +23,7 @@
 
 import org.drools.WorkingMemory;
 import org.drools.spi.Activation;
+import org.drools.spi.AgendaGroup;
 
 /**
  * @author <a href="mailto:simon at redhillconsulting.com.au">Simon Harris </a>
@@ -63,7 +64,8 @@
         return this.listeners.isEmpty();
     }
 
-    public void fireActivationCreated(final Activation activation, WorkingMemory workingMemory) {
+    public void fireActivationCreated(final Activation activation,
+                                      WorkingMemory workingMemory) {
         if ( this.listeners.isEmpty() ) {
             return;
         }
@@ -71,11 +73,13 @@
         final ActivationCreatedEvent event = new ActivationCreatedEvent( activation );
 
         for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
-            ((AgendaEventListener) this.listeners.get( i )).activationCreated( event, workingMemory );
+            ((AgendaEventListener) this.listeners.get( i )).activationCreated( event,
+                                                                               workingMemory );
         }
     }
 
-    public void fireActivationCancelled(final Activation activation, WorkingMemory workingMemory) {
+    public void fireActivationCancelled(final Activation activation,
+                                        WorkingMemory workingMemory) {
         if ( this.listeners.isEmpty() ) {
             return;
         }
@@ -83,11 +87,13 @@
         final ActivationCancelledEvent event = new ActivationCancelledEvent( activation );
 
         for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
-            ((AgendaEventListener) this.listeners.get( i )).activationCancelled( event, workingMemory );
+            ((AgendaEventListener) this.listeners.get( i )).activationCancelled( event,
+                                                                                 workingMemory );
         }
     }
 
-    public void fireBeforeActivationFired(final Activation activation, WorkingMemory workingMemory) {
+    public void fireBeforeActivationFired(final Activation activation,
+                                          WorkingMemory workingMemory) {
         if ( this.listeners.isEmpty() ) {
             return;
         }
@@ -95,7 +101,8 @@
         final BeforeActivationFiredEvent event = new BeforeActivationFiredEvent( activation );
 
         for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
-            ((AgendaEventListener) this.listeners.get( i )).beforeActivationFired( event, workingMemory );
+            ((AgendaEventListener) this.listeners.get( i )).beforeActivationFired( event,
+                                                                                   workingMemory );
         }
     }
 
@@ -107,7 +114,34 @@
         final AfterActivationFiredEvent event = new AfterActivationFiredEvent( activation );
 
         for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
-            ((AgendaEventListener) this.listeners.get( i )).afterActivationFired( event, workingMemory );
+            ((AgendaEventListener) this.listeners.get( i )).afterActivationFired( event,
+                                                                                  workingMemory );
         }
     }
+    
+    public void fireAgendaGroupPopped(AgendaGroup agendaGroup) {
+        if ( this.listeners.isEmpty() ) {
+            return;
+        }
+
+        final AgendaGroupPoppedEvent event = new AgendaGroupPoppedEvent(agendaGroup);
+
+        for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
+            ((AgendaEventListener) this.listeners.get( i )).agendaGroupPopped( event,
+                                                                               workingMemory );
+        }        
+    }
+    
+    public void fireAgendaGroupPushed(AgendaGroup agendaGroup) {
+        if ( this.listeners.isEmpty() ) {
+            return;
+        }
+
+        final AgendaGroupPushedEvent event = new AgendaGroupPushedEvent(agendaGroup);
+
+        for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
+            ((AgendaEventListener) this.listeners.get( i )).agendaGroupPushed( event,
+                                                                               workingMemory );
+        }        
+    }
 }
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupEvent.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupEvent.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupEvent.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -0,0 +1,38 @@
+package org.drools.event;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.EventObject;
+
+import org.drools.spi.AgendaGroup;
+
+public class AgendaGroupEvent extends EventObject {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 320L;
+
+    public AgendaGroupEvent(final AgendaGroup agendaGroup) {
+        super( agendaGroup );
+    }
+
+    public AgendaGroup getAgendaGroup() {
+        return (AgendaGroup) getSource();
+    }
+
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupPoppedEvent.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupPoppedEvent.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupPoppedEvent.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -0,0 +1,34 @@
+package org.drools.event;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.spi.AgendaGroup;
+
+public class AgendaGroupPoppedEvent extends AgendaGroupEvent {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 320L;
+
+    public AgendaGroupPoppedEvent(final AgendaGroup agendaGroup) {
+        super( agendaGroup );
+    }
+
+    public String toString() {
+        return "<==[AgendaGroupPoppedEvent(" + getAgendaGroup().getName() + "]";
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupPushedEvent.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupPushedEvent.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaGroupPushedEvent.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -0,0 +1,34 @@
+package org.drools.event;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.spi.AgendaGroup;
+
+public class AgendaGroupPushedEvent extends AgendaGroupEvent {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 320L;
+
+    public AgendaGroupPushedEvent(final AgendaGroup agendaGroup) {
+        super( agendaGroup );
+    }
+
+    public String toString() {
+        return ">==[AgendaGroupPushedEvent(" + getAgendaGroup().getName() + "]";
+    }
+}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/DebugAgendaEventListener.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/DebugAgendaEventListener.java	2007-04-07 12:06:27 UTC (rev 10806)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/DebugAgendaEventListener.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -25,20 +25,34 @@
         // intentionally left blank
     }
 
-    public void activationCreated(final ActivationCreatedEvent event, WorkingMemory workingMemory) {
+    public void activationCreated(final ActivationCreatedEvent event,
+                                  WorkingMemory workingMemory) {
         System.err.println( event );
     }
 
-    public void activationCancelled(final ActivationCancelledEvent event, WorkingMemory workingMemory) {
+    public void activationCancelled(final ActivationCancelledEvent event,
+                                    WorkingMemory workingMemory) {
         System.err.println( event );
     }
 
-    public void beforeActivationFired(final BeforeActivationFiredEvent event, WorkingMemory workingMemory) {
+    public void beforeActivationFired(final BeforeActivationFiredEvent event,
+                                      WorkingMemory workingMemory) {
         System.err.println( event );
     }
 
-    public void afterActivationFired(final AfterActivationFiredEvent event, WorkingMemory workingMemory) {
+    public void afterActivationFired(final AfterActivationFiredEvent event,
+                                     WorkingMemory workingMemory) {
         System.err.println( event );
     }
 
+    public void agendaGroupPopped(AgendaGroupPoppedEvent event,
+                                  WorkingMemory workingMemory) {
+        System.err.println( event );
+    }
+
+    public void agendaGroupPushed(AgendaGroupPushedEvent event,
+                                  WorkingMemory workingMemory) {
+        System.err.println( event );
+    }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/DefaultAgendaEventListener.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/DefaultAgendaEventListener.java	2007-04-07 12:06:27 UTC (rev 10806)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/DefaultAgendaEventListener.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -25,19 +25,33 @@
         // intentionally left blank
     }
 
-    public void activationCreated(final ActivationCreatedEvent event, WorkingMemory workingMemory) {
+    public void activationCreated(final ActivationCreatedEvent event,
+                                  WorkingMemory workingMemory) {
         // intentionally left blank
     }
 
-    public void activationCancelled(final ActivationCancelledEvent event, WorkingMemory workingMemory) {
+    public void activationCancelled(final ActivationCancelledEvent event,
+                                    WorkingMemory workingMemory) {
         // intentionally left blank
     }
 
-    public void beforeActivationFired(final BeforeActivationFiredEvent event, WorkingMemory workingMemory) {
+    public void beforeActivationFired(final BeforeActivationFiredEvent event,
+                                      WorkingMemory workingMemory) {
         // intentionally left blank
     }
 
-    public void afterActivationFired(final AfterActivationFiredEvent event, WorkingMemory workingMemory) {
+    public void afterActivationFired(final AfterActivationFiredEvent event,
+                                     WorkingMemory workingMemory) {
         // intentionally left blank
     }
+    
+    public void agendaGroupPopped(AgendaGroupPoppedEvent event,
+                                  WorkingMemory workingMemory) {
+        // intentionally left blank
+    }
+
+    public void agendaGroupPushed(AgendaGroupPushedEvent event,
+                                  WorkingMemory workingMemory) {
+        // intentionally left blank
+    }    
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java	2007-04-07 12:06:27 UTC (rev 10806)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java	2007-04-07 12:06:36 UTC (rev 10807)
@@ -17,7 +17,15 @@
  */
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
 
+import org.drools.Cheese;
+import org.drools.FactHandle;
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.WorkingMemory;
+
 import junit.framework.TestCase;
 
 /**
@@ -28,5 +36,51 @@
         assertTrue( Serializable.class.isAssignableFrom( WorkingMemoryEventSupport.class ) );
     }
 
-    // TODO: Need more tests but I'M tired! Need sleep.
+    public void testWorkingMemoryEventListener() {
+        RuleBase rb = RuleBaseFactory.newRuleBase();
+        WorkingMemory wm = rb.newWorkingMemory();
+
+        final List wmList = new ArrayList();
+        WorkingMemoryEventListener workingMemoryListener = new WorkingMemoryEventListener() {
+
+            public void objectAsserted(ObjectAssertedEvent event) {
+                wmList.add( event );
+            }
+
+            public void objectModified(ObjectModifiedEvent event) {
+                wmList.add( event );
+            }
+
+            public void objectRetracted(ObjectRetractedEvent event) {
+                wmList.add( event );
+            }
+
+        };
+
+        wm.addEventListener( workingMemoryListener );
+
+        Cheese stilton = new Cheese( "stilton",
+                                     15 );
+        Cheese cheddar = new Cheese( "cheddar",
+                                     17 );
+
+        FactHandle stiltonHandle = wm.assertObject( stilton );
+
+        ObjectAssertedEvent oae = (ObjectAssertedEvent) wmList.get( 0 );
+        assertSame( stiltonHandle,
+                    oae.getFactHandle() );
+
+        wm.modifyObject( stiltonHandle,
+                         stilton );
+        ObjectModifiedEvent ome = (ObjectModifiedEvent) wmList.get( 1 );
+        assertSame( stiltonHandle,
+                    ome.getFactHandle() );
+
+        wm.retractObject( stiltonHandle );
+        ObjectRetractedEvent ore = (ObjectRetractedEvent) wmList.get( 2 );
+        assertSame( stiltonHandle,
+                    ore.getFactHandle() );
+
+        wm.assertObject( cheddar );
+    }
 }
\ No newline at end of file




More information about the jboss-svn-commits mailing list