[java-opensaml COMMIT] in /trunk/opensaml-util/src/main/java/org/opensaml/util/storage: AbstractStorageService.java S...

noreply at shibboleth.net noreply at shibboleth.net
Mon Apr 29 17:15:18 EDT 2013


Author: scantor
Date: Mon Apr 29 17:15:18 2013
New Revision: 3323

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3323&view=rev
Log:
Add custom serialization to storage API, some refactoring.

Added:
    trunk/opensaml-util/src/main/java/org/opensaml/util/storage/AbstractStorageService.java   (with props)
    trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageSerializer.java   (with props)
Modified:
    trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageRecord.java
    trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageService.java
    trunk/opensaml-util/src/main/java/org/opensaml/util/storage/impl/MemoryStorageService.java

Modified: trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageRecord.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageRecord.java?rev=3323&r1=3322&r2=3323&view=diff
==============================================================================
--- trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageRecord.java (original)
+++ trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageRecord.java Mon Apr 29 17:15:18 2013
@@ -17,15 +17,21 @@
 
 package org.opensaml.util.storage;
 
+import java.io.IOException;
+
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import javax.annotation.concurrent.NotThreadSafe;
 
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 
 /**
  * Represents a versioned record in a {@link StorageService}.
+ * 
+ * @param <Type> the object type represented by the record
  */
-public class StorageRecord {
+ at NotThreadSafe
+public class StorageRecord<Type> {
 
     /** Version field. */
     private int version;
@@ -67,6 +73,17 @@
     }
 
     /**
+     * Get the record value, using a custom deserialization process.
+     * 
+     * @param serializer a custom (de)serialization process to apply
+     * @return  the record value
+     * @throws IOException if deserialization fails
+     */
+    @Nonnull public Type getValue(@Nonnull final StorageSerializer<Type> serializer) throws IOException {
+        return serializer.deserialize(value);
+    }
+    
+    /**
      * Get the record expiration.
      * 
      * @return  the record expiration, or null if none
@@ -82,6 +99,18 @@
      */
     protected void setValue(@Nonnull @NotEmpty final String val) {
         value = val;
+    }
+
+    /**
+     * Set the record value, using a custom serialization process.
+     * 
+     * @param instance  the new record value
+     * @param serializer a custom serialization process to apply
+     * @throws IOException if serialization fails
+     */
+    protected void setValue(@Nonnull final Type instance, @Nonnull final StorageSerializer<Type> serializer)
+            throws IOException {
+        value = serializer.serialize(instance);
     }
     
     /**

Modified: trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageService.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageService.java?rev=3323&r1=3322&r2=3323&view=diff
==============================================================================
--- trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageService.java (original)
+++ trunk/opensaml-util/src/main/java/org/opensaml/util/storage/StorageService.java Mon Apr 29 17:15:18 2013
@@ -115,6 +115,38 @@
     public boolean createText(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key,
             @Nonnull @NotEmpty final String value, final long expiration) throws IOException;
 
+    /**
+     * Creates a new "text" record in the store with no explicit expiration, using a custom serialization
+     * process for an arbitrary object.
+     * 
+     * @param context       a storage context label
+     * @param key           a key unique to context
+     * @param value         object to store
+     * @param serializer    custom serializer for the object
+     * 
+     * @return  true iff record was inserted, false iff a duplicate was found
+     * @throws IOException  if fatal errors occur in the insertion process 
+     */
+    public boolean createText(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key,
+            @Nonnull final Object value, @Nonnull final StorageSerializer serializer) throws IOException;
+
+    /**
+     * Creates a new "text" record in the store, using a custom serialization
+     * process for an arbitrary object.
+     * 
+     * @param context       a storage context label
+     * @param key           a key unique to context
+     * @param value         object to store
+     * @param serializer    custom serializer for the object
+     * @param expiration    expiration for record
+     * 
+     * @return  true iff record was inserted, false iff a duplicate was found
+     * @throws IOException  if fatal errors occur in the insertion process 
+     */

[... 800 lines stripped ...]


More information about the commits mailing list