[java-opensaml COMMIT] in /trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl: AbstractMemoryStorage...
noreply at shibboleth.net
noreply at shibboleth.net
Thu Oct 24 20:53:46 EDT 2013
Author: scantor
Date: Thu Oct 24 20:53:46 2013
New Revision: 3484
URL: http://svn.shibboleth.net/view/java-opensaml?rev=3484&view=rev
Log:
Refactor in-memory storage for client-side addition.
Added:
trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/AbstractMemoryStorageService.java (with props)
Modified:
trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/MemoryStorageService.java
Modified: trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/MemoryStorageService.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/MemoryStorageService.java?rev=3484&r1=3483&r2=3484&view=diff
==============================================================================
--- trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/MemoryStorageService.java (original)
+++ trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/MemoryStorageService.java Thu Oct 24 20:53:46 2013
@@ -17,13 +17,10 @@
package org.opensaml.storage.impl;
-import java.io.IOException;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TimerTask;
-import java.util.Map.Entry;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -31,46 +28,36 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-import net.shibboleth.utilities.java.support.annotation.constraint.Positive;
-import net.shibboleth.utilities.java.support.collection.Pair;
+import net.shibboleth.utilities.java.support.annotation.constraint.Live;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import org.opensaml.storage.AbstractStorageService;
-import org.opensaml.storage.StorageRecord;
-import org.opensaml.storage.VersionMismatchException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
/**
- * Implementation of {@link StorageService} that stores data in-memory with no persistence.
+ * Implementation of {@link StorageService} that stores data in-memory in a shared data structure
+ * with no persistence.
*/
-public class MemoryStorageService extends AbstractStorageService {
+public class MemoryStorageService extends AbstractMemoryStorageService {
/** Class logger. */
- private final Logger log = LoggerFactory.getLogger(MemoryStorageService.class);
+ @Nonnull private final Logger log = LoggerFactory.getLogger(MemoryStorageService.class);
/** Map of contexts. */
- private Map<String, Map<String, MutableStorageRecord>> contextMap;
+ @NonnullAfterInit @NonnullElements private Map<String, Map<String, MutableStorageRecord>> contextMap;
/** A shared lock to synchronize access. */
- private ReadWriteLock lock;
+ @NonnullAfterInit private ReadWriteLock lock;
- /** Constructor. */
- public MemoryStorageService() {
- setContextSize(Integer.MAX_VALUE);
- setKeySize(Integer.MAX_VALUE);
- setValueSize(Integer.MAX_VALUE);
- }
-
/** {@inheritDoc} */
protected void doInitialize() throws ComponentInitializationException {
super.doInitialize();
- contextMap = new HashMap<String, Map<String, MutableStorageRecord>>();
+ contextMap = Maps.newHashMap();
lock = new ReentrantReadWriteLock(true);
}
@@ -81,331 +68,17 @@
lock = null;
}
+
/** {@inheritDoc} */
- public boolean create(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key,
- @Nonnull @NotEmpty final String value, @Nullable final Long expiration) throws IOException {
- final Lock writeLock = lock.writeLock();
-
- try {
- writeLock.lock();
-
- // Create new context if necessary.
- Map<String, MutableStorageRecord> dataMap = contextMap.get(context);
- if (dataMap == null) {
- dataMap = new HashMap();
- contextMap.put(context, dataMap);
- }
-
- // Check for a duplicate.
- StorageRecord record = dataMap.get(key);
- if (record != null) {
- // Not yet expired?
- Long exp = record.getExpiration();
- if (exp == null || System.currentTimeMillis() < exp) {
- return false;
- }
-
- // It's dead, so we can just remove it now and create the new record.
- }
-
- dataMap.put(key, new MutableStorageRecord(value, expiration));
[... 321 lines stripped ...]
More information about the commits
mailing list