Add finals and move thread name constant to provider 95/46195/3
authorAndrej Leitner <andrej.leitner@pantheon.tech>
Mon, 26 Sep 2016 14:24:18 +0000 (16:24 +0200)
committerAndrej Leitner <andrej.leitner@pantheon.tech>
Tue, 27 Sep 2016 08:08:40 +0000 (10:08 +0200)
 - add onDTC annotations
 - code cleanup

Change-Id: I585d08e67138805672d19293892358205650c998
Signed-off-by: Andrej Leitner <andrej.leitner@pantheon.tech>
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/NodeListener.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/AbstractFrmSyncListener.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/ForwardingRulesSyncProvider.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SimplifiedConfigListener.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SimplifiedOperationalListener.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorFutureDecorator.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorFutureZipDecorator.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorGuardDecorator.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorImpl.java
applications/forwardingrules-sync/src/test/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorFutureZipDecoratorTest.java

index 05ca0c20f6ee73838a4b4ea454dc26055ad308a6..920737b45091142fc5060dee1361e6b10783793d 100644 (file)
@@ -8,12 +8,11 @@
 
 package org.opendaylight.openflowplugin.applications.frsync;
 
-import java.util.EventListener;
 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
  * Unifying listener for data and event changes on node.
  */
-public interface NodeListener<T extends DataObject> extends EventListener, ClusteredDataTreeChangeListener<T> {
+public interface NodeListener<T extends DataObject> extends ClusteredDataTreeChangeListener<T> {
 }
index ba70e32c58d91271bde7740dba6a885e97f61457..9ad1542e1c135681892c244cab5f358a034f2996 100644 (file)
@@ -40,9 +40,9 @@ public abstract class AbstractFrmSyncListener<T extends DataObject> implements N
                 final Optional<ListenableFuture<Boolean>> optFuture = processNodeModification(modification);
                 if (optFuture.isPresent()) {
                     final ListenableFuture<Boolean> future = optFuture.get();
-                    final Boolean ret = future.get(15000, TimeUnit.MILLISECONDS);
+                    future.get(15000, TimeUnit.MILLISECONDS);
                     if (LOG.isTraceEnabled()) {
-                        LOG.trace("Syncup return [{}] for {} from {} listener", ret, nodeId.getValue(), dsType());
+                        LOG.trace("Syncup for {} return from {} listener", nodeId.getValue(), dsType());
                     }
                 }
             } catch (InterruptedException e) {
index 996f3ef4c06d3a40e81d82fc32d831d8e32474a2..642bd684e329e3aee677ce622ae4bb0b34c20b81 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.Objects;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -50,6 +51,7 @@ import org.slf4j.LoggerFactory;
 public class ForwardingRulesSyncProvider implements AutoCloseable, BindingAwareProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(ForwardingRulesSyncProvider.class);
+    private static final String FRS_EXECUTOR_PREFIX = "FRS-executor-";
 
     private final DataBroker dataService;
     private final ClusterSingletonServiceProvider clusterSingletonService;
@@ -75,7 +77,7 @@ public class ForwardingRulesSyncProvider implements AutoCloseable, BindingAwareP
                                        final DataBroker dataBroker,
                                        final RpcConsumerRegistry rpcRegistry,
                                        final ClusterSingletonServiceProvider clusterSingletonService) {
-        Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry can not be null!");
+        Preconditions.checkNotNull(rpcRegistry, "RpcConsumerRegistry can not be null!");
         this.dataService = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
         this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService,
                 "ClusterSingletonServiceProvider can not be null!");
@@ -88,7 +90,7 @@ public class ForwardingRulesSyncProvider implements AutoCloseable, BindingAwareP
         nodeOperationalDataTreePath = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, NODE_WC_PATH);
 
         final ExecutorService executorService= Executors.newCachedThreadPool(new ThreadFactoryBuilder()
-                .setNameFormat(SyncReactorFutureDecorator.FRM_RPC_CLIENT_PREFIX + "%d")
+                .setNameFormat(FRS_EXECUTOR_PREFIX + "%d")
                 .setDaemon(false)
                 .setUncaughtExceptionHandler((thread, e) -> LOG.error("Uncaught exception {}", thread, e))
                 .build());
@@ -137,12 +139,12 @@ public class ForwardingRulesSyncProvider implements AutoCloseable, BindingAwareP
     }
 
     public void close() throws InterruptedException {
-        if (dataTreeConfigChangeListener != null) {
+        if (Objects.nonNull(dataTreeConfigChangeListener)) {
             dataTreeConfigChangeListener.close();
             dataTreeConfigChangeListener = null;
         }
 
-        if (dataTreeOperationalChangeListener != null) {
+        if (Objects.nonNull(dataTreeOperationalChangeListener)) {
             dataTreeOperationalChangeListener.close();
             dataTreeOperationalChangeListener = null;
         }
index 7204f8297f8a5555483716abb63638d53a96749b..e4964b99e0f75fb0e75acfeccb95e632625ace80 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.openflowplugin.applications.frsync.impl;
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collection;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -44,7 +45,7 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     @Override
-    public void onDataTreeChanged(final Collection<DataTreeModification<FlowCapableNode>> modifications) {
+    public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<FlowCapableNode>> modifications) {
         super.onDataTreeChanged(modifications);
     }
 
@@ -82,9 +83,8 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     /**
-     * Add only what is missing on device. If node was added to config DS and it is already present
-     * in operational DS (connected) diff between current new configuration and actual configuration
-     * (seen in operational) should be calculated and sent to device.
+     * If node was added to config DS and it is already present in operational DS (connected) diff between current
+     * new configuration and actual configuration (seen in operational) should be calculated and sent to device.
      */
     private ListenableFuture<Boolean> onNodeAdded(final InstanceIdentifier<FlowCapableNode> nodePath,
                                                   final FlowCapableNode dataAfter,
index 424a98daebc3b7456b864abb5a89a013ea305ea7..326b1debea1f67f245d70f680f4504a8fdaa5120 100644 (file)
@@ -15,6 +15,7 @@ import java.text.SimpleDateFormat;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
@@ -65,12 +66,12 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
     }
 
     @Override
-    public void onDataTreeChanged(final Collection<DataTreeModification<Node>> modifications) {
+    public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<Node>> modifications) {
         super.onDataTreeChanged(modifications);
     }
 
     /**
-     * Update cache, register for device masterhip when device connected and start reconciliation if device
+     * Update cache, register for device mastership when device connected and start reconciliation if device
      * is registered and actual modification is consistent.Skip the event otherwise.
      * @throws InterruptedException from syncup
      */
index dab77ff13b6c72140c0397fcfe501ab053a1a727..585abaa93dbc50ce17f637eace2e61e801e1c117 100644 (file)
@@ -27,11 +27,10 @@ import org.slf4j.LoggerFactory;
 public class SyncReactorFutureDecorator implements SyncReactor {
 
     private static final Logger LOG = LoggerFactory.getLogger(SyncReactorFutureDecorator.class);
-    public static final String FRM_RPC_CLIENT_PREFIX = "FRS-executor-";
     private final SyncReactor delegate;
     private final ListeningExecutorService executorService;
 
-    public SyncReactorFutureDecorator(SyncReactor delegate, ListeningExecutorService executorService) {
+    public SyncReactorFutureDecorator(final SyncReactor delegate, final ListeningExecutorService executorService) {
         this.delegate = delegate;
         this.executorService = executorService;
     }
@@ -41,9 +40,7 @@ public class SyncReactorFutureDecorator implements SyncReactor {
         final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
         return executorService.submit(() -> {
             try {
-                final Boolean futureResult = doSyncupInFuture(flowcapableNodePath, syncupEntry)
-                        .get(10000, TimeUnit.MILLISECONDS);
-                return futureResult;
+                return doSyncupInFuture(flowcapableNodePath, syncupEntry).get(10000, TimeUnit.MILLISECONDS);
             } catch (TimeoutException e) {
                 LOG.warn("Syncup future timeout occured {}", nodeId.getValue(), e);
                 return Boolean.FALSE;
index 4393b05d8f846db1b07b2e4f7c7921212fd34e46..ae2c05ca928250a950b2c012333dcbd639c09052 100644 (file)
@@ -19,8 +19,6 @@ import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
 import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Enriches {@link SyncReactorFutureDecorator} with state compression.
@@ -31,7 +29,7 @@ public class SyncReactorFutureZipDecorator extends SyncReactorFutureDecorator {
     private final Map<InstanceIdentifier<FlowCapableNode>, SyncupEntry> compressionQueue = new HashMap<>();
     private final Semaphore compressionGuard = new Semaphore(1, true);
 
-    public SyncReactorFutureZipDecorator(SyncReactor delegate, ListeningExecutorService executorService) {
+    public SyncReactorFutureZipDecorator(final SyncReactor delegate, final ListeningExecutorService executorService) {
         super(delegate, executorService);
     }
 
index d44c171b511fc37d8235b267fffef18faa604ee0..26c8cf5e1bbe3a3245c3cf45cd54e49fa381c059 100644 (file)
@@ -34,8 +34,8 @@ public class SyncReactorGuardDecorator implements SyncReactor {
     private final SyncReactor delegate;
     private final SemaphoreKeeper<InstanceIdentifier<FlowCapableNode>> semaphoreKeeper;
 
-    public SyncReactorGuardDecorator(SyncReactor delegate,
-            SemaphoreKeeper<InstanceIdentifier<FlowCapableNode>> semaphoreKeeper) {
+    public SyncReactorGuardDecorator(final SyncReactor delegate,
+                                     final SemaphoreKeeper<InstanceIdentifier<FlowCapableNode>> semaphoreKeeper) {
         this.delegate = delegate;
         this.semaphoreKeeper = semaphoreKeeper;
     }
index d1cb342cd0bc9703ee8b36173cb5536081ee505a..6f64b8d4b1d053d827aff9dc1658fd48ffabb6df 100644 (file)
@@ -18,7 +18,6 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
 import org.opendaylight.openflowplugin.applications.frsync.SyncPlanPushStrategy;
 import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
 import org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SynchronizationDiffInput;
@@ -51,7 +50,7 @@ public class SyncReactorImpl implements SyncReactor {
     private static final Logger LOG = LoggerFactory.getLogger(SyncReactorImpl.class);
     private final SyncPlanPushStrategy syncPlanPushStrategy;
 
-    public SyncReactorImpl(SyncPlanPushStrategy syncPlanPushStrategy) {
+    public SyncReactorImpl(final SyncPlanPushStrategy syncPlanPushStrategy) {
         this.syncPlanPushStrategy = Preconditions.checkNotNull(syncPlanPushStrategy, "execution strategy is mandatory");
     }
 
index 32449eb87b33338cba59eddd55064d3cafc229d6..7bf2fadea83689a08a1d1de594a7a892339c4d0a 100644 (file)
@@ -65,7 +65,7 @@ public class SyncReactorFutureZipDecoratorTest {
     public void setUp() {
         final ExecutorService executorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
                 .setDaemon(false)
-                .setNameFormat(SyncReactorFutureDecorator.FRM_RPC_CLIENT_PREFIX)
+                .setNameFormat("frsync-test-%d")
                 .setUncaughtExceptionHandler((thread, e) -> LOG.error("Uncaught exception {}", thread, e))
                 .build());
         syncThreadPool = MoreExecutors.listeningDecorator(executorService);