[java-opensaml COMMIT] /trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynam...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Oct 16 22:21:17 EDT 2013
Author: putmanb
Date: Wed Oct 16 22:21:17 2013
New Revision: 3478
URL: http://svn.shibboleth.net/view/java-opensaml?rev=3478&view=rev
Log:
Some work on abstract dynamic provider background cleanup task.
Modified:
trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.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=3478&r1=3477&r2=3478&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 Wed Oct 16 22:21:17 2013
@@ -23,7 +23,9 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Timer;
+import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
@@ -45,6 +47,7 @@
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.conn.Wire;
import org.opensaml.core.criterion.EntityIdCriterion;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.io.UnmarshallingException;
@@ -84,6 +87,10 @@
/** Generated Accept request header value. */
private String supportedContentTypesValue;
+ // TODO constructor defaults and getter/setter for this
+ // TODO right name?
+ private long maxLastAccessedInterval;
+
/**
* Constructor.
*
@@ -370,6 +377,8 @@
if (! getSupportedContentTypes().isEmpty()) {
supportedContentTypesValue = StringSupport.listToStringValue(getSupportedContentTypes(), ", ");
}
+
+ // TODO create and init backing store cleanup sweeper
}
/** {@inheritDoc} */
@@ -430,6 +439,23 @@
}
}
+ public void cleanupOrphanedManagementData() {
+ // TODO think have a race condition here
+ for (String entityID : mgmtDataMap.keySet()) {
+ Lock writeLock = mgmtDataMap.get(entityID).getReadWriteLock().writeLock();
+ try {
+ writeLock.lock();
+
+ if (!getIndexedDescriptors().containsKey(entityID)) {
+ removeManagementData(entityID);
+ }
+
+ } finally {
+ writeLock.unlock();
+ }
+ }
+ }
+
}
protected class EntityManagementData {
@@ -459,5 +485,43 @@
}
}
+
+ protected class BackingStoreCleanupSweeper extends TimerTask {
+
+ /** {@inheritDoc} */
+ public void run() {
+ if (!isInitialized()) {
+ // just in case the metadata provider was destroyed before this task runs
+ return;
+ }
+
+ // Purge entries that haven't been accessed in the specified interval
+ long now = System.currentTimeMillis();
+ long latestValid = now - maxLastAccessedInterval;
+
+ DynamicEntityBackingStore backingStore = getBackingStore();
+ Map<String, List<EntityDescriptor>> indexedDescriptors = backingStore.getIndexedDescriptors();
+
+ for (String entityID : indexedDescriptors.keySet()) {
+ Lock writeLock = backingStore.getManagementData(entityID).getReadWriteLock().writeLock();
+ try {
+ writeLock.lock();
+
+ if (backingStore.getManagementData(entityID).getLastAccessedTime() < latestValid) {
+ indexedDescriptors.remove(entityID);
+ // TODO do this here, or in later cleanup code
+ //backingStore.removeManagementData(entityID);
+ }
+
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ // Cleanup mgmt data entries that don't have any indexed descriptors associated with them
+ backingStore.cleanupOrphanedManagementData();
+ }
+
+ }
}
More information about the commits
mailing list