Cleanup ReconciliationServiceImpl 37/92337/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 31 Aug 2020 11:27:55 +0000 (13:27 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 31 Aug 2020 11:27:55 +0000 (13:27 +0200)
The first hint here is the raw ConcurrentHashMap, which turns out
to be immediately overwritten in constructor. After this is fixed
it becomes obvious the field is actually final, not volatile.

Further investigation shows we can improve use of RpcErrorBuilder,
making the code a lot simpler.

Change-Id: I89bc14a6f30f7903d8e54d496e3899b290a03705
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/ReconciliationServiceImpl.java

index 6680c58c11e75d0ccdf4411de92641994aa6ba3f..60086bf4f90e2a5e93cdfc58b008455da327745e 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.applications.southboundcli;
 
 import static java.util.Objects.requireNonNull;
@@ -23,7 +22,6 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -64,7 +62,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class ReconciliationServiceImpl implements ReconciliationService, AutoCloseable {
-
     private static final Logger LOG = LoggerFactory.getLogger(ReconciliationServiceImpl.class);
 
     private final DataBroker broker;
@@ -74,7 +71,7 @@ public class ReconciliationServiceImpl implements ReconciliationService, AutoClo
     private final Long startCount = 1L;
     private final int threadPoolSize = 10;
     private final ExecutorService executor = Executors.newWorkStealingPool(threadPoolSize);
-    private volatile Map<String, ReconciliationState> reconciliationStates = new ConcurrentHashMap();
+    private final Map<String, ReconciliationState> reconciliationStates;
 
     public ReconciliationServiceImpl(final DataBroker broker, final FrmReconciliationService frmReconciliationService,
                                      final AlarmAgent alarmAgent, final NodeListener nodeListener,
@@ -147,12 +144,11 @@ public class ReconciliationServiceImpl implements ReconciliationService, AutoClo
         return reconciliationStates.get(nodeId.toString());
     }
 
-    private ListenableFuture<RpcResult<ReconcileOutput>> buildErrorResponse(String msg) {
-        SettableFuture<RpcResult<ReconcileOutput>> result = SettableFuture.create();
+    private static ListenableFuture<RpcResult<ReconcileOutput>> buildErrorResponse(String msg) {
         LOG.error("Error {}", msg);
-        RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.PROTOCOL, "reconcile", msg);
-        result.set(RpcResultBuilder.<ReconcileOutput>failed().withRpcError(error).build());
-        return result;
+        return RpcResultBuilder.<ReconcileOutput>failed()
+                .withError(RpcError.ErrorType.PROTOCOL, "reconcile", msg)
+                .buildFuture();
     }
 
     private List<Long> getAllNodes() {