[jboss-svn-commits] JBL Code SVN: r25871 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/agent and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Mar 29 04:37:15 EDT 2009


Author: mark.proctor at jboss.com
Date: 2009-03-29 04:37:14 -0400 (Sun, 29 Mar 2009)
New Revision: 25871

Modified:
   labs/jbossrules/trunk/drools-compiler/.classpath
   labs/jbossrules/trunk/drools-compiler/pom.xml
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/KnowledgeAgentTest.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/UrlResource.java
Log:
-fixed resource concurrent modification issues
-upgraded jetty, which was having problems with HEAD request messages.

Modified: labs/jbossrules/trunk/drools-compiler/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-compiler/.classpath	2009-03-29 06:22:59 UTC (rev 25870)
+++ labs/jbossrules/trunk/drools-compiler/.classpath	2009-03-29 08:37:14 UTC (rev 25871)
@@ -15,9 +15,9 @@
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.15/janino-2.5.15.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty/6.1.9/jetty-6.1.9.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty-embedded/6.1.9/jetty-embedded-6.1.9.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty-util/6.1.9/jetty-util-6.1.9.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty/6.1.15/jetty-6.1.15.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty-embedded/6.1.15/jetty-embedded-6.1.15.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty-util/6.1.15/jetty-util-6.1.15.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jmock/jmock/2.5.1/jmock-2.5.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jmock/jmock-legacy/2.5.1/jmock-legacy-2.5.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/joda-time/joda-time/1.6/joda-time-1.6.jar"/>
@@ -25,7 +25,7 @@
   <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mvel/mvel2/2.0.8-SNAPSHOT/mvel2-2.0.8-SNAPSHOT.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/objenesis/objenesis/1.0/objenesis-1.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/servlet-api-2.5/6.1.9/servlet-api-2.5-6.1.9.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/servlet-api/2.5-20081211/servlet-api-2.5-20081211.jar"/>
   <classpathentry kind="var" path="M2_REPO/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar"/>
 </classpath>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-compiler/pom.xml	2009-03-29 06:22:59 UTC (rev 25870)
+++ labs/jbossrules/trunk/drools-compiler/pom.xml	2009-03-29 08:37:14 UTC (rev 25871)
@@ -51,7 +51,7 @@
 		<dependency>
 			<groupId>org.mortbay.jetty</groupId>
 			<artifactId>jetty-embedded</artifactId>
-			<version>6.1.9</version>
+			<version>6.1.15</version>
 			<scope>test</scope>
 		</dependency>					
 	</dependencies>

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/KnowledgeAgentTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/KnowledgeAgentTest.java	2009-03-29 06:22:59 UTC (rev 25870)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/KnowledgeAgentTest.java	2009-03-29 08:37:14 UTC (rev 25871)
@@ -7,10 +7,14 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 import junit.framework.TestCase;
 
@@ -51,6 +55,7 @@
 
         server.start();
     }
+    
 
     protected void tearDown() throws Exception {
         fileManager.tearDown();
@@ -61,8 +66,6 @@
         server.stop();
     }
     
-    public void testDummy() {}
-    
     public void  testModifyFileUrl() throws Exception {
         String rule1 = "";
         rule1 += "package org.drools.test\n";
@@ -73,7 +76,6 @@
         rule1 += "list.add( drools.getRule().getName() );\n";
         rule1 += "end\n";
         File f1 = fileManager.newFile( "rule1.drl" );
-        f1.deleteOnExit();
         Writer output = new BufferedWriter( new FileWriter( f1 ) );
         output.write( rule1 );
         output.close();
@@ -87,7 +89,6 @@
         rule2 += "list.add( drools.getRule().getName() );\n";
         rule2 += "end\n";
         File f2 = fileManager.newFile( "rule2.drl" );
-        f2.deleteOnExit();
         output = new BufferedWriter( new FileWriter( f2 ) );
         output.write( rule2 );
         output.close();
@@ -102,7 +103,6 @@
         xml += "    </add> ";
         xml += "</change-set>";
         File fxml = fileManager.newFile( "changeset.xml" );
-        fxml.deleteOnExit();
         output = new BufferedWriter( new FileWriter( fxml ) );
         output.write( xml );
         output.close();
@@ -210,7 +210,6 @@
         xml += "    </add> ";
         xml += "</change-set>";
         File fxml = fileManager.newFile( "changeset.xml" );
-        fxml.deleteOnExit();
         Writer output = new BufferedWriter( new FileWriter( fxml ) );
         output.write( xml );
         output.close();
@@ -443,7 +442,6 @@
         xml += "    </add> ";
         xml += "</change-set>";
         File fxml = fileManager.newFile( "changeset.xml" );
-        fxml.deleteOnExit();
         Writer output = new BufferedWriter( new FileWriter( fxml ) );
         output.write( xml );
         output.close();
@@ -494,7 +492,6 @@
         rule1 += "list.add( drools.getRule().getName() );\n";
         rule1 += "end\n";
         File f1 = fileManager.newFile( "rule1.drl" );
-        f1.deleteOnExit();
         Writer output = new BufferedWriter( new FileWriter( f1 ) );
         output.write( rule1 );
         output.close();
@@ -508,7 +505,6 @@
         rule2 += "list.add( drools.getRule().getName() );\n";
         rule2 += "end\n";
         File f2 = fileManager.newFile( "rule2.drl" );
-        f2.deleteOnExit();
         output = new BufferedWriter( new FileWriter( f2 ) );
         output.write( rule2 );
         output.close();
@@ -523,7 +519,6 @@
         xml += "    </add> ";
         xml += "</change-set>";
         File fxml = fileManager.newFile( "changeset.xml" );
-        fxml.deleteOnExit();
         output = new BufferedWriter( new FileWriter( fxml ) );
         output.write( xml );
         output.close();

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java	2009-03-29 06:22:59 UTC (rev 25870)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java	2009-03-29 08:37:14 UTC (rev 25871)
@@ -8,6 +8,7 @@
 
 /**
  * drools.agent.scanResources = <true|false>
+ * drools.agent.scanDirectories = <true|false>
  * drools.agent.newInstance = <true|false>
  * drools.agent.monitorChangeSetEvents = <true|false>
  *

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 06:22:59 UTC (rev 25870)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java	2009-03-29 08:37:14 UTC (rev 25871)
@@ -123,74 +123,77 @@
 
     public void processChangeSet(ChangeSet changeSet,
                                  ChangeSetState changeSetState) {
-        for ( Resource resource : changeSet.getResourcesAdded() ) {
-            if ( ((InternalResource) resource).isDirectory() ) {
-                this.resourceDirectories.add( resource );
-                this.listener.debug( "KnowledgeAgent subscribing to directory=" + resource );
-                this.notifier.subscribeResourceChangeListener( this,
-                                                               resource );
-                // if it's a dir, subscribe it's children first
-                for ( Resource child : ((InternalResource) resource).listResources() ) {
-                    if ( ((InternalResource) child).isDirectory() ) {
-                        continue; // ignore sub directories
+        synchronized ( this.resources ) {
+            
+            for ( Resource resource : changeSet.getResourcesAdded() ) {
+                if ( ((InternalResource) resource).isDirectory() ) {
+                    this.resourceDirectories.add( resource );
+                    this.listener.debug( "KnowledgeAgent subscribing to directory=" + resource );
+                    this.notifier.subscribeResourceChangeListener( this,
+                                                                   resource );
+                    // if it's a dir, subscribe it's children first
+                    for ( Resource child : ((InternalResource) resource).listResources() ) {
+                        if ( ((InternalResource) child).isDirectory() ) {
+                            continue; // ignore sub directories
+                        }
+                        ((InternalResource) child).setResourceType( ((InternalResource) resource).getResourceType() );
+                        ResourceMapping mapping = this.resources.get( child );
+                        if ( mapping == null ) {
+                            this.listener.debug( "KnowledgeAgent subscribing to directory content resource=" + child );
+                            this.notifier.subscribeResourceChangeListener( this,
+                                                                           child );
+                            mapping = new ResourceMapping( child );
+                            this.resources.put( child,
+                                                mapping );
+                        }
                     }
-                    ((InternalResource) child).setResourceType( ((InternalResource) resource).getResourceType() );
-                    ResourceMapping mapping = this.resources.get( child );
+                } else {
+                    if ( ((InternalResource) resource).getResourceType() == ResourceType.PKG ) {
+                        changeSetState.pkgs.add( resource );
+                    } else if ( ((InternalResource) resource).getResourceType() == ResourceType.CHANGE_SET ) {
+                        // @TODO
+                        continue;
+                    }
+    
+                    ResourceMapping mapping = this.resources.get( resource );
                     if ( mapping == null ) {
-                        this.listener.debug( "KnowledgeAgent subscribing to directory content resource=" + child );
+                        this.listener.debug( "KnowledgeAgent subscribing to resource=" + resource );
                         this.notifier.subscribeResourceChangeListener( this,
-                                                                       child );
-                        mapping = new ResourceMapping( child );
-                        this.resources.put( child,
+                                                                       resource );
+                        mapping = new ResourceMapping( resource );
+                        this.resources.put( resource,
                                             mapping );
                     }
                 }
-            } else {
-                if ( ((InternalResource) resource).getResourceType() == ResourceType.PKG ) {
-                    changeSetState.pkgs.add( resource );
-                } else if ( ((InternalResource) resource).getResourceType() == ResourceType.CHANGE_SET ) {
-                    // @TODO
-                    continue;
+            }
+    
+            for ( Resource resource : changeSet.getResourcesRemoved() ) {
+                if ( ((InternalResource) resource).getResourceType() == ResourceType.CHANGE_SET ) {
+                    processChangeSet( resource,
+                                      changeSetState );
+                } else if ( changeSetState.scanDirectories && ((InternalResource) resource).isDirectory() ) {
+                    this.listener.debug( "KnowledgeAgent unsubscribing from directory resource=" + resource );
+                    this.resourceDirectories.remove( resource );
+                    this.notifier.unsubscribeResourceChangeListener( this,
+                                                                     resource );
+                } else {
+                    this.listener.debug( "KnowledgeAgent unsubscribing from resource=" + resource );
+                    this.resources.remove( resource );
+                    this.notifier.unsubscribeResourceChangeListener( this,
+                                                                     resource );
                 }
-
-                ResourceMapping mapping = this.resources.get( resource );
-                if ( mapping == null ) {
-                    this.listener.debug( "KnowledgeAgent subscribing to resource=" + resource );
-                    this.notifier.subscribeResourceChangeListener( this,
-                                                                   resource );
-                    mapping = new ResourceMapping( resource );
-                    this.resources.put( resource,
-                                        mapping );
+            }
+    
+            // are we going to need kbuilder to build these resources?
+            for ( Resource resource : this.resources.keySet() ) {
+                this.listener.debug( "KnowledgeAgent ChangeSet requires KnowledgeBuilder" );
+                if ( ((InternalResource) resource).getResourceType() != ResourceType.CHANGE_SET && ((InternalResource) resource).getResourceType() != ResourceType.PKG ) {
+                    changeSetState.needsKnowledgeBuilder = true;
+                    break;
                 }
             }
         }
 
-        for ( Resource resource : changeSet.getResourcesRemoved() ) {
-            if ( ((InternalResource) resource).getResourceType() == ResourceType.CHANGE_SET ) {
-                processChangeSet( resource,
-                                  changeSetState );
-            } else if ( changeSetState.scanDirectories && ((InternalResource) resource).isDirectory() ) {
-                this.listener.debug( "KnowledgeAgent unsubscribing from directory resource=" + resource );
-                this.resourceDirectories.remove( resource );
-                this.notifier.unsubscribeResourceChangeListener( this,
-                                                                 resource );
-            } else {
-                this.listener.debug( "KnowledgeAgent unsubscribing from resource=" + resource );
-                this.resources.remove( resource );
-                this.notifier.unsubscribeResourceChangeListener( this,
-                                                                 resource );
-            }
-        }
-
-        // are we going to need kbuilder to build these resources?
-        for ( Resource resource : this.resources.keySet() ) {
-            this.listener.debug( "KnowledgeAgent ChangeSet requires KnowledgeBuilder" );
-            if ( ((InternalResource) resource).getResourceType() != ResourceType.CHANGE_SET && ((InternalResource) resource).getResourceType() != ResourceType.PKG ) {
-                changeSetState.needsKnowledgeBuilder = true;
-                break;
-            }
-        }
-
     }
 
     public ChangeSet getChangeSet(Resource resource) {

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java	2009-03-29 06:22:59 UTC (rev 25870)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java	2009-03-29 08:37:14 UTC (rev 25871)
@@ -36,7 +36,7 @@
         this.queue = new LinkedBlockingQueue<ChangeSet>();
         this.listener.info( "ResourceChangeNotification created" );
     }
-    
+
     public void setSystemEventListener(SystemEventListener listener) {
         this.listener = listener;
     }
@@ -198,22 +198,18 @@
     }
 
     public void start() {
-        if ( this.processChangeSet == null ) {
-            this.processChangeSet = new ProcessChangeSet( this.queue,
-                                                          this,
-                                                          this.listener );
-        }
+        this.processChangeSet = new ProcessChangeSet( this.queue,
+                                                      this,
+                                                      this.listener );
 
-        if ( !this.processChangeSet.isRunning() ) {
-            this.processChangeSet.setNotify( true );
-            this.thread = new Thread( this.processChangeSet );
-            this.thread.start();
-        }
+        this.thread = new Thread( this.processChangeSet );
+        this.thread.start();
     }
 
     public void stop() {
-        this.processChangeSet.setNotify( false );
+        this.processChangeSet.stop();
         this.thread.interrupt();
+        this.processChangeSet = null;
     }
 
     private Thread           thread;
@@ -233,10 +229,11 @@
             this.queue = queue;
             this.notifier = notifier;
             this.listener = listener;
+            this.notify = true;
         }
 
-        public void setNotify(boolean notify) {
-            this.notify = notify;
+        public void stop() {
+            this.notify = false;
         }
 
         public boolean isRunning() {
@@ -256,7 +253,7 @@
                     exception = e;
                 }
                 Thread.yield();
-                if ( this.notify && exception != null) {
+                if ( this.notify && exception != null ) {
                     this.listener.exception( new RuntimeException( "ResourceChangeNotification ChangeSet publication thread was interrupted, but shutdown was not scheduled",
                                                                    exception ) );
                 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java	2009-03-29 06:22:59 UTC (rev 25870)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java	2009-03-29 08:37:14 UTC (rev 25871)
@@ -25,30 +25,28 @@
     private Map<Resource, Set<ResourceChangeNotifier>> resources;
     private Set<Resource>                              directories;
     private SystemEventListener                        listener;
+    private int                                        interval;
 
     public ResourceChangeScannerImpl() {
         this.listener = SystemEventListenerFactory.getSystemEventListener();
         this.resources = new HashMap<Resource, Set<ResourceChangeNotifier>>();
         this.directories = new HashSet<Resource>();
-        this.scannerScheduler = new ProcessChangeSet( this.resources,
-                                                      this,
-                                                      this.listener );
-        setInterval( 60 );
+        this.interval = 60;
         this.listener.info( "ResourceChangeScanner created with default interval=60" );
     }
-    
+
     public void setSystemEventListener(SystemEventListener listener) {
         this.listener = listener;
-    }    
+    }
 
     public void configure(ResourceChangeScannerConfiguration configuration) {
-        setInterval( ((ResourceChangeScannerConfigurationImpl) configuration).getInterval() );
-        this.listener.info( "ResourceChangeScanner reconfigured with interval=" + ( getInterval() ) );
-        
+        this.interval = ((ResourceChangeScannerConfigurationImpl) configuration).getInterval();
+        this.listener.info( "ResourceChangeScanner reconfigured with interval=" + getInterval() );
+
         // restart it if it's already running.
-        if ( this.scannerScheduler.isRunning() ) {
+        if ( this.scannerScheduler != null && this.scannerScheduler.isRunning() ) {
             stop();
-            start();           
+            start();
         }
     }
 
@@ -194,24 +192,34 @@
     }
 
     public void setInterval(int interval) {
-        this.scannerScheduler.setInterval( interval );
+        this.interval = interval;
+        this.listener.info( "ResourceChangeScanner reconfigured with interval=" + getInterval() );
+
+        if ( this.scannerScheduler != null && this.scannerScheduler.isRunning() ) {
+            stop();
+            start();
+        }
     }
 
     public int getInterval() {
-        return this.scannerScheduler.getInterval();
+        return this.interval;
     }
 
     public void start() {
-        if ( !this.scannerScheduler.isRunning() ) {
-            this.scannerScheduler.setScan( true );
-            thread = new Thread( this.scannerScheduler );
-            thread.start();
-        }
+        this.scannerScheduler = new ProcessChangeSet( this.resources,
+                                                      this,
+                                                      this.listener,
+                                                      this.interval );
+        thread = new Thread( this.scannerScheduler );
+        thread.start();
     }
 
     public void stop() {
-        this.scannerScheduler.setScan( false );
-        this.thread.interrupt();
+        if ( this.scannerScheduler != null && this.scannerScheduler.isRunning() ) {
+            this.scannerScheduler.stop();
+            this.thread.interrupt();
+            this.scannerScheduler = null;
+        }
     }
 
     public void reset() {
@@ -233,22 +241,21 @@
 
         ProcessChangeSet(Map<Resource, Set<ResourceChangeNotifier>> resources,
                          ResourceChangeScannerImpl scanner,
-                         SystemEventListener listener) {
+                         SystemEventListener listener,
+                         int interval) {
             this.resources = resources;
             this.scanner = scanner;
             this.listener = listener;
-        }
-
-        public void setInterval(long interval) {
             this.interval = interval;
+            this.scan = true;
         }
 
         public int getInterval() {
             return (int) this.interval;
         }
 
-        public void setScan(boolean scan) {
-            this.scan = scan;
+        public void stop() {
+            this.scan = false;
         }
 
         public boolean isRunning() {
@@ -263,7 +270,7 @@
                 while ( this.scan ) {
                     Exception exception = null;
                     //System.out.println( "BEFORE : sync this.resources" );
-                    synchronized ( this.resources ) {      
+                    synchronized ( this.resources ) {
                         //System.out.println( "DURING : sync this.resources" );
                         // lock the resources, as we don't want this modified while processing
                         this.scanner.scan();
@@ -275,10 +282,10 @@
                     } catch ( InterruptedException e ) {
                         exception = e;
                     }
-                    
-                    if ( this.scan && exception != null) {
-                        this.listener.exception( new RuntimeException( "ResourceChangeNotification ChangeSet scanning thread was interrupted, but shutdown was not scheduled",
-                                                                       exception ) );                        
+
+                    if ( this.scan && exception != null ) {
+                        this.listener.exception( new RuntimeException( "ResourceChangeNotification ChangeSet scanning thread was interrupted, but shutdown was not requested",
+                                                                       exception ) );
                     }
                 }
                 this.listener.info( "ResourceChangeNotification scanner has stopped" );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/UrlResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/UrlResource.java	2009-03-29 06:22:59 UTC (rev 25870)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/UrlResource.java	2009-03-29 08:37:14 UTC (rev 25871)
@@ -126,7 +126,7 @@
                 if ( conn instanceof HttpURLConnection ) {
                     ((HttpURLConnection) conn).setRequestMethod( "HEAD" );
                 }
-                long date = conn.getLastModified();
+                long date =  conn.getHeaderFieldDate("Last-Modified", 0); //conn.getLastModified(); to keep mic happy :)
                 return date;
             }
         } catch ( IOException e ) {




More information about the jboss-svn-commits mailing list