You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by tc...@apache.org on 2005/09/21 22:17:04 UTC

svn commit: r290819 - in /jakarta/commons/sandbox/jci/trunk: ./ src/java/org/apache/commons/jci/ src/java/org/apache/commons/jci/compilers/ src/java/org/apache/commons/jci/compilers/eclipse/ src/java/org/apache/commons/jci/compilers/groovy/ src/java/or...

Author: tcurdt
Date: Wed Sep 21 13:16:41 2005
New Revision: 290819

URL: http://svn.apache.org/viewcvs?rev=290819&view=rev
Log:
for those using it already ...sorry for the big changes :)

no specific distinction between compiling or reload classloader the action is happening inside the listener anyway,
reloading classloader can now serve from multiple stores,

a handler can be set to intercept problems as they occure (if supported by the compiler ...still needs to be used in the impls),
the fam can now be started directly without the need for handling the thread explicitly,
support for chained chained resource transformations


Added:
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/AbstractListener.java
Removed:
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java
Modified:
    jakarta/commons/sandbox/jci/trunk/TODO
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblemHandler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.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
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java

Modified: jakarta/commons/sandbox/jci/trunk/TODO
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/TODO?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/TODO (original)
+++ jakarta/commons/sandbox/jci/trunk/TODO Wed Sep 21 13:16:41 2005
@@ -4,7 +4,7 @@
   o embedded java compiler
   o javac 
   o jikes
-o transformation "pipelines" (more than just one transformation)
 o make suffixes matching (*.java, *.class) configurable
 o turn the JavaCompilerFactory into an interface and maybe provide a simple default impl
 o documentation
+o dependency analysis for proper re-try after errors

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=290819&r1=290818&r2=290819&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 Wed Sep 21 13:16:41 2005
@@ -18,14 +18,7 @@
 import java.io.File;
 import java.io.InputStream;
 import java.net.URL;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import org.apache.commons.jci.listeners.ReloadingListener;
-import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
-import org.apache.commons.jci.readers.FileResourceReader;
-import org.apache.commons.jci.readers.ResourceReader;
-import org.apache.commons.jci.stores.MemoryResourceStore;
+import org.apache.commons.jci.listeners.AbstractListener;
 import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.jci.stores.ResourceStoreClassLoader;
 import org.apache.commons.logging.Log;
@@ -40,37 +33,46 @@
     private final static Log log = LogFactory.getLog(ReloadingClassLoader.class);
     
     private final ClassLoader parent;
-    private final ResourceStore store;
-    private final Collection reloadingListeners = new HashSet();
-
+    //private final Collection reloadingListeners = new HashSet();
+    private ResourceStore[] stores = new ResourceStore[0];
     private ClassLoader delegate;
+    
+    public ReloadingClassLoader(final ClassLoader pParent) {        
+        super(pParent);
+        parent = pParent;        
 
-    protected final ResourceReader reader;
-    protected final File repository;
+        delegate = new ResourceStoreClassLoader(parent, stores);
+    }
 
-    protected FilesystemAlterationMonitor fam;
-    protected Thread thread;
+    public void addListener(final AbstractListener pListener) {
+        pListener.setReloadingClassLoader(this);
+        addResourceStore(pListener.getStore());
+    }
     
-    public ReloadingClassLoader(final ClassLoader pParent, final File pRepository) {
-        this(pParent, pRepository, new MemoryResourceStore());
+    public void removeListener(final AbstractListener pListener) {
+        removeResourceStore(pListener.getStore());
+        pListener.setReloadingClassLoader(null);
+    }
+    
+    private void addResourceStore(final ResourceStore pStore) {
+        final int n = stores.length;
+        final ResourceStore[] newStores = new ResourceStore[n + 1];
+        System.arraycopy(stores, 0, newStores, 0, n);
+        newStores[n] = pStore;
+        stores = newStores;
+        delegate = new ResourceStoreClassLoader(parent, stores);
     }
 
-    public ReloadingClassLoader(final ClassLoader pParent, final File pRepository, final ResourceStore pStore) {        
-        super(pParent);
-
-        parent = pParent;        
-        repository = pRepository;        
-        reader = new FileResourceReader(repository);
-        store = pStore;
-                
-        delegate = new ResourceStoreClassLoader(parent, store);
+    private void removeResourceStore(final ResourceStore pStore) {
+        //FIXME
     }
     
+    /*
     public void start() {
         fam = new FilesystemAlterationMonitor(); 
         fam.addListener(new ReloadingListener(store) {  
-            protected void notifyOfCheck( boolean pReload ) {
-                super.notifyOfCheck(pReload);
+            protected void needsReload( boolean pReload ) {
+                super.needsReload(pReload);
                 if (pReload) {
                     ReloadingClassLoader.this.reload();                    
                 } else {
@@ -78,19 +80,14 @@
                 }
             }
         }, repository);
-        thread = new Thread(fam);         
-        thread.start();
+        fam.start();
     }
-
+    
     public void stop() {
         fam.stop();
-        try {
-            thread.join();
-        } catch (final InterruptedException e) {
-            ;
-        }
     }
-
+    */
+    /*
     public void addListener(final ReloadingClassLoaderListener pListener) {
         synchronized (reloadingListeners) {
             reloadingListeners.add(pListener);
@@ -102,15 +99,18 @@
             return reloadingListeners.remove(pListener);
         }        
     }
-    
-    protected void reload() {
-        log.debug("reloading");
-
-        delegate = new ResourceStoreClassLoader(parent, store);
-        
-        notifyReloadingListeners(true);
+    */
+    public void reload(final boolean pReload) {
+        if (pReload) {
+            log.debug("reloading");
+            delegate = new ResourceStoreClassLoader(parent, stores);
+            //notifyReloadingListeners(true);
+        } else {
+            log.debug("not reloading");
+            //notifyReloadingListeners(false);            
+        }
     }
-    
+    /*
     private void notifyReloadingListeners(final boolean pReload) { 
         synchronized (reloadingListeners) {
             for (final Iterator it = reloadingListeners.iterator(); it.hasNext();) {
@@ -119,7 +119,7 @@
             }            
         }
     }
-    
+    */
     public static String clazzName( final File base, final File file ) {
         final int rootLength = base.getAbsolutePath().length();
         final String absFileName = file.getAbsolutePath();

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java?rev=290819&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java (added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java Wed Sep 21 13:16:41 2005
@@ -0,0 +1,14 @@
+package org.apache.commons.jci.compilers;
+
+import org.apache.commons.jci.problems.CompilationProblemHandler;
+
+
+public abstract class AbstractJavaCompiler implements JavaCompiler {
+
+    protected CompilationProblemHandler problemHandler;
+    
+    public void setCompilationProblemHandler( final CompilationProblemHandler pHandler ) {
+        problemHandler = pHandler;
+    }
+    
+}

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java Wed Sep 21 13:16:41 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.commons.jci.compilers;
 
+import org.apache.commons.jci.problems.CompilationProblemHandler;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
 
@@ -24,7 +25,8 @@
  *
  */
 public interface JavaCompiler {
-    // setCompilationProblemHandler( CompilationProblemHandler pHandler );
+    
+    void setCompilationProblemHandler( final CompilationProblemHandler pHandler );
 
     // addCompilationProblemHandler( CompilationProblemHandler pHandler );
     // removeCompilationProblemHandler( CompilationProblemHandler pHandler );

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java Wed Sep 21 13:16:41 2005
@@ -26,7 +26,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
-import org.apache.commons.jci.compilers.JavaCompiler;
+import org.apache.commons.jci.compilers.AbstractJavaCompiler;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.lang.StringUtils;
@@ -47,7 +47,7 @@
 import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
 import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
 
-public final class EclipseJavaCompiler implements JavaCompiler {
+public final class EclipseJavaCompiler extends AbstractJavaCompiler {
 
     private final static Log log = LogFactory.getLog(EclipseJavaCompiler.class);
     private final EclipseJavaCompilerSettings settings;

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java Wed Sep 21 13:16:41 2005
@@ -5,8 +5,8 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import org.apache.commons.jci.compilers.AbstractJavaCompiler;
 import org.apache.commons.jci.compilers.CompilationResult;
-import org.apache.commons.jci.compilers.JavaCompiler;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.logging.Log;
@@ -20,7 +20,7 @@
 import org.codehaus.groovy.control.messages.WarningMessage;
 import org.codehaus.groovy.tools.GroovyClass;
 
-public final class GroovyJavaCompiler implements JavaCompiler {
+public final class GroovyJavaCompiler extends AbstractJavaCompiler {
 
     private final static Log log = LogFactory.getLog(GroovyJavaCompiler.class);
     

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java Wed Sep 21 13:16:41 2005
@@ -25,8 +25,8 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import org.apache.commons.jci.compilers.AbstractJavaCompiler;
 import org.apache.commons.jci.compilers.CompilationResult;
-import org.apache.commons.jci.compilers.JavaCompiler;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
@@ -51,7 +51,7 @@
 /**
  * @author art@gramlich-net.com
  */
-public final class JaninoJavaCompiler implements JavaCompiler {
+public final class JaninoJavaCompiler extends AbstractJavaCompiler {
 
     private final static Log log = LogFactory.getLog(JaninoJavaCompiler.class);
 

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/AbstractListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/AbstractListener.java?rev=290819&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/AbstractListener.java (added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/AbstractListener.java Wed Sep 21 13:16:41 2005
@@ -0,0 +1,31 @@
+package org.apache.commons.jci.listeners;
+
+import java.io.File;
+import org.apache.commons.jci.ReloadingClassLoader;
+import org.apache.commons.jci.monitor.FilesystemAlterationListener;
+import org.apache.commons.jci.stores.ResourceStore;
+
+
+public abstract class AbstractListener implements FilesystemAlterationListener {
+
+    protected final File repository;
+    protected ReloadingClassLoader reloader;
+
+    public AbstractListener(final File pRepository) {
+        repository = pRepository;        
+    }
+
+    public void setReloadingClassLoader(final ReloadingClassLoader pReloader) {
+        reloader = pReloader;
+    }
+    
+    public abstract ResourceStore getStore();
+    
+    public File getRepository() {
+        return repository;
+    }
+
+    protected void needsReload( final boolean pReload ) {
+        reloader.reload(pReload);
+    }
+}

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java Wed Sep 21 13:16:41 2005
@@ -22,15 +22,18 @@
 import org.apache.commons.jci.ReloadingClassLoader;
 import org.apache.commons.jci.compilers.CompilationResult;
 import org.apache.commons.jci.compilers.JavaCompiler;
-import org.apache.commons.jci.monitor.FilesystemAlterationListener;
+import org.apache.commons.jci.compilers.eclipse.EclipseJavaCompiler;
 import org.apache.commons.jci.problems.CompilationProblem;
+import org.apache.commons.jci.readers.FileResourceReader;
 import org.apache.commons.jci.readers.ResourceReader;
+import org.apache.commons.jci.stores.MemoryResourceStore;
+import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.jci.stores.TransactionalResourceStore;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 
-public class CompilingListener implements FilesystemAlterationListener {
+public class CompilingListener extends AbstractListener {
 
     private final static Log log = LogFactory.getLog(CompilingListener.class);
     
@@ -43,29 +46,42 @@
     private final TransactionalResourceStore transactionalStore;
     private CompilationResult lastResult;
     
+    public CompilingListener( final File pRepository ) {
+        this(pRepository,
+             new EclipseJavaCompiler(),
+             new TransactionalResourceStore(new MemoryResourceStore())
+             );
+    }
+    
     public CompilingListener(
-            final ResourceReader pReader,
+            final File pRepository,
             final JavaCompiler pCompiler,
             final TransactionalResourceStore pTransactionalStore
             ) {
+        super(pRepository);
         compiler = pCompiler;
-        reader = pReader;
         transactionalStore = pTransactionalStore;
+
+        reader = new FileResourceReader(pRepository);
         lastResult = null;
     }
     
+    public ResourceStore getStore() {
+        return transactionalStore;
+    }
+
     public synchronized CompilationResult getCompilationResult() {
         return lastResult;
     }
     
-    public void onStart(final File pRepository) {
+    public void onStart() {
         created.clear();
         changed.clear();
         deleted.clear();
         transactionalStore.onStart();
     }
-    public void onStop(final File pRepository) {
-        log.debug("resources " +
+    public void onStop() {
+        log.debug(
                 created.size() + " created, " + 
                 changed.size() + " changed, " + 
                 deleted.size() + " deleted");
@@ -75,7 +91,7 @@
         if (deleted.size() > 0) {
             for (Iterator it = deleted.iterator(); it.hasNext();) {
                 final File file = (File) it.next();
-                transactionalStore.remove(ReloadingClassLoader.clazzName(pRepository, file));
+                transactionalStore.remove(ReloadingClassLoader.clazzName(repository, file));
             }
             reload = true;
         }
@@ -92,7 +108,7 @@
             int i = 0;
             for (Iterator it = compileables.iterator(); it.hasNext();) {
                 final File file = (File) it.next();
-                clazzes[i] = ReloadingClassLoader.clazzName(pRepository, file);
+                clazzes[i] = ReloadingClassLoader.clazzName(repository, file);
                 i++;
             }
             
@@ -116,6 +132,7 @@
                     );
         
             if (errors.length > 0) {
+                // FIXME: they need to be marked for re-compilation
                 for (int j = 0; j < clazzes.length; j++) {
                     transactionalStore.remove(clazzes[j]);
                 }
@@ -126,9 +143,7 @@
 
         transactionalStore.onStop();
 
-        if (reload) {
-            reload();
-        }                
+        needsReload(reload);
     }
 
     public void onCreateFile( final File file ) {
@@ -155,9 +170,5 @@
     public void onChangeDirectory( final File file ) {                
     }
     public void onDeleteDirectory( final File file ) {
-    }
-
-    protected void reload() {
-        log.debug("reload");
     }
 }

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=290819&r1=290818&r2=290819&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 Wed Sep 21 13:16:41 2005
@@ -22,13 +22,13 @@
 import java.util.Iterator;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.jci.ReloadingClassLoader;
-import org.apache.commons.jci.monitor.FilesystemAlterationListener;
+import org.apache.commons.jci.stores.MemoryResourceStore;
 import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 
-public class ReloadingListener implements FilesystemAlterationListener{
+public class ReloadingListener extends AbstractListener{
 
     private final static Log log = LogFactory.getLog(ReloadingListener.class);
 
@@ -38,16 +38,25 @@
 
     private final ResourceStore store;
     
-    public ReloadingListener(final ResourceStore pStore) {
-        store = pStore;        
+    public ReloadingListener(final File pRepository) {
+        this(pRepository, new MemoryResourceStore());
+    }
+
+    public ReloadingListener(final File pRepository, final ResourceStore pStore) {
+        super(pRepository);
+        store = pStore;
+    }
+
+    public ResourceStore getStore() {
+        return store;
     }
     
-    public void onStart(final File repository) {
+    public void onStart() {
         created.clear();
         changed.clear();
         deleted.clear();
     }
-    public void onStop(final File pRepository) {
+    public void onStop() {
         boolean reload = false;
         
         log.debug("created:" + created.size()
@@ -57,7 +66,7 @@
         if (deleted.size() > 0) {
             for (Iterator it = deleted.iterator(); it.hasNext();) {
                 final File file = (File) it.next();
-                store.remove(ReloadingClassLoader.clazzName(pRepository, file));
+                store.remove(ReloadingClassLoader.clazzName(repository, file));
             }
             reload = true;
         }
@@ -67,11 +76,13 @@
                 final File file = (File) it.next();
                 try {
                     final byte[] bytes = IOUtils.toByteArray(new FileReader(file));
-                    store.write(ReloadingClassLoader.clazzName(pRepository, file), bytes);
+                    store.write(ReloadingClassLoader.clazzName(repository, file), bytes);
                 } catch(final Exception e) {
                     log.error("could not load " + file, e);
                 }
             }
+            // FIXME: not necessary
+            //reload = true;
         }
 
         if (changed.size() > 0) {
@@ -79,7 +90,7 @@
                 final File file = (File) it.next();
                 try {
                     final byte[] bytes = IOUtils.toByteArray(new FileReader(file));
-                    store.write(ReloadingClassLoader.clazzName(pRepository, file), bytes);
+                    store.write(ReloadingClassLoader.clazzName(repository, file), bytes);
                 } catch(final Exception e) {
                     log.error("could not load " + file, e);
                 }
@@ -87,7 +98,7 @@
             reload = true;
         }
 
-        notifyOfCheck(reload);
+        needsReload(reload);
     }
 
     public void onCreateFile( final File file ) {
@@ -116,11 +127,4 @@
     public void onDeleteDirectory( final File file ) {
     }
 
-    protected void notifyOfCheck(final boolean pReload) {
-        if (pReload) {
-            log.debug("reload required");
-        } else {
-            log.debug("no reload required");            
-        }
-    }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java Wed Sep 21 13:16:41 2005
@@ -22,12 +22,13 @@
  *
  */
 public interface FilesystemAlterationListener {
-    void onStart( final File repository );
+    File getRepository();
+    void onStart();
     void onCreateFile( final File file );
     void onChangeFile( final File file );
     void onDeleteFile( final File file );
     void onCreateDirectory( final File dir );
     void onChangeDirectory( final File dir );
     void onDeleteDirectory( final File dir );
-    void onStop( final File repository );
+    void onStop();
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java Wed Sep 21 13:16:41 2005
@@ -1,17 +1,10 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * 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.
+ * Copyright 1999-2004 The Apache Software Foundation. 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.
  */
 package org.apache.commons.jci.monitor;
 
@@ -125,6 +118,7 @@
             return file;
         }
 
+
         public void markNotChanged() {
             lastModified = file.lastModified();
         }
@@ -138,38 +132,49 @@
     private Map listeners = new MultiHashMap();
     private Map directories = new MultiHashMap();
     private Map entries = new HashMap();
-
     private final Object mutexListeners = new Object();
     private final Object mutexRunning = new Object();
-    
     private long delay = 3000;
     private boolean running = true;
-    
+    private Thread thread;
+
+
     public FilesystemAlterationMonitor() {
     }
 
+
+    public void start() {
+        thread = new Thread(this);
+        thread.start();
+    }
+
+
     public void stop() {
-        synchronized(mutexRunning) {
+        synchronized (mutexRunning) {
             running = false;
         }
+        try {
+            thread.join(delay);
+        } catch (InterruptedException e) {
+        }
     }
-    
+
+
     public void setInterval( final long pDelay ) {
         delay = pDelay;
     }
 
 
-    public void addListener( final FilesystemAlterationListener listener, final File directory ) {
+    public void addListener( final FilesystemAlterationListener pListener ) {
+        final File directory = pListener.getRepository();
         synchronized (mutexListeners) {
             // listerner -> dir1, dir2, dir3
-
             final MultiHashMap newListeners = new MultiHashMap(listeners);
-            newListeners.put(listener, directory);
+            newListeners.put(pListener, directory);
             listeners = newListeners;
-            
             // directory -> listener1, listener2, listener3
             final MultiHashMap newDirectories = new MultiHashMap(directories);
-            newDirectories.put(directory, listener);
+            newDirectories.put(directory, pListener);
             directories = newDirectories;
         }
     }
@@ -181,7 +186,6 @@
             final MultiHashMap newListeners = new MultiHashMap(listeners);
             Collection d = (Collection) newListeners.remove(listener);
             listeners = newListeners;
-
             if (d != null) {
                 // directory -> listener1, listener2, listener3
                 final MultiHashMap newDirectories = new MultiHashMap(directories);
@@ -190,135 +194,129 @@
                     entries.remove(d);
                 }
                 directories = newDirectories;
-            }            
+            }
         }
     }
 
+
     private void onStart( final File root ) {
         log.debug("start checking " + root);
-
         Map directories;
-        synchronized(mutexListeners) {
+        synchronized (mutexListeners) {
             directories = this.directories;
         }
         final Collection l = (Collection) directories.get(root);
         if (l != null) {
             for (Iterator it = l.iterator(); it.hasNext();) {
-                final FilesystemAlterationListener listener = (FilesystemAlterationListener) it.next();
-                listener.onStart(root);
-            }            
+                final FilesystemAlterationListener listener = (FilesystemAlterationListener) it
+                        .next();
+                listener.onStart();
+            }
         }
     }
 
 
     private void onStop( final File root ) {
         log.debug("stop checking " + root);
-                
         Map directories;
-        synchronized(mutexListeners) {
+        synchronized (mutexListeners) {
             directories = this.directories;
         }
         final Collection l = (Collection) directories.get(root);
         if (l != null) {
             for (Iterator it = l.iterator(); it.hasNext();) {
-                final FilesystemAlterationListener listener = (FilesystemAlterationListener) it.next();
-                listener.onStop(root);
-            }            
+                final FilesystemAlterationListener listener = (FilesystemAlterationListener) it
+                        .next();
+                listener.onStop();
+            }
         }
     }
 
 
     private void onCreate( final File root, final Entry entry ) {
-        
-        log.debug("created " + ((entry.isDirectory())?"dir ":"file ") + entry);
-        
+        log.debug("created " + ((entry.isDirectory()) ? "dir " : "file ") + entry);
         Map directories;
-        synchronized(mutexListeners) {
+        synchronized (mutexListeners) {
             directories = this.directories;
         }
-
         final Collection l = (Collection) directories.get(root);
         if (l != null) {
             if (entry.isDirectory()) {
                 for (Iterator it = l.iterator(); it.hasNext();) {
-                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it.next();
+                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it
+                            .next();
                     listener.onCreateDirectory(entry.getFile());
                 }
             } else {
                 for (Iterator it = l.iterator(); it.hasNext();) {
-                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it.next();
+                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it
+                            .next();
                     listener.onCreateFile(entry.getFile());
                 }
             }
         }
-
         entry.markNotChanged();
     }
 
 
     private void onChange( final File root, final Entry entry ) {
-        
-        log.debug("changed " + ((entry.isDirectory())?"dir ":"file ") + entry);
-        
+        log.debug("changed " + ((entry.isDirectory()) ? "dir " : "file ") + entry);
         Map directories;
-        synchronized(mutexListeners) {
+        synchronized (mutexListeners) {
             directories = this.directories;
         }
-
         final Collection l = (Collection) directories.get(root);
         if (l != null) {
             if (entry.isDirectory()) {
                 for (Iterator it = l.iterator(); it.hasNext();) {
-                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it.next();
+                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it
+                            .next();
                     listener.onChangeDirectory(entry.getFile());
                 }
             } else {
                 for (Iterator it = l.iterator(); it.hasNext();) {
-                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it.next();
+                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it
+                            .next();
                     listener.onChangeFile(entry.getFile());
                 }
             }
         }
-
         entry.markNotChanged();
     }
 
 
     private void onDelete( final File root, final Entry entry ) {
-        
-        log.debug("deleted " + ((entry.isDirectory())?"dir ":"file ") + entry);
-        
+        log.debug("deleted " + ((entry.isDirectory()) ? "dir " : "file ") + entry);
         Map directories;
-        synchronized(mutexListeners) {
+        synchronized (mutexListeners) {
             directories = this.directories;
         }
-
         final Collection l = (Collection) directories.get(root);
         if (l != null) {
             if (entry.isDirectory()) {
                 for (Iterator it = l.iterator(); it.hasNext();) {
-                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it.next();
+                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it
+                            .next();
                     listener.onDeleteDirectory(entry.getFile());
                 }
             } else {
                 for (Iterator it = l.iterator(); it.hasNext();) {
-                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it.next();
+                    final FilesystemAlterationListener listener = (FilesystemAlterationListener) it
+                            .next();
                     listener.onDeleteFile(entry.getFile());
                 }
             }
         }
-
         entry.markNotChanged();
     }
 
 
     private void check( final File root, final Entry entry, final boolean create ) {
-        //log.debug("checking " + entry);
-        
+        // log.debug("checking " + entry);
         if (entry.isDirectory()) {
             final Entry[] currentChilds = entry.getChilds();
             if (entry.hasChanged() || create) {
-                //log.debug(entry + " has changed");
+                // log.debug(entry + " has changed");
                 if (!create) {
                     onChange(root, entry);
                     for (int i = 0; i < currentChilds.length; i++) {
@@ -347,7 +345,7 @@
                     check(root, child, true);
                 }
             } else {
-                //log.debug(entry + " has not changed");
+                // log.debug(entry + " has not changed");
                 for (int i = 0; i < currentChilds.length; i++) {
                     final Entry child = currentChilds[i];
                     check(root, child, false);
@@ -365,43 +363,34 @@
 
     public void run() {
         log.info("fam running");
-        
         while (true) {
-            
-            synchronized(mutexRunning) {
+            synchronized (mutexRunning) {
                 if (!running) {
                     break;
                 }
             }
-            
             Map directories;
-            
             synchronized (mutexListeners) {
                 directories = this.directories;
             }
-
             for (Iterator it = directories.keySet().iterator(); it.hasNext();) {
                 final File directory = (File) it.next();
                 if (directory.exists()) {
                     onStart(directory);
-                    
                     Entry root;
                     synchronized (mutexListeners) {
-                        root = (Entry)entries.get(directory);
+                        root = (Entry) entries.get(directory);
                         if (root == null) {
                             root = new Entry(directory, directory);
                             entries.put(directory, root);
                         }
                     }
-                    
                     check(directory, root, false);
                     onStop(directory);
                 }
             }
-
             ThreadUtils.sleep(delay);
         }
-        
         log.info("fam exiting");
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblemHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblemHandler.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblemHandler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblemHandler.java Wed Sep 21 13:16:41 2005
@@ -21,7 +21,5 @@
  *
  */
 public interface CompilationProblemHandler {
-    void onStart();
     void handle( final CompilationProblem pProblem );
-    void onStop();
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java Wed Sep 21 13:16:41 2005
@@ -28,27 +28,35 @@
 
     private final static Log log = LogFactory.getLog(ResourceStoreClassLoader.class);
 
-    private final ResourceStore store;
+    private final ResourceStore[] stores;
     private final ClassLoader parent;
 
-    public ResourceStoreClassLoader( final ClassLoader pParent, final ResourceStore pStore ) {
+    public ResourceStoreClassLoader( final ClassLoader pParent, final ResourceStore[] pStores ) {
         super(pParent);
         parent = pParent;
-        store = pStore;
+        stores = pStores;
     }
 
     private Class fastFindClass(final String name) {
-        final byte[] clazzBytes = store.read(name);
         
-        if (clazzBytes != null) {
-            log.debug("found class " + name  + " (" + clazzBytes.length + " bytes)");
-            return defineClass(name, clazzBytes, 0, clazzBytes.length);
+        if (stores != null) {
+            for (int i = 0; i < stores.length; i++) {
+                final ResourceStore store = stores[i];
+                final byte[] clazzBytes = store.read(name);
+                if (clazzBytes != null) {
+                    log.debug("found class " + name  + " (" + clazzBytes.length + " bytes)");
+                    return defineClass(name, clazzBytes, 0, clazzBytes.length);
+                }            
+            }
         }
         
+        log.debug("did not find class " + name);
+        
         return null;            
     }
     
     protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
+        log.debug("looking for " + name);
         Class clazz = findLoadedClass(name);
 
         if (clazz == null) {

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=290819&r1=290818&r2=290819&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 Wed Sep 21 13:16:41 2005
@@ -4,6 +4,8 @@
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
 import org.apache.commons.jci.compilers.JavaSources;
+import org.apache.commons.jci.listeners.CompilingListener;
+import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -14,26 +16,30 @@
     
     private final Signal reloadSignal = new Signal();
 
-    private CompilingClassLoader cl;
-    private ReloadingClassLoaderListener listener;
+    private ReloadingClassLoader classloader;
+    private CompilingListener listener;
+    private FilesystemAlterationMonitor fam;
     
     protected void setUp() throws Exception {
         super.setUp();
         
-        listener = new ReloadingClassLoaderListener() {
-            public void hasChecked() {
-            }
-            public void hasReloaded(boolean pReload) {
-                synchronized(reloadSignal) {
-                    reloadSignal.triggered = true;
-                    reloadSignal.notify();
+        classloader = new ReloadingClassLoader(this.getClass().getClassLoader());
+        listener = new CompilingListener(directory) {
+            protected void needsReload(final boolean pReload) {
+                super.needsReload(pReload);
+                if (pReload) {
+                    synchronized(reloadSignal) {
+                        reloadSignal.triggered = true;
+                        reloadSignal.notify();
+                    }
                 }
-            }
-        };
-
-        cl = new CompilingClassLoader(this.getClass().getClassLoader(), directory);
-        cl.addListener(listener);
-        cl.start();
+            }  
+        };        
+        classloader.addListener(listener);
+        
+        fam = new FilesystemAlterationMonitor();
+        fam.addListener(listener);
+        fam.start();
     }
 
     private void initialCompile() throws Exception {
@@ -55,51 +61,51 @@
     public void testCreate() throws Exception {
         initialCompile();
         
-        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        final Object simple = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));
         
-        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+        final Object extended = classloader.loadClass("jci.Extended").newInstance();        
         assertTrue("Extended:Simple".equals(extended.toString()));
     }
 
     public void testChange() throws Exception {        
         initialCompile();
 
-        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        final Object simple = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));
         
-        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+        final Object extended = classloader.loadClass("jci.Extended").newInstance();        
         assertTrue("Extended:Simple".equals(extended.toString()));
 
         delay();
         writeFile("jci/Simple.java", JavaSources.SIMPLE);
         waitForSignal(reloadSignal);
     
-        final Object SIMPLE = cl.loadClass("jci.Simple").newInstance();        
+        final Object SIMPLE = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("SIMPLE".equals(SIMPLE.toString()));
         
-        final Object newExtended = cl.loadClass("jci.Extended").newInstance();        
+        final Object newExtended = classloader.loadClass("jci.Extended").newInstance();        
         assertTrue("Extended:SIMPLE".equals(newExtended.toString()));
     }
 
     public void testDelete() throws Exception {
         initialCompile();
 
-        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        final Object simple = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));
         
-        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+        final Object extended = classloader.loadClass("jci.Extended").newInstance();        
         assertTrue("Extended:Simple".equals(extended.toString()));
         
         delay();
         assertTrue(new File(directory, "jci/Extended.java").delete());
         waitForSignal(reloadSignal);
 
-        final Object oldSimple = cl.loadClass("jci.Simple").newInstance();        
+        final Object oldSimple = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(oldSimple.toString()));
 
         try {
-            cl.loadClass("jci.Extended").newInstance();
+            classloader.loadClass("jci.Extended").newInstance();
             fail();
         } catch(final ClassNotFoundException e) {
             assertTrue("jci.Extended".equals(e.getMessage()));
@@ -110,7 +116,7 @@
         waitForSignal(reloadSignal);
 
         try {
-            cl.loadClass("jci.Simple").newInstance();
+            classloader.loadClass("jci.Simple").newInstance();
             fail();
         } catch(final ClassNotFoundException e) {
             assertTrue("jci.Simple".equals(e.getMessage()));
@@ -121,10 +127,10 @@
     public void testDeleteDependency() throws Exception {        
         initialCompile();
 
-        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        final Object simple = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));
         
-        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+        final Object extended = classloader.loadClass("jci.Extended").newInstance();        
         assertTrue("Extended:Simple".equals(extended.toString()));
         
         delay();
@@ -132,7 +138,7 @@
         waitForSignal(reloadSignal);
 
         try {
-            cl.loadClass("jci.Extended").newInstance();
+            classloader.loadClass("jci.Extended").newInstance();
             fail();
         } catch(final NoClassDefFoundError e) {
             assertTrue("jci/Simple".equals(e.getMessage()));
@@ -141,8 +147,8 @@
     }
 
     protected void tearDown() throws Exception {
-        cl.removeListener(listener);
-        cl.stop();
+        fam.removeListener(listener);
+        fam.stop();
         super.tearDown();
     }
     

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=290819&r1=290818&r2=290819&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 Wed Sep 21 13:16:41 2005
@@ -17,6 +17,8 @@
 
 import java.io.File;
 import org.apache.commons.jci.compilers.JavaSources;
+import org.apache.commons.jci.listeners.ReloadingListener;
+import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -28,8 +30,9 @@
     private final Signal reloadSignal = new Signal();
     private final Signal checkedSignal = new Signal();
 
-    private ReloadingClassLoader cl;
-    private ReloadingClassLoaderListener listener;
+    private ReloadingClassLoader classloader;
+    private ReloadingListener listener;
+    private FilesystemAlterationMonitor fam;
 
     private final byte[] clazzSimple;
     private final byte[] clazzSIMPLE;
@@ -50,8 +53,10 @@
     protected void setUp() throws Exception {
         super.setUp();
         
-        listener = new ReloadingClassLoaderListener() {
-            public void hasReloaded( final boolean pReload ) {                
+        classloader = new ReloadingClassLoader(this.getClass().getClassLoader());
+        listener = new ReloadingListener(directory) {
+            protected void needsReload(final boolean pReload) {
+                super.needsReload(pReload);
                 if (pReload) {
                     synchronized(reloadSignal) {
                         reloadSignal.triggered = true;
@@ -63,13 +68,13 @@
                         checkedSignal.notify();
                     }
                 }
-            }
-
+            }  
         };
-
-        cl = new ReloadingClassLoader(this.getClass().getClassLoader(), directory);
-        cl.addListener(listener);
-        cl.start();
+        classloader.addListener(listener);
+        
+        fam = new FilesystemAlterationMonitor();
+        fam.addListener(listener);
+        fam.start();
     }
 
     public void testCreate() throws Exception {
@@ -81,7 +86,7 @@
         writeFile("jci/Simple.class", clazzSimple);
         waitForSignal(checkedSignal);
         
-        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        final Object simple = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));        
     }
 
@@ -94,7 +99,7 @@
         writeFile("jci/Simple.class", clazzSimple);
         waitForSignal(checkedSignal);
 
-        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        final Object simple = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));
         
         log.debug("changing class");
@@ -103,7 +108,7 @@
         writeFile("jci/Simple.class", clazzSIMPLE);
         waitForSignal(reloadSignal);
     
-        final Object SIMPLE = cl.loadClass("jci.Simple").newInstance();        
+        final Object SIMPLE = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("SIMPLE".equals(SIMPLE.toString()));        
     }
 
@@ -116,7 +121,7 @@
         writeFile("jci/Simple.class", clazzSimple);
         waitForSignal(checkedSignal);
 
-        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        final Object simple = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));
 
         log.debug("deleting class");
@@ -126,7 +131,7 @@
         waitForSignal(reloadSignal);
 
         try {
-            cl.loadClass("jci.Simple").newInstance();        
+            classloader.loadClass("jci.Simple").newInstance();        
             fail();
         } catch(final ClassNotFoundException e) {
             assertTrue("jci.Simple".equals(e.getMessage()));
@@ -143,10 +148,10 @@
         writeFile("jci/Extended.class", clazzExtended);
         waitForSignal(checkedSignal);
 
-        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        final Object simple = classloader.loadClass("jci.Simple").newInstance();        
         assertTrue("Simple".equals(simple.toString()));
         
-        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+        final Object extended = classloader.loadClass("jci.Extended").newInstance();        
         assertTrue("Extended:Simple".equals(extended.toString()));
 
         log.debug("deleting class dependency");
@@ -156,7 +161,7 @@
         waitForSignal(reloadSignal);
 
         try {
-            cl.loadClass("jci.Extended").newInstance();
+            classloader.loadClass("jci.Extended").newInstance();
             fail();
         } catch(final NoClassDefFoundError e) {
             assertTrue("jci/Simple".equals(e.getMessage()));
@@ -165,7 +170,7 @@
 
     public void testClassNotFound() {
         try {
-            cl.loadClass("bla");
+            classloader.loadClass("bla");
             fail();
         } catch(final ClassNotFoundException e) {
             log.info(e.getMessage());
@@ -173,16 +178,16 @@
     }
     
     public void testDelegation() {
-        cl.clearAssertionStatus();
-        cl.setClassAssertionStatus("org.apache.commons.jci.ReloadingClassLoader",true);
-        cl.setDefaultAssertionStatus(false);
-        cl.setPackageAssertionStatus("org.apache.commons.jci", true);
+        classloader.clearAssertionStatus();
+        classloader.setClassAssertionStatus("org.apache.commons.jci.ReloadingClassLoader",true);
+        classloader.setDefaultAssertionStatus(false);
+        classloader.setPackageAssertionStatus("org.apache.commons.jci", true);
         // FIXME: compare with delegation
     }
     
     protected void tearDown() throws Exception {
-        cl.removeListener(listener);
-        cl.stop();
+        fam.removeListener(listener);
+        fam.stop();
         super.tearDown();
     }
     

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java?rev=290819&r1=290818&r2=290819&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java Wed Sep 21 13:16:41 2005
@@ -18,6 +18,8 @@
 import java.io.File;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.jci.AbstractTestCase;
+import org.apache.commons.jci.listeners.AbstractListener;
+import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -31,9 +33,8 @@
 
     private FilesystemAlterationMonitor fam;
     private MyFilesystemAlterationListener listener;
-    private Thread thread; 
 
-    private class MyFilesystemAlterationListener implements FilesystemAlterationListener {
+    private class MyFilesystemAlterationListener extends AbstractListener {
         private int started;
         private int stopped;
         private int createdFiles;
@@ -43,6 +44,18 @@
         private int changedDirs;
         private int deletedDirs;
  
+        public MyFilesystemAlterationListener(final File pRepository) {
+            super(pRepository);
+        }
+        
+        public ResourceStore getStore() {
+            return null;
+        }
+
+        protected void needsReload( boolean pReload ) {
+            // prevent NPE
+        }
+
         public int getChangedDirs() {
             return changedDirs;
         }
@@ -68,10 +81,10 @@
             return stopped;
         }
                  
-        public void onStart(final File repository) {
+        public void onStart() {
             ++started;
         }
-        public void onStop(final File repository) {
+        public void onStop() {
             ++stopped;
             synchronized(signal) {
                 signal.triggered = true;
@@ -98,19 +111,16 @@
         }       
     }
 
-    private void start() throws Exception {
+    private void start() {
         fam = new FilesystemAlterationMonitor();
-        listener = new MyFilesystemAlterationListener();        
-        fam.addListener(listener, directory);
-        thread = new Thread(fam); 
-        thread.start();
-
+        listener = new MyFilesystemAlterationListener(directory);
+        fam.addListener(listener);
+        fam.start();
         waitForSignal(signal);
     }
     
-    private void stop() throws Exception {
+    private void stop() {
         fam.stop();
-        thread.join();        
     }
     
     public void testCreateFileDetection() throws Exception {



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