felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsav...@apache.org
Subject svn commit: r994943 - in /felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr: OBRRepositoryProvider.java impl/AbstractOBRBundleRepository.java impl/CachingOBRBundleRepository.java impl/NonCachingOBRBundleRepository.java
Date Wed, 08 Sep 2010 09:42:03 GMT
Author: dsavage
Date: Wed Sep  8 09:42:02 2010
New Revision: 994943

URL: http://svn.apache.org/viewvc?rev=994943&view=rev
Log:
add support for offline=<true|false> config to obr (FELIX-2585)

Modified:
    felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/OBRRepositoryProvider.java
    felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/AbstractOBRBundleRepository.java
    felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/CachingOBRBundleRepository.java
    felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/NonCachingOBRBundleRepository.java

Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/OBRRepositoryProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/OBRRepositoryProvider.java?rev=994943&r1=994942&r2=994943&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/OBRRepositoryProvider.java
(original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/OBRRepositoryProvider.java
Wed Sep  8 09:42:02 2010
@@ -38,6 +38,7 @@ public class OBRRepositoryProvider imple
     private static final String AUTH_FILE = "auth";
     public static final String CACHE_DIRECTORY = "cache";
     public static final String INDEX_CACHE_FILE = "index";
+    public static final String OFFLINE = "offline";
 
     public IBundleRepository createRepository(String id, Properties preferences)
         throws RepositoryException
@@ -58,8 +59,10 @@ public class OBRRepositoryProvider imple
             File authFile = auth == null ? null : new File(auth);
             Long up = preferences.containsKey(UPDATE_PERIOD) ? Long.parseLong(preferences.getProperty(UPDATE_PERIOD))
                 : 60 * 60 * 24 * 7;
+            
+            boolean offline = preferences.containsKey(OFFLINE) ? Boolean.parseBoolean(preferences.getProperty(OFFLINE))
: false;
 
-            if (testURL.openConnection().getLastModified() == 0)
+            if (!offline && testURL.openConnection().getLastModified() == 0)
             {
                 String msg = "Failed to read OBR index: ";
                 if (!indexCache.exists())
@@ -71,12 +74,12 @@ public class OBRRepositoryProvider imple
             if (preferences.getProperty(IN_MEMORY) == null)
             {
                 return new NonCachingOBRBundleRepository(id, repositoryURL, indexCache,
-                    localCache, updatePeriod, authFile);
+                    localCache, updatePeriod, authFile, offline);
             }
             else
             {
                 return new CachingOBRBundleRepository(id, repositoryURL, indexCache,
-                    localCache, updatePeriod, authFile);
+                    localCache, updatePeriod, authFile, offline);
             }
         }
         catch (IOException e)

Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/AbstractOBRBundleRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/AbstractOBRBundleRepository.java?rev=994943&r1=994942&r2=994943&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/AbstractOBRBundleRepository.java
(original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/AbstractOBRBundleRepository.java
Wed Sep  8 09:42:02 2010
@@ -41,15 +41,17 @@ public abstract class AbstractOBRBundleR
 {
     private static SAXParserFactory factory = SAXParserFactory.newInstance();
 
-    private URL obrURL;
-    private File obrlCache;
-    private File bundleCache;
-    private long updatePeriod;
+    private final URL obrURL;
+    private final File obrlCache;
+    private final File bundleCache;
+    private final long updatePeriod;
     private final File authFile;
     private final Properties authMap = new Properties();
-    private long authLastModified;
+    private final boolean offline;
 
-    public AbstractOBRBundleRepository(String id, URL repositoryURL, File obrCache, File
bundleCache, long updatePeriod, File authFile)
+    private long authLastModified;
+    
+    public AbstractOBRBundleRepository(String id, URL repositoryURL, File obrCache, File
bundleCache, long updatePeriod, File authFile, boolean offline)
     {
         super(id);
         this.obrURL = repositoryURL;
@@ -57,6 +59,7 @@ public abstract class AbstractOBRBundleR
         this.bundleCache = bundleCache;
         this.updatePeriod = updatePeriod;
         this.authFile = authFile;
+        this.offline = offline;
     }
 
     public void refresh()
@@ -104,6 +107,8 @@ public abstract class AbstractOBRBundleR
         {
             authMap.clear();
             authMap.load(new FileInputStream(authFile));
+            
+            authLastModified = authFile.lastModified();
         }
 
         String authKey = "";
@@ -232,7 +237,7 @@ public abstract class AbstractOBRBundleR
         if (!getObrlCache().exists())
             return true;
 
-        return getObrlCache().lastModified() + getUpdatePeriod() < System.currentTimeMillis();
+        return !offline && getObrlCache().lastModified() + getUpdatePeriod() <
System.currentTimeMillis();
     }
 
     private URL getObrURL()

Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/CachingOBRBundleRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/CachingOBRBundleRepository.java?rev=994943&r1=994942&r2=994943&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/CachingOBRBundleRepository.java
(original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/CachingOBRBundleRepository.java
Wed Sep  8 09:42:02 2010
@@ -33,9 +33,9 @@ public class CachingOBRBundleRepository 
 
     private SoftReference<List<ISigilBundle>> bundles;
 
-    public CachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache,
long updatePeriod, File authFile)
+    public CachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache,
long updatePeriod, File authFile, boolean offline)
     {
-        super(id, repositoryURL, obrCache, bundleCache, updatePeriod, authFile);
+        super(id, repositoryURL, obrCache, bundleCache, updatePeriod, authFile, offline);
     }
 
     @Override

Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/NonCachingOBRBundleRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/NonCachingOBRBundleRepository.java?rev=994943&r1=994942&r2=994943&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/NonCachingOBRBundleRepository.java
(original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/NonCachingOBRBundleRepository.java
Wed Sep  8 09:42:02 2010
@@ -43,9 +43,9 @@ public class NonCachingOBRBundleReposito
     	});
     } */
 
-    public NonCachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File
bundleCache, long updatePeriod, File authFile)
+    public NonCachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File
bundleCache, long updatePeriod, File authFile, boolean offline)
     {
-        super(id, repositoryURL, obrCache, bundleCache, updatePeriod, authFile);
+        super(id, repositoryURL, obrCache, bundleCache, updatePeriod, authFile, offline);
     }
 
     @Override



Mime
View raw message