[jboss-svn-commits] JBL Code SVN: r25872 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Mar 29 04:49:38 EDT 2009


Author: mark.proctor at jboss.com
Date: 2009-03-29 04:49:38 -0400 (Sun, 29 Mar 2009)
New Revision: 25872

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java
Log:
-some improvements to the KnowledgeAgent's service.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java	2009-03-29 08:37:14 UTC (rev 25871)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java	2009-03-29 08:49:38 UTC (rev 25872)
@@ -463,35 +463,28 @@
     }
 
     public void monitorResourceChangeEvents(boolean monitor) {
-        if ( this.changeSetNotificationDetector == null ) {
-            if ( monitor ) {
-                // we are going to start the monitor, so initialise it
-                this.changeSetNotificationDetector = new ChangeSetNotificationDetector( this,
-                                                                                        this.queue,
-                                                                                        this.listener );
-            } else if ( this.changeSetNotificationDetector == null ) {
-                // do nothing, we aren't starting the monitor and the monitorResourceChangeEvents field is null
-                return;
-            }
-        }
-
-        if ( !this.changeSetNotificationDetector.monitor && monitor ) {
-            // If the thread is not running and we are trying to start it, we must create a new Thread
-            this.thread = new Thread( this.changeSetNotificationDetector );
-            this.changeSetNotificationDetector.monitor = true;
-            this.thread.start();
-        } else {
+        
+        if ( !monitor && this.changeSetNotificationDetector != null) {
+            // we are running, but it wants to stop
             // this will stop the thread
-            this.changeSetNotificationDetector.monitor = false;
+            this.changeSetNotificationDetector.stop();
             this.thread.interrupt();
+            this.changeSetNotificationDetector = null;
+        } else if ( monitor && this.changeSetNotificationDetector == null ) {
+            this.changeSetNotificationDetector = new ChangeSetNotificationDetector( this,
+                                                                                    this.queue,
+                                                                                    this.listener );
+            this.thread = new Thread( this.changeSetNotificationDetector );
+            this.thread.start();
         }
+
     }
 
     public static class ChangeSetNotificationDetector
         implements
         Runnable {
         private LinkedBlockingQueue<ChangeSet> queue;
-        public volatile boolean                monitor;
+        private volatile boolean                monitor;
         private KnowledgeAgentImpl             kagent;
         private SystemEventListener            listener;
 
@@ -501,7 +494,12 @@
             this.queue = queue;
             this.kagent = kagent;
             this.listener = listener;
+            this.monitor = true;
         }
+        
+        public void stop() {
+            this.monitor = false;
+        }
 
         public void run() {
             if ( this.monitor ) {




More information about the jboss-svn-commits mailing list