commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r232868 - in /jakarta/commons/sandbox/jci/trunk/src: java/org/apache/commons/jci/ java/org/apache/commons/jci/listeners/ test/org/apache/commons/jci/
Date Mon, 15 Aug 2005 20:26:46 GMT
Author: tcurdt
Date: Mon Aug 15 13:26:37 2005
New Revision: 232868

URL: http://svn.apache.org/viewcvs?rev=232868&view=rev
Log:
distinguish between reload and check


Modified:
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java?rev=232868&r1=232867&r2=232868&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
Mon Aug 15 13:26:37 2005
@@ -68,22 +68,25 @@
     
     public void start() {
         fam = new FilesystemAlterationMonitor(); 
-        fam.addListener(new ReloadingListener(store) {
-            public void reload() {
-                super.reload();
-                ReloadingClassLoader.this.reload();
-            }            
+        fam.addListener(new ReloadingListener(store) {  
+            protected void notifyAboutCheck( boolean pReload ) {
+                super.notifyAboutCheck(pReload);
+                if (pReload) {
+                    ReloadingClassLoader.this.reload();                    
+                } else {
+                    ReloadingClassLoader.this.notifyReloadingListeners(false);          
         
+                }
+            }
         }, repository);
         thread = new Thread(fam);         
         thread.start();
-        reload();        
     }
 
     public void stop() {
         fam.stop();
         try {
             thread.join();
-        } catch (InterruptedException e) {
+        } catch (final InterruptedException e) {
             ;
         }
     }
@@ -102,12 +105,17 @@
     
     protected void reload() {
         log.debug("reloading");
-        delegate = new ResourceStoreClassLoader(parent, store);
 
+        delegate = new ResourceStoreClassLoader(parent, store);
+        
+        notifyReloadingListeners(true);
+    }
+    
+    private void notifyReloadingListeners(final boolean pReload) { 
         synchronized (reloadingListeners) {
             for (final Iterator it = reloadingListeners.iterator(); it.hasNext();) {
                 final ReloadingClassLoaderListener listener = (ReloadingClassLoaderListener)
it.next();
-                listener.hasReloaded();
+                listener.hasReloaded(pReload);
             }            
         }
     }
@@ -116,11 +124,8 @@
         final int rootLength = base.getAbsolutePath().length();
         final String absFileName = file.getAbsolutePath();
         final int p = absFileName.lastIndexOf('.');
-        final String relFileName = absFileName.substring(
-                rootLength + 1,
-                p
-                );
-        final String clazzName = relFileName.replace(File.separatorChar,'.');
+        final String relFileName = absFileName.substring(rootLength + 1, p);
+        final String clazzName = relFileName.replace(File.separatorChar, '.');
         return clazzName;
     }
 

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java?rev=232868&r1=232867&r2=232868&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
Mon Aug 15 13:26:37 2005
@@ -20,5 +20,5 @@
  * @author tcurdt
  */
 public interface ReloadingClassLoaderListener {
-    void hasReloaded();
+    void hasReloaded(final boolean pReload);
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java?rev=232868&r1=232867&r2=232868&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java
Mon Aug 15 13:26:37 2005
@@ -48,9 +48,12 @@
         deleted.clear();
     }
     public void onStop(final File pRepository) {
-
         boolean reload = false;
         
+        log.debug("created:" + created.size()
+               + " changed:" + changed.size()
+               + " deleted:" + deleted.size());
+        
         if (deleted.size() > 0) {
             for (Iterator it = deleted.iterator(); it.hasNext();) {
                 final File file = (File) it.next();
@@ -69,9 +72,6 @@
                     log.error("could not load " + file, e);
                 }
             }
-            // FIXME only required to make the wait in the testcases
-            // work. should be replace with a wait inside the fam
-            reload = true;
         }
 
         if (changed.size() > 0) {
@@ -87,9 +87,7 @@
             reload = true;
         }
 
-        if (reload) {
-            reload();
-        }                
+        notifyAboutCheck(reload);
     }
 
     public void onCreateFile( final File file ) {
@@ -115,7 +113,11 @@
     public void onDeleteDirectory( final File file ) {
     }
 
-    protected void reload() {        
-        log.debug("reload");
+    protected void notifyAboutCheck(final boolean pReload) {
+        if (pReload) {
+            log.debug("reload required");
+        } else {
+            log.debug("no reload required");            
+        }
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java?rev=232868&r1=232867&r2=232868&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
Mon Aug 15 13:26:37 2005
@@ -12,7 +12,7 @@
 
     private final static Log log = LogFactory.getLog(CompilingClassLoaderTestCase.class);
     
-    private final Signal reload = new Signal();
+    private final Signal reloadSignal = new Signal();
 
     private CompilingClassLoader cl;
     private ReloadingClassLoaderListener listener;
@@ -21,10 +21,12 @@
         super.setUp();
         
         listener = new ReloadingClassLoaderListener() {
-            public void hasReloaded() {
-                synchronized(reload) {
-                    reload.triggered = true;
-                    reload.notify();
+            public void hasChecked() {
+            }
+            public void hasReloaded(boolean pReload) {
+                synchronized(reloadSignal) {
+                    reloadSignal.triggered = true;
+                    reloadSignal.notify();
                 }
             }
         };
@@ -38,14 +40,14 @@
         delay();        
         writeFile("jci/Simple.java", Programs.simple);        
         writeFile("jci/Extended.java", Programs.extended);        
-        waitForSignal(reload);
+        waitForSignal(reloadSignal);
     }
     
     
     public void testCompileProblems() throws Exception {
         delay();        
         writeFile("jci/Simple.java", Programs.error);
-        waitForSignal(reload);
+        waitForSignal(reloadSignal);
         
         // FIXME
     }
@@ -71,7 +73,7 @@
 
         delay();
         writeFile("jci/Simple.java", Programs.SIMPLE);
-        waitForSignal(reload);
+        waitForSignal(reloadSignal);
     
         final Object SIMPLE = cl.loadClass("jci.Simple").newInstance();        
         assertTrue("SIMPLE".equals(SIMPLE.toString()));
@@ -91,7 +93,7 @@
         
         delay();
         assertTrue(new File(directory, "jci/Extended.java").delete());
-        waitForSignal(reload);
+        waitForSignal(reloadSignal);
 
         final Object oldSimple = cl.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(oldSimple.toString()));
@@ -105,7 +107,7 @@
         
         delay();
         FileUtils.deleteDirectory(new File(directory, "jci"));
-        waitForSignal(reload);
+        waitForSignal(reloadSignal);
 
         try {
             cl.loadClass("jci.Simple").newInstance();
@@ -127,7 +129,7 @@
         
         delay();
         assertTrue(new File(directory, "jci/Simple.java").delete());
-        waitForSignal(reload);
+        waitForSignal(reloadSignal);
 
         try {
             cl.loadClass("jci.Extended").newInstance();

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java?rev=232868&r1=232867&r2=232868&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
Mon Aug 15 13:26:37 2005
@@ -25,7 +25,8 @@
 
     private final static Log log = LogFactory.getLog(ReloadingClassLoaderTestCase.class);
     
-    private final Signal reload = new Signal();
+    private final Signal reloadSignal = new Signal();
+    private final Signal checkedSignal = new Signal();
 
     private ReloadingClassLoader cl;
     private ReloadingClassLoaderListener listener;
@@ -50,12 +51,20 @@
         super.setUp();
         
         listener = new ReloadingClassLoaderListener() {
-            public void hasReloaded() {
-                synchronized(reload) {
-                    reload.triggered = true;
-                    reload.notify();
+            public void hasReloaded( final boolean pReload ) {                
+                if (pReload) {
+                    synchronized(reloadSignal) {
+                        reloadSignal.triggered = true;
+                        reloadSignal.notify();
+                    }
+                } else {
+                    synchronized(checkedSignal) {
+                        checkedSignal.triggered = true;
+                        checkedSignal.notify();
+                    }
                 }
             }
+
         };
 
         cl = new ReloadingClassLoader(this.getClass().getClassLoader(), directory);
@@ -64,26 +73,26 @@
     }
 
     public void testCreate() throws Exception {
-        waitForSignal(reload);
+        waitForSignal(checkedSignal);
 
         log.debug("creating class");
         
         delay();
         writeFile("jci/Simple.class", clazzSimple);
-        waitForSignal(reload);
+        waitForSignal(checkedSignal);
         
         final Object simple = cl.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));        
     }
 
     public void testChange() throws Exception {        
-        waitForSignal(reload);
+        waitForSignal(checkedSignal);
 
         log.debug("creating class");
 
         delay();        
         writeFile("jci/Simple.class", clazzSimple);
-        waitForSignal(reload);
+        waitForSignal(checkedSignal);
 
         final Object simple = cl.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));
@@ -92,20 +101,20 @@
         
         delay();        
         writeFile("jci/Simple.class", clazzSIMPLE);
-        waitForSignal(reload);
+        waitForSignal(reloadSignal);
     
         final Object SIMPLE = cl.loadClass("jci.Simple").newInstance();        
         assertTrue("SIMPLE".equals(SIMPLE.toString()));        
     }
 
     public void testDelete() throws Exception {
-        waitForSignal(reload);
+        waitForSignal(checkedSignal);
 
         log.debug("creating class");
 
         delay();        
         writeFile("jci/Simple.class", clazzSimple);
-        waitForSignal(reload);
+        waitForSignal(checkedSignal);
 
         final Object simple = cl.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));
@@ -114,7 +123,7 @@
         
         assertTrue(new File(directory, "jci/Simple.class").delete());
         
-        waitForSignal(reload);
+        waitForSignal(reloadSignal);
 
         try {
             cl.loadClass("jci.Simple").newInstance();        



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message