[java-identity-provider COMMIT] /trunk/idp-core/src/main/java/net/shibboleth/idp/service/AbstractSpringReloadableServ...

noreply at shibboleth.net noreply at shibboleth.net
Thu Feb 7 17:01:06 EST 2013


Author: scantor
Date: Thu Feb  7 17:01:06 2013
New Revision: 4280

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4280&view=rev
Log:
Do Spring build both at start and reload time, implement config file monitoring.

Modified:
    trunk/idp-core/src/main/java/net/shibboleth/idp/service/AbstractSpringReloadableService.java

Modified: trunk/idp-core/src/main/java/net/shibboleth/idp/service/AbstractSpringReloadableService.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-core/src/main/java/net/shibboleth/idp/service/AbstractSpringReloadableService.java?rev=4280&r1=4279&r2=4280&view=diff
==============================================================================
--- trunk/idp-core/src/main/java/net/shibboleth/idp/service/AbstractSpringReloadableService.java (original)
+++ trunk/idp-core/src/main/java/net/shibboleth/idp/service/AbstractSpringReloadableService.java Thu Feb  7 17:01:06 2013
@@ -19,6 +19,7 @@
 
 import java.util.HashMap;
 import java.util.List;
+import java.util.concurrent.locks.Lock;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -26,6 +27,7 @@
 
 import net.shibboleth.idp.spring.SpringSupport;
 import net.shibboleth.utilities.java.support.resource.Resource;
+import net.shibboleth.utilities.java.support.resource.ResourceException;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -66,6 +68,12 @@
     private GenericApplicationContext serviceContext;
 
     /**
+     * Time, in milliseconds, when the service configuration for the given index was last observed to have changed.
+     * -1 indicates the configuration resource did not exist.
+     */
+    private long[] resourceLastModifiedTimes;
+    
+    /**
      * Gets the application context that is the parent to this service's context.
      * 
      * @return application context that is the parent to this service's context
@@ -112,6 +120,28 @@
 
         serviceConfigurations =
                 ImmutableList.<Resource> builder().addAll(Iterables.filter(configs, Predicates.notNull())).build();
+        if (!serviceConfigurations.isEmpty()) {
+            resourceLastModifiedTimes = new long[serviceConfigurations.size()];
+
+            int numOfResources = serviceConfigurations.size();
+            Resource serviceConfig;
+            for (int i = 0; i < numOfResources; i++) {
+                serviceConfig = serviceConfigurations.get(i);
+                try {
+                    if (serviceConfig.exists()) {
+                        resourceLastModifiedTimes[i] = serviceConfig.getLastModifiedTime();
+                    } else {
+                        resourceLastModifiedTimes[i] = -1;
+                    }
+                } catch (ResourceException e) {
+                    log.info("Configuration resource '" + serviceConfig.getLocation()
+                            + "' last modification date could not be determined", e);
+                    resourceLastModifiedTimes[i] = -1;
+                }
+            }
+        } else {
+            resourceLastModifiedTimes = null;
+        }
     }
 
     /**
@@ -127,20 +157,29 @@
     }
 
     /** {@inheritDoc} */
-    protected boolean shouldReload() {
-        // TODO implement
-        // loop over each resource and check if the any resources have been changed since
-        // the last time the service was reloaded. Also have to take into account locking
-        // issue so that checking if reloading doesn't block use of service but does block
-        // actual reloading
-        
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    protected void doPreReload(@Nonnull final HashMap context) throws ServiceException {
-        log.info("Configuration change detected, reloading configuration for service '{}'", getId());
-
+    protected void doPreStart(@Nonnull final HashMap context) throws ServiceException {
+        super.doPreStart(context);
+        
+        createContext(context);
+    }
+
+    /** {@inheritDoc} */
+    protected void doPostStart(@Nonnull final HashMap context) throws ServiceException {
+        super.doPostStart(context);
+        GenericApplicationContext appCtx =
+                (GenericApplicationContext) context.get(AbstractSpringService.APP_CTX_CTX_KEY);
+        serviceContext = appCtx;
+    }
+
+    /**
+     * Creates the Spring context during initial startup or as a reload operation.
+     * 
+     * @param context Collection of data carried through start and reload operations.
+     *  This is an appropriate place to keep state as the process progresses.
+     * 
+     * @throws ServiceException thrown if there is a problem starting or reloading the service
+     */
+    protected void createContext(@Nonnull final HashMap context) throws ServiceException {
         try {
             log.debug("Creating new ApplicationContext for service '{}'", getId());
             GenericApplicationContext appContext =
@@ -156,7 +195,14 @@
             throw new ServiceException("Error creating new application context for service " + getId());
         }
     }
-
+    
+    /** {@inheritDoc} */

[... 168 lines stripped ...]


More information about the commits mailing list