Bug 5419: Add persistAsync method to DataPersistenceProvider
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / RaftActorDelegatingPersistentDataProvider.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);
+        }
+    }
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.