[java-opensaml] 03/03: OSJ-249: Enhance FilesystemLoadSaveManager to check file last ...

Brent Putman putmanb at georgetown.edu
Fri Sep 28 22:53:01 EDT 2018


This is an automated email from the git hooks/post-receive script.

putmanb pushed a commit to branch master
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=ede9aba7fac9ceb698b03b9a359627c4556878da

commit ede9aba7fac9ceb698b03b9a359627c4556878da
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Fri Sep 28 21:48:36 2018 -0400

    OSJ-249: Enhance FilesystemLoadSaveManager to check file last ...
    
    Change recent API addition to have conditional load flag passed as
    ctor arg rather than setter.  We don't want this changing after
    construction.
---
 ...actConditionalLoadXMLObjectLoadSaveManager.java | 18 +++--
 .../ConditionalLoadXMLObjectLoadSaveManager.java   | 12 +--
 .../xml/persist/FilesystemLoadSaveManager.java     | 87 ++++++++++++++++++++--
 .../core/xml/persist/MapLoadSaveManager.java       | 39 +++++++++-
 .../xml/persist/FilesystemLoadSaveManagerTest.java |  2 +-
 .../core/xml/persist/MapLoadSaveManagerTest.java   |  2 +-
 .../impl/LocalDynamicMetadataResolverTest.java     |  8 +-
 7 files changed, 136 insertions(+), 32 deletions(-)

diff --git a/opensaml-core/src/main/java/org/opensaml/core/xml/persist/AbstractConditionalLoadXMLObjectLoadSaveManager.java b/opensaml-core/src/main/java/org/opensaml/core/xml/persist/AbstractConditionalLoadXMLObjectLoadSaveManager.java
index bca03f7..5388678 100644
--- a/opensaml-core/src/main/java/org/opensaml/core/xml/persist/AbstractConditionalLoadXMLObjectLoadSaveManager.java
+++ b/opensaml-core/src/main/java/org/opensaml/core/xml/persist/AbstractConditionalLoadXMLObjectLoadSaveManager.java
@@ -26,6 +26,8 @@ import javax.annotation.Nullable;
 
 import org.opensaml.core.xml.XMLObject;
 
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
+
 /**
  * Abstract base class for {@link XMLObjectLoadSaveManager} implementations which 
  * track the modify times of requested data such that {@link #load(String)} returns
@@ -44,9 +46,16 @@ public abstract class AbstractConditionalLoadXMLObjectLoadSaveManager<T extends
     /** Storage for last modified time of requested data. */
     private Map<String, Long> loadLastModified;
     
-    /** Constructor. */
-    protected AbstractConditionalLoadXMLObjectLoadSaveManager() {
+    /** 
+     * Constructor. 
+     * 
+     * @param conditionalLoad whether {@link #load(String)} should behave 
+     *      as defined in {@link ConditionalLoadXMLObjectLoadSaveManager}
+     */
+    protected AbstractConditionalLoadXMLObjectLoadSaveManager(
+            @ParameterName(name="conditionalLoad") final boolean conditionalLoad) {
         loadLastModified = new HashMap<>();
+        loadConditionally = conditionalLoad;
     }
     
     /** {@inheritDoc} */
@@ -55,11 +64,6 @@ public abstract class AbstractConditionalLoadXMLObjectLoadSaveManager<T extends
     }
     
     /** {@inheritDoc} */
-    public void setLoadConditionally(final boolean flag) {
-        loadConditionally = flag;
-    }
-    
-    /** {@inheritDoc} */
     @Nullable public synchronized Long getLoadLastModified(@Nonnull final String key) {
         return loadLastModified.get(key);
     }
diff --git a/opensaml-core/src/main/java/org/opensaml/core/xml/persist/ConditionalLoadXMLObjectLoadSaveManager.java b/opensaml-core/src/main/java/org/opensaml/core/xml/persist/ConditionalLoadXMLObjectLoadSaveManager.java
index 5117e20..bbaaebe 100644
--- a/opensaml-core/src/main/java/org/opensaml/core/xml/persist/ConditionalLoadXMLObjectLoadSaveManager.java
+++ b/opensaml-core/src/main/java/org/opensaml/core/xml/persist/ConditionalLoadXMLObjectLoadSaveManager.java
@@ -33,28 +33,20 @@ import org.opensaml.core.xml.XMLObject;
 public interface ConditionalLoadXMLObjectLoadSaveManager<T extends XMLObject> extends XMLObjectLoadSaveManager<T> {
     
     /** 
-     * Get the configuration flag for whether {@link #load(String)} will check and return data only if modified 
+     * Get whether {@link #load(String)} will check and return data only if modified 
      * since the last request for that data.
      * 
      * @return true if data modify time check is enabled, false if not
      */
     public boolean isLoadConditionally();
     
-    /** 
-     * Set the configuration flag for whether {@link #load(String)} will check and return data only if modified 
-     * since the last request for that data.
-     * 
-     * @param flag true if data modify time check should be enabled, false if not
-     */
-    public void setLoadConditionally(final boolean flag);
-    
     /**
      * Retrieve the cached modified time for the last load of the specified key.
      * 
      * <p>
      * Note that this will be null if {@link #load(String)} has not been called
      * for the specified key since construction or since the last call to 
-     * {@link #clearLoadLastModified(String)}.
+     * {@link #clearLoadLastModified(String)} or {@link #clearAllLoadLastModified()}.
      * </p> 
      * 
      * @param key the target key
diff --git a/opensaml-core/src/main/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManager.java b/opensaml-core/src/main/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManager.java
index 6dfb9a8..b6154a5 100644
--- a/opensaml-core/src/main/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManager.java
+++ b/opensaml-core/src/main/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManager.java
@@ -49,6 +49,7 @@ import com.google.common.collect.Collections2;
 import com.google.common.io.ByteStreams;
 import com.google.common.io.Files;
 
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
 import net.shibboleth.utilities.java.support.collection.Pair;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
@@ -88,19 +89,51 @@ public class FilesystemLoadSaveManager<T extends XMLObject> extends AbstractCond
      *
      * @param baseDir the base directory, must be an absolute path
      */
-    public FilesystemLoadSaveManager(@Nonnull final String baseDir) {
+    public FilesystemLoadSaveManager(
+            @ParameterName(name="baseDir") @Nonnull final String baseDir) {
         this(new File(Constraint.isNotNull(StringSupport.trimOrNull(baseDir), 
                 "Base directory string instance was null or empty")),
-                null);
+                null,
+                false);
     }
 
     /**
      * Constructor.
      *
      * @param baseDir the base directory, must be an absolute path
+     * @param conditionalLoad whether {@link #load(String)} should behave 
+     *      as defined in {@link ConditionalLoadXMLObjectLoadSaveManager}
      */
-    public FilesystemLoadSaveManager(@Nonnull final File baseDir) {
-        this(baseDir, null);
+    public FilesystemLoadSaveManager(
+            @ParameterName(name="baseDir") @Nonnull final String baseDir, 
+            @ParameterName(name="conditionalLoad") final boolean conditionalLoad) {
+        this(new File(Constraint.isNotNull(StringSupport.trimOrNull(baseDir), 
+                "Base directory string instance was null or empty")),
+                null,
+                conditionalLoad);
+    }
+    
+    /**
+     * Constructor.
+     *
+     * @param baseDir the base directory, must be an absolute path
+     */
+    public FilesystemLoadSaveManager(
+            @ParameterName(name="baseDirFile") @Nonnull final File baseDir) {
+        this(baseDir, null, false);
+    }
+    
+    /**
+     * Constructor.
+     *
+     * @param baseDir the base directory, must be an absolute path
+     * @param conditionalLoad whether {@link #load(String)} should behave 
+     *      as defined in {@link ConditionalLoadXMLObjectLoadSaveManager}
+     */
+    public FilesystemLoadSaveManager(
+            @ParameterName(name="baseDirFile") @Nonnull final File baseDir, 
+            @ParameterName(name="conditionalLoad") final boolean conditionalLoad) {
+        this(baseDir, null, conditionalLoad);
     }
     
     /**
@@ -109,10 +142,13 @@ public class FilesystemLoadSaveManager<T extends XMLObject> extends AbstractCond
      * @param baseDir the base directory, must be an absolute path
      * @param pp the parser pool instance to use
      */
-    public FilesystemLoadSaveManager(@Nonnull final String baseDir, @Nullable final ParserPool pp) {
+    public FilesystemLoadSaveManager(
+            @ParameterName(name="baseDir") @Nonnull final String baseDir, 
+            @ParameterName(name="parserPool") @Nullable final ParserPool pp) {
         this(new File(Constraint.isNotNull(StringSupport.trimOrNull(baseDir), 
                 "Base directory string instance was null or empty")),
-                pp);
+                pp, 
+                false);
     }
 
     /**
@@ -120,9 +156,44 @@ public class FilesystemLoadSaveManager<T extends XMLObject> extends AbstractCond
      *
      * @param baseDir the base directory, must be an absolute path
      * @param pp the parser pool instance to use
+     * @param conditionalLoad whether {@link #load(String)} should behave 
+     *      as defined in {@link ConditionalLoadXMLObjectLoadSaveManager}
      */
-    public FilesystemLoadSaveManager(@Nonnull final File baseDir, @Nullable final ParserPool pp) {
-        super();
+    public FilesystemLoadSaveManager(
+            @ParameterName(name="baseDir") @Nonnull final String baseDir, 
+            @ParameterName(name="parserPool") @Nullable final ParserPool pp,
+            @ParameterName(name="conditionalLoad") final boolean conditionalLoad) {
+        this(new File(Constraint.isNotNull(StringSupport.trimOrNull(baseDir), 
+                "Base directory string instance was null or empty")),
+                pp, conditionalLoad);
+    }
+    /**
+     * Constructor.
+     *
+     * @param baseDir the base directory, must be an absolute path
+     * @param pp the parser pool instance to use
+     */
+    public FilesystemLoadSaveManager(
+            @ParameterName(name="baseDirFile") @Nonnull final File baseDir, 
+            @ParameterName(name="parserPool") @Nullable final ParserPool pp) {
+        this(baseDir, pp, false);
+    }
+    
+    /**
+     * Constructor.
+     *
+     * @param baseDir the base directory, must be an absolute path
+     * @param pp the parser pool instance to use
+     * @param conditionalLoad whether {@link #load(String)} should behave 
+     *      as defined in {@link ConditionalLoadXMLObjectLoadSaveManager}
+     */
+    public FilesystemLoadSaveManager(
+            @ParameterName(name="baseDirFile") @Nonnull final File baseDir, 
+            @ParameterName(name="parserPool") @Nullable final ParserPool pp,
+            @ParameterName(name="conditionalLoad") final boolean conditionalLoad) {
+        
+        super(conditionalLoad);
+        
         baseDirectory = Constraint.isNotNull(baseDir, "Base directory File instance was null");
         Constraint.isTrue(baseDirectory.isAbsolute(), "Base directory specified was not an absolute path");
         if (baseDirectory.exists()) {
diff --git a/opensaml-core/src/main/java/org/opensaml/core/xml/persist/MapLoadSaveManager.java b/opensaml-core/src/main/java/org/opensaml/core/xml/persist/MapLoadSaveManager.java
index b1fe17e..32194b5 100644
--- a/opensaml-core/src/main/java/org/opensaml/core/xml/persist/MapLoadSaveManager.java
+++ b/opensaml-core/src/main/java/org/opensaml/core/xml/persist/MapLoadSaveManager.java
@@ -30,6 +30,7 @@ import org.opensaml.core.xml.XMLObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
 import net.shibboleth.utilities.java.support.collection.Pair;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 
@@ -52,17 +53,49 @@ public class MapLoadSaveManager<T extends XMLObject> extends AbstractConditional
     
     /** Constructor. */
     public MapLoadSaveManager() {
-        this(new HashMap<String,T>());
+        this(new HashMap<String,T>(), new HashMap<String,Long>(), false);
+    }
+
+    /** 
+     * Constructor.
+     * 
+     * @param conditionalLoad whether {@link #load(String)} should behave 
+     *      as defined in {@link ConditionalLoadXMLObjectLoadSaveManager}
+     * */
+    public MapLoadSaveManager(@ParameterName(name="conditionalLoad") final boolean conditionalLoad) {
+        this(new HashMap<String,T>(), new HashMap<String,Long>(), conditionalLoad);
     }
 
     /**
      * Constructor.
+     * 
+     * <p>
+     * Note: conditional load is not supported with this option, because of the need to track
+     * modify times of items stored in the backing map.
+     * Use instead {@link MapLoadSaveManager#MapLoadSaveManager(boolean)}.
+     * </p>
      *
      * @param map the backing map 
      */
-    public MapLoadSaveManager(@Nonnull final Map<String, T> map) {
+    public MapLoadSaveManager(@ParameterName(name="map") @Nonnull final Map<String, T> map) {
+        this(map, new HashMap<String,Long>(), false);
+    }
+    
+    /**
+     * Constructor.
+     * 
+     * @param map the backing map 
+     * @param lastModifiedMap the storage for data last modified times
+     * @param conditionalLoad whether {@link #load(String)} should behave 
+     *      as defined in {@link ConditionalLoadXMLObjectLoadSaveManager}
+     */
+    protected MapLoadSaveManager(
+            @ParameterName(name="map") @Nonnull final Map<String, T> map,
+            @ParameterName(name="dataLastModified") @Nonnull final Map<String,Long> lastModifiedMap,
+            @ParameterName(name="conditionalLoad") final boolean conditionalLoad) {
+        super(conditionalLoad);
         backingMap = Constraint.isNotNull(map, "Backing map was null");
-        dataLastModified = new HashMap<>();
+        dataLastModified = Constraint.isNotNull(lastModifiedMap, "Data last modified map was null");
     }
 
     /** {@inheritDoc} */
diff --git a/opensaml-core/src/test/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManagerTest.java b/opensaml-core/src/test/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManagerTest.java
index 3159b7d..6808c82 100644
--- a/opensaml-core/src/test/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManagerTest.java
+++ b/opensaml-core/src/test/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManagerTest.java
@@ -145,7 +145,7 @@ public class FilesystemLoadSaveManagerTest extends XMLObjectBaseTestCase {
     
     @Test
     public void checkCheckModifyTimeTracking() throws IOException {
-        manager.setLoadConditionally(true);
+        manager = new FilesystemLoadSaveManager<>(baseDir, true);
         
         Assert.assertNull(manager.load("foo"));
         Assert.assertNull(manager.getLoadLastModified("foo"));
diff --git a/opensaml-core/src/test/java/org/opensaml/core/xml/persist/MapLoadSaveManagerTest.java b/opensaml-core/src/test/java/org/opensaml/core/xml/persist/MapLoadSaveManagerTest.java
index 022abba..ccd4681 100644
--- a/opensaml-core/src/test/java/org/opensaml/core/xml/persist/MapLoadSaveManagerTest.java
+++ b/opensaml-core/src/test/java/org/opensaml/core/xml/persist/MapLoadSaveManagerTest.java
@@ -110,7 +110,7 @@ public class MapLoadSaveManagerTest extends XMLObjectBaseTestCase {
     
     @Test
     public void checkCheckModifyTimeTracking() throws IOException {
-        manager.setLoadConditionally(true);
+        manager = new MapLoadSaveManager<>(true);
         
         Assert.assertNull(manager.load("foo"));
         Assert.assertNull(manager.getLoadLastModified("foo"));
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/impl/LocalDynamicMetadataResolverTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/impl/LocalDynamicMetadataResolverTest.java
index ad3a2bb..f4a5458 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/impl/LocalDynamicMetadataResolverTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/impl/LocalDynamicMetadataResolverTest.java
@@ -121,8 +121,12 @@ public class LocalDynamicMetadataResolverTest extends XMLObjectBaseTestCase {
     }
     
     @Test
-    public void testConditionalLoadManagerWithClearEntityID() throws IOException, ResolverException {
-        sourceManager.setLoadConditionally(true);
+    public void testConditionalLoadManagerWithClearEntityID() throws IOException, ResolverException, ComponentInitializationException {
+        sourceManager = new MapLoadSaveManager<>(true);
+        resolver = new LocalDynamicMetadataResolver(sourceManager);
+        resolver.setId("abc123");
+        resolver.setParserPool(parserPool);
+        resolver.initialize();
         
         sourceManager.save(sha1Digester.apply(entityID1), entity1);
         

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list