Fix remaining CS errors in sal-akka-raft and enable enforcement
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / ReplicatedLogImpl.java
index 7e1cb69afff8124d8cd794b3d68aec0f019d1e1b..9123c14d5d615553a2abf58d19e9a1d89ad63f39 100644 (file)
@@ -11,7 +11,7 @@ import akka.japi.Procedure;
 import com.google.common.base.Preconditions;
 import java.util.Collections;
 import java.util.List;
-import org.opendaylight.controller.cluster.raft.base.messages.DeleteEntries;
+import org.opendaylight.controller.cluster.raft.persisted.DeleteEntries;
 
 /**
  * Implementation of ReplicatedLog used by the RaftActor.
@@ -19,18 +19,15 @@ import org.opendaylight.controller.cluster.raft.base.messages.DeleteEntries;
 class ReplicatedLogImpl extends AbstractReplicatedLogImpl {
     private static final int DATA_SIZE_DIVIDER = 5;
 
-    private final Procedure<DeleteEntries> deleteProcedure = new Procedure<DeleteEntries>() {
-        @Override
-        public void apply(final DeleteEntries notUsed) {
-        }
-    };
+    private final Procedure<DeleteEntries> deleteProcedure = NoopProcedure.instance();
 
     private final RaftActorContext context;
     private long dataSizeSinceLastSnapshot = 0L;
 
-    private ReplicatedLogImpl(final long snapshotIndex, final long snapshotTerm, final List<ReplicatedLogEntry> unAppliedEntries,
+    private ReplicatedLogImpl(final long snapshotIndex, final long snapshotTerm,
+            final List<ReplicatedLogEntry> unAppliedEntries,
             final RaftActorContext context) {
-        super(snapshotIndex, snapshotTerm, unAppliedEntries);
+        super(snapshotIndex, snapshotTerm, unAppliedEntries, context.getId());
         this.context = Preconditions.checkNotNull(context);
     }
 
@@ -44,17 +41,15 @@ class ReplicatedLogImpl extends AbstractReplicatedLogImpl {
     }
 
     @Override
-    public void removeFromAndPersist(final long logEntryIndex) {
+    public boolean removeFromAndPersist(final long logEntryIndex) {
         // FIXME: Maybe this should be done after the command is saved
         long adjustedIndex = removeFrom(logEntryIndex);
-        if(adjustedIndex >= 0) {
+        if (adjustedIndex >= 0) {
             context.getPersistenceProvider().persist(new DeleteEntries(adjustedIndex), deleteProcedure);
+            return true;
         }
-    }
 
-    @Override
-    public void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry) {
-        appendAndPersist(replicatedLogEntry, null);
+        return false;
     }
 
     @Override
@@ -91,14 +86,22 @@ class ReplicatedLogImpl extends AbstractReplicatedLogImpl {
         }
     }
 
+    @Override
+    public void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry) {
+        appendAndPersist(replicatedLogEntry, null);
+    }
+
     @Override
     public void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry,
             final Procedure<ReplicatedLogEntry> callback)  {
 
         context.getLogger().debug("{}: Append log entry and persist {} ", context.getId(), replicatedLogEntry);
 
-        // FIXME : By adding the replicated log entry to the in-memory journal we are not truly ensuring durability of the logs
-        append(replicatedLogEntry);
+        // FIXME : By adding the replicated log entry to the in-memory journal we are not truly ensuring durability
+        // of the logs
+        if (!append(replicatedLogEntry)) {
+            return;
+        }
 
         // When persisting events with persist it is guaranteed that the
         // persistent actor will not receive further commands between the
@@ -106,19 +109,16 @@ class ReplicatedLogImpl extends AbstractReplicatedLogImpl {
         // handler. This also holds for multiple persist calls in context
         // of a single command.
         context.getPersistenceProvider().persist(replicatedLogEntry,
-            new Procedure<ReplicatedLogEntry>() {
-                @Override
-                public void apply(final ReplicatedLogEntry param) throws Exception {
-                    context.getLogger().debug("{}: persist complete {}", context.getId(), param);
+            param -> {
+                context.getLogger().debug("{}: persist complete {}", context.getId(), param);
 
-                    int logEntrySize = param.size();
-                    dataSizeSinceLastSnapshot += logEntrySize;
+                int logEntrySize = param.size();
+                dataSizeSinceLastSnapshot += logEntrySize;
 
-                    if (callback != null) {
-                        callback.apply(param);
-                    }
+                if (callback != null) {
+                    callback.apply(param);
                 }
             }
         );
     }
-}
\ No newline at end of file
+}