Bug 5419: Add persistAsync method to DataPersistenceProvider 40/48440/2
authorTom Pantelis <tpanteli@brocade.com>
Thu, 17 Nov 2016 07:03:26 +0000 (02:03 -0500)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 22 Nov 2016 18:58:28 +0000 (18:58 +0000)
Change-Id: I7558cdbc59bb3db1d2ea6311ff37eec47efff92e
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorDelegatingPersistentDataProvider.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/DataPersistenceProvider.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/DelegatingPersistentDataProvider.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/NonPersistentDataProvider.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/PersistentDataProvider.java

index 378f33a..238b7e7 100644 (file)
@@ -31,22 +31,43 @@ class RaftActorDelegatingPersistentDataProvider extends DelegatingPersistentData
     }
 
     @Override
-    public <T> void persist(final T object, final Procedure<T> procedure) {
+    public <T> void persist(final T entry, final Procedure<T> procedure) {
+        doPersist(entry, procedure, false);
+    }
+
+    @Override
+    public <T> void persistAsync(T entry, Procedure<T> procedure) {
+        doPersist(entry, procedure, true);
+    }
+
+    private <T> void doPersist(final T entry, final Procedure<T> procedure, final boolean async) {
         if (getDelegate().isRecoveryApplicable()) {
-            super.persist(object, procedure);
+            persistSuper(entry, procedure, async);
         } else {
-            if (object instanceof ReplicatedLogEntry) {
-                Payload payload = ((ReplicatedLogEntry)object).getData();
+            if (entry instanceof ReplicatedLogEntry) {
+                Payload payload = ((ReplicatedLogEntry)entry).getData();
                 if (payload instanceof PersistentPayload) {
                     // We persist the Payload but not the ReplicatedLogEntry to avoid gaps in the journal indexes
                     // on recovery if data persistence is later enabled.
-                    persistentProvider.persist(payload, p -> procedure.apply(object));
+                    if (async) {
+                        persistentProvider.persistAsync(payload, p -> procedure.apply(entry));
+                    } else {
+                        persistentProvider.persist(payload, p -> procedure.apply(entry));
+                    }
                 } else {
-                    super.persist(object, procedure);
+                    persistSuper(entry, procedure, async);
                 }
             } else {
-                super.persist(object, procedure);
+                persistSuper(entry, procedure, async);
             }
         }
     }
+
+    private <T> void persistSuper(final T object, final Procedure<T> procedure, final boolean async) {
+        if (async) {
+            super.persistAsync(object, procedure);
+        } else {
+            super.persist(object, procedure);
+        }
+    }
 }
index d136d45..c655dcd 100644 (file)
@@ -26,7 +26,7 @@ public interface DataPersistenceProvider {
     boolean isRecoveryApplicable();
 
     /**
-     * Persists an entry to he applicable synchronously.
+     * Persists an entry to the applicable journal synchronously.
      *
      * @param entry the journal entry to persist
      * @param procedure the callback when persistence is complete
@@ -34,6 +34,15 @@ public interface DataPersistenceProvider {
      */
     <T> void persist(T entry, Procedure<T> procedure);
 
+    /**
+     * Persists an entry to the applicable journal asynchronously.
+     *
+     * @param entry the journal entry to persist
+     * @param procedure the callback when persistence is complete
+     * @param <T> the type of the journal entry
+     */
+    <T> void persistAsync(T entry, Procedure<T> procedure);
+
     /**
      * Saves a snapshot.
      *
index c513e38..f1a20fc 100644 (file)
@@ -40,6 +40,11 @@ public class DelegatingPersistentDataProvider implements DataPersistenceProvider
         delegate.persist(entry, procedure);
     }
 
+    @Override
+    public <T> void persistAsync(T entry, Procedure<T> procedure) {
+        delegate.persistAsync(entry, procedure);
+    }
+
     @Override
     public void saveSnapshot(Object entry) {
         delegate.saveSnapshot(entry);
index 91ae8f1..d4381f7 100644 (file)
@@ -33,6 +33,11 @@ public class NonPersistentDataProvider implements DataPersistenceProvider {
         }
     }
 
+    @Override
+    public <T> void persistAsync(T entry, Procedure<T> procedure) {
+        persist(entry, procedure);
+    }
+
     @Override
     public void saveSnapshot(Object snapshot) {
         // no-op
index b4f08c0..1d676fa 100644 (file)
@@ -33,6 +33,11 @@ public class PersistentDataProvider implements DataPersistenceProvider {
         persistentActor.persist(entry, procedure);
     }
 
+    @Override
+    public <T> void persistAsync(T entry, Procedure<T> procedure) {
+        persistentActor.persistAsync(entry, procedure);
+    }
+
     @Override
     public void saveSnapshot(Object snapshot) {
         persistentActor.saveSnapshot(snapshot);