You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2014/03/31 18:12:55 UTC

svn commit: r1583363 - in /felix/trunk/fileinstall/src: main/java/org/apache/felix/fileinstall/internal/ test/java/org/apache/felix/fileinstall/internal/

Author: gnodet
Date: Mon Mar 31 16:12:55 2014
New Revision: 1583363

URL: http://svn.apache.org/r1583363
Log:
[FELIX-4474] Remove the static fields on FileInstall

Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
    felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java?rev=1583363&r1=1583362&r2=1583363&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java (original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java Mon Mar 31 16:12:55 2014
@@ -114,6 +114,8 @@ public class DirectoryWatcher extends Th
 
     final File javaIoTmpdir = new File(System.getProperty("java.io.tmpdir"));
 
+    final FileInstall fileInstall;
+
     Map<String, String> properties;
     File watchedDirectory;
     File tmpDir;
@@ -152,9 +154,10 @@ public class DirectoryWatcher extends Th
     // which may result in an attempt to start the watched bundles
     private AtomicBoolean stateChanged = new AtomicBoolean();
 
-    public DirectoryWatcher(Map<String, String> properties, BundleContext context)
+    public DirectoryWatcher(FileInstall fileInstall, Map<String, String> properties, BundleContext context)
     {
         super("fileinstall-" + getThreadName(properties));
+        this.fileInstall = fileInstall;
         this.properties = properties;
         this.context = context;
         poll = getLong(properties, POLL, 2000);
@@ -251,13 +254,13 @@ public class DirectoryWatcher extends Th
     {
         // We must wait for FileInstall to complete initialisation
         // to avoid race conditions observed in FELIX-2791
-        synchronized (FileInstall.barrier)
+        synchronized (fileInstall.barrier)
         {
-            while (!FileInstall.initialized)
+            while (!fileInstall.initialized)
             {
                 try
                 {
-                    FileInstall.barrier.wait(0);
+                    fileInstall.barrier.wait(0);
                 }
                 catch (InterruptedException e)
                 {
@@ -357,7 +360,7 @@ public class DirectoryWatcher extends Th
 
     private void process(Set<File> files) throws InterruptedException
     {
-        List<ArtifactListener> listeners = FileInstall.getListeners();
+        List<ArtifactListener> listeners = fileInstall.getListeners();
         List<Artifact> deleted = new ArrayList<Artifact>();
         List<Artifact> modified = new ArrayList<Artifact>();
         List<Artifact> created = new ArrayList<Artifact>();
@@ -1040,7 +1043,7 @@ public class DirectoryWatcher extends Th
             // Find a listener for this artifact if needed
             if (artifact.getListener() == null)
             {
-                artifact.setListener(findListener(path, FileInstall.getListeners()));
+                artifact.setListener(findListener(path, fileInstall.getListeners()));
             }
             // Forget this artifact
             removeArtifact(path);

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java?rev=1583363&r1=1583362&r2=1583363&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java (original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java Mon Mar 31 16:12:55 2014
@@ -52,14 +52,14 @@ import org.osgi.util.tracker.ServiceTrac
  */
 public class FileInstall implements BundleActivator, ServiceTrackerCustomizer
 {
-    static Runnable cmSupport;
-    static final Map<ServiceReference, ArtifactListener> listeners = new TreeMap<ServiceReference, ArtifactListener>();
-    static final BundleTransformer bundleTransformer = new BundleTransformer();
+    Runnable cmSupport;
+    final Map<ServiceReference, ArtifactListener> listeners = new TreeMap<ServiceReference, ArtifactListener>();
+    final BundleTransformer bundleTransformer = new BundleTransformer();
     BundleContext context;
     final Map<String, DirectoryWatcher> watchers = new HashMap<String, DirectoryWatcher>();
     ServiceTracker listenersTracker;
-    static boolean initialized;
-    static final Object barrier = new Object();
+    boolean initialized;
+    final Object barrier = new Object();
     ServiceRegistration urlHandlerRegistration;
 
     public void start(BundleContext context) throws Exception
@@ -222,7 +222,7 @@ public class FileInstall implements Bund
         {
             watcher.close();
         }
-        watcher = new DirectoryWatcher(properties, context);
+        watcher = new DirectoryWatcher(this, properties, context);
         watcher.setDaemon(true);
         synchronized (watchers)
         {
@@ -281,7 +281,7 @@ public class FileInstall implements Bund
         }
     }
 
-    static List<ArtifactListener> getListeners()
+    List<ArtifactListener> getListeners()
     {
         synchronized (listeners)
         {

Modified: felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java?rev=1583363&r1=1583362&r2=1583363&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java (original)
+++ felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java Mon Mar 31 16:12:55 2014
@@ -70,7 +70,7 @@ public class DirectoryWatcherTest extend
     {
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
         assertEquals( "getLong gives the default value for non-existing properties", 100, dw.getLong( props, TEST, 100 ) );
         EasyMock.verify(mockBundleContext);
     }
@@ -82,7 +82,7 @@ public class DirectoryWatcherTest extend
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
         assertEquals( "getLong retrieves the right property value", 33, dw.getLong( props, TEST, 100 ) );
         EasyMock.verify(mockBundleContext);
     }
@@ -94,7 +94,7 @@ public class DirectoryWatcherTest extend
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
         assertEquals( "getLong retrieves the right property value", 100, dw.getLong( props, TEST, 100 ) );
         EasyMock.verify(mockBundleContext);
     }
@@ -104,7 +104,7 @@ public class DirectoryWatcherTest extend
     {
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
         assertEquals( "getBoolean gives the default value for non-existing properties", true, dw.getBoolean( props, TEST, true ) );
         EasyMock.verify(mockBundleContext);
     }
@@ -116,7 +116,7 @@ public class DirectoryWatcherTest extend
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
         assertEquals( "getBoolean retrieves the right property value", true, dw.getBoolean( props, TEST, false ) );
         EasyMock.verify(mockBundleContext);
     }
@@ -128,7 +128,7 @@ public class DirectoryWatcherTest extend
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
         assertEquals( "getBoolean retrieves the right property value", false, dw.getBoolean( props, TEST, true ) );
         EasyMock.verify(mockBundleContext);
     }
@@ -138,7 +138,7 @@ public class DirectoryWatcherTest extend
     {
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
         assertEquals( "getFile gives the default value for non-existing properties", new File("tmp"), dw.getFile( props, TEST, new File("tmp") ) );
         EasyMock.verify(mockBundleContext);
     }
@@ -150,7 +150,7 @@ public class DirectoryWatcherTest extend
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
         assertEquals( "getBoolean retrieves the right property value", new File("test"), dw.getFile( props, TEST, new File("tmp") ) );
         EasyMock.verify(mockBundleContext);
     }
@@ -168,7 +168,7 @@ public class DirectoryWatcherTest extend
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
 
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
 
         assertEquals( "POLL parameter correctly read", 500l, dw.poll );
         assertEquals( "LOG_LEVEL parameter correctly read", 1, dw.logLevel );
@@ -189,7 +189,7 @@ public class DirectoryWatcherTest extend
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
         EasyMock.replay(mockBundleContext);
 
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
 
         assertTrue( "DIR parameter correctly read", dw.watchedDirectory.getAbsolutePath().endsWith(
             "src" + File.separatorChar + "test" + File.separatorChar + "resources" ) );
@@ -212,7 +212,7 @@ public class DirectoryWatcherTest extend
                 .andReturn(BundleRevision.TYPE_FRAGMENT);
        EasyMock.replay(mockBundleContext, mockBundle, mockBundleRevision);
 
-        dw = new DirectoryWatcher( props, mockBundleContext );
+        dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
 
         assertTrue( "Fragment type correctly retrieved from Package Admin service", dw.isFragment( mockBundle ) );
 
@@ -243,7 +243,7 @@ public class DirectoryWatcherTest extend
     
             try
             {
-                dw = new DirectoryWatcher( props, mockBundleContext );
+                dw = new DirectoryWatcher( new FileInstall(), props, mockBundleContext );
                 fail("Expected an IllegalStateException");
             } 
             catch (IllegalStateException e)
@@ -293,7 +293,7 @@ public class DirectoryWatcherTest extend
 
         props.put(DirectoryWatcher.DIR, watchedDirectoryPath);
 
-        dw = new DirectoryWatcher(props, mockBundleContext);
+        dw = new DirectoryWatcher(new FileInstall(), props, mockBundleContext);
         dw.noInitialDelay = true;
         dw.scanner = scanner;
         try {
@@ -345,7 +345,7 @@ public class DirectoryWatcherTest extend
 
         props.put(DirectoryWatcher.DIR, watchedDirectoryPath);
 
-        dw = new DirectoryWatcher(props, mockBundleContext);
+        dw = new DirectoryWatcher(new FileInstall(), props, mockBundleContext);
         dw.noInitialDelay = true;
         dw.scanner = scanner;
         try {
@@ -405,11 +405,12 @@ public class DirectoryWatcherTest extend
         artifact.setListener(mockArtifactListener);
         artifact.setPath(bundleFile);
 
-        FileInstall.listeners.put(mockServiceReference, mockArtifactListener);
+        FileInstall fileInstall = new FileInstall();
+        fileInstall.listeners.put(mockServiceReference, mockArtifactListener);
 
         props.put(DirectoryWatcher.DIR, watchedDirectoryPath);
 
-        dw = new DirectoryWatcher(props, mockBundleContext) {
+        dw = new DirectoryWatcher(fileInstall, props, mockBundleContext) {
 
             void refresh(Collection<Bundle> bundles) throws InterruptedException {
                 Assert.fail("bundle refresh called");