[java-opensaml COMMIT] in /trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl: AbstractD...

noreply at shibboleth.net noreply at shibboleth.net
Fri Nov 7 19:31:48 EST 2014


Author: putmanb
Date: Fri Nov  7 19:31:47 2014
New Revision: 4137

URL: http://svn.shibboleth.net/view/java-opensaml?rev=4137&view=rev
Log:
Implement refresh delay factor in dynamic metadata resolver.

Modified:
    trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java
    trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractMetadataResolver.java

Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java?rev=4137&r1=4136&r2=4137&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java Fri Nov  7 19:31:47 2014
@@ -18,7 +18,6 @@
 package org.opensaml.saml.metadata.resolver.impl;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -75,6 +74,9 @@
     /** Maximum cache duration. */
     private Long maxCacheDuration;
     
+    /** Factor used to compute when the next refresh interval will occur. Default value: 0.75 */
+    private Float refreshDelayFactor = 0.75f;
+    
     /** The maximum idle time in milliseconds for which the resolver will keep data for a given entityID, 
      * before it is removed. */
     private Long maxIdleEntityData;
@@ -109,6 +111,8 @@
         // Default to 8 hours.
         maxCacheDuration = 8*60*60*1000L;
         
+        refreshDelayFactor = 0.75f;
+        
         // Default to 30 minutes.
         cleanupTaskInterval = 30*60*1000L;
         
@@ -166,6 +170,35 @@
         ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
         maxCacheDuration = Constraint.isNotNull(duration, "Maximum cache duration may not be null");
     }
+    
+    /**
+     * Gets the delay factor used to compute the next refresh time.
+     * 
+     * <p>Defaults to:  0.75.</p>
+     * 
+     * @return delay factor used to compute the next refresh time
+     */
+    public Float getRefreshDelayFactor() {
+        return refreshDelayFactor;
+    }
+
+    /**
+     * Sets the delay factor used to compute the next refresh time. The delay must be between 0.0 and 1.0, exclusive.
+     * 
+     * <p>Defaults to:  0.75.</p>
+     * 
+     * @param factor delay factor used to compute the next refresh time
+     */
+    public void setRefreshDelayFactor(Float factor) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+
+        if (factor <= 0 || factor >= 1) {
+            throw new IllegalArgumentException("Refresh delay factor must be a number between 0.0 and 1.0, exclusive");
+        }
+
+        refreshDelayFactor = factor;
+    }
 
     /**
      * Get the flag indicating whether idle entity data should be removed. 
@@ -251,23 +284,33 @@
         }
         
         String entityID = StringSupport.trimOrNull(criteria.get(EntityIdCriterion.class).getEntityId());
-        Lock readLock = getBackingStore().getManagementData(entityID).getReadWriteLock().readLock();
+        log.debug("Attempting to resolve metadata for entityID: {}", entityID);
+        
+        EntityManagementData mgmtData = getBackingStore().getManagementData(entityID);
+        Lock readLock = mgmtData.getReadWriteLock().readLock();
+        boolean shouldAttemptRefresh = false;
         try {
             readLock.lock();
             
-            List<EntityDescriptor> descriptors = lookupEntityID(entityID);
-            if (!descriptors.isEmpty()) {
-                log.debug("Found requested metadata in backing store, returning");
-                return descriptors;
+            shouldAttemptRefresh = shouldAttemptRefresh(mgmtData);
+            
+            if (!shouldAttemptRefresh) {
+                List<EntityDescriptor> descriptors = lookupEntityID(entityID);
+                if (!descriptors.isEmpty()) {
+                    log.debug("Found requested metadata in backing store, returning");
+                    return descriptors;
+                } else {
+                    log.debug("Did not find requested metadata in backing store, will attempt to resolve dynamically");
+                }
+        
+            } else {
+                log.debug("Metadata was indicated to be refreshed based on refresh trigger time");
             }
         } finally {
             readLock.unlock();
         }
         
-        log.debug("Did not find requested metadata in backing store, will attempt to resolve dynamically");
-        
-        return resolveFromOriginSource(criteria);
-        

[... 239 lines stripped ...]


More information about the commits mailing list