BUG8607 Fix checkstyle issues
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / frm / impl / DeviceMastershipManager.java
index 7b31ef170d54f844fb6200edf5633615cf2007f8..2e27d697411f722df0c0c7f3d6cf4c09cebd9825 100644 (file)
@@ -45,14 +45,11 @@ import org.slf4j.LoggerFactory;
 /**
  * Manager for clustering service registrations of {@link DeviceMastership}.
  */
-public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<FlowCapableNode>,
-        OpendaylightInventoryListener, AutoCloseable{
+public class DeviceMastershipManager
+        implements ClusteredDataTreeChangeListener<FlowCapableNode>, OpendaylightInventoryListener, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(DeviceMastershipManager.class);
-    private static final InstanceIdentifier<FlowCapableNode> II_TO_FLOW_CAPABLE_NODE
-            = InstanceIdentifier.builder(Nodes.class)
-            .child(Node.class)
-            .augmentation(FlowCapableNode.class)
-            .build();
+    private static final InstanceIdentifier<FlowCapableNode> II_TO_FLOW_CAPABLE_NODE = InstanceIdentifier
+            .builder(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class).build();
 
     private final ClusterSingletonServiceProvider clusterSingletonService;
     private final ListenerRegistration<?> notifListenerRegistration;
@@ -64,9 +61,8 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
     private Set<InstanceIdentifier<FlowCapableNode>> activeNodes = Collections.emptySet();
 
     public DeviceMastershipManager(final ClusterSingletonServiceProvider clusterSingletonService,
-                                   final NotificationProviderService notificationService,
-                                   final FlowNodeReconciliation reconcliationAgent,
-                                   final DataBroker dataBroker) {
+            final NotificationProviderService notificationService, final FlowNodeReconciliation reconcliationAgent,
+            final DataBroker dataBroker) {
         this.clusterSingletonService = clusterSingletonService;
         this.notifListenerRegistration = notificationService.registerNotificationListener(this);
         this.reconcliationAgent = reconcliationAgent;
@@ -91,22 +87,24 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
     }
 
     /**
-     * Temporary solution before Mastership manager from plugin.
-     * Remove notification after update.
-     * Update node notification should be send only when mastership in plugin was granted.
-     * @param notification received notification
+     * Temporary solution before Mastership manager from plugin. Remove notification
+     * after update. Update node notification should be send only when mastership in
+     * plugin was granted.
+     *
+     * @param notification
+     *            received notification
      */
     @Override
     public void onNodeUpdated(NodeUpdated notification) {
         LOG.debug("NodeUpdate notification received : {}", notification);
-        DeviceMastership membership = deviceMasterships.computeIfAbsent(notification.getId(), device ->
-                new DeviceMastership(notification.getId()));
+        DeviceMastership membership = deviceMasterships.computeIfAbsent(notification.getId(),
+            device -> new DeviceMastership(notification.getId()));
         membership.reconcile();
     }
 
     @Override
     public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
-        //Not published by plugin
+        // Not published by plugin
     }
 
     @Override
@@ -122,7 +120,7 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
 
     @Override
     public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
-        //Not published by plugin
+        // Not published by plugin
     }
 
     @Override
@@ -132,8 +130,7 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
         for (DataTreeModification<FlowCapableNode> change : changes) {
             final InstanceIdentifier<FlowCapableNode> key = change.getRootPath().getRootIdentifier();
             final DataObjectModification<FlowCapableNode> mod = change.getRootNode();
-            final InstanceIdentifier<FlowCapableNode> nodeIdent =
-                    key.firstIdentifierOf(FlowCapableNode.class);
+            final InstanceIdentifier<FlowCapableNode> nodeIdent = key.firstIdentifierOf(FlowCapableNode.class);
 
             switch (mod.getModificationType()) {
                 case DELETE:
@@ -142,7 +139,7 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
                     }
                     break;
                 case SUBTREE_MODIFIED:
-                    //NO-OP since we do not need to reconcile on Node-updated
+                    // NO-OP since we do not need to reconcile on Node-updated
                     break;
                 case WRITE:
                     if (mod.getDataBefore() == null) {
@@ -156,21 +153,20 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
     }
 
     public void remove(InstanceIdentifier<FlowCapableNode> identifier, FlowCapableNode del,
-                       InstanceIdentifier<FlowCapableNode> nodeIdent) {
-        if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE)){
+            InstanceIdentifier<FlowCapableNode> nodeIdent) {
+        if (compareInstanceIdentifierTail(identifier, II_TO_FLOW_CAPABLE_NODE)) {
             if (LOG.isDebugEnabled()) {
-                LOG.debug("Node removed: {}",nodeIdent.firstKeyOf(Node.class).getId().getValue());
+                LOG.debug("Node removed: {}", nodeIdent.firstKeyOf(Node.class).getId().getValue());
             }
 
-            if ( ! nodeIdent.isWildcarded()) {
+            if (!nodeIdent.isWildcarded()) {
                 if (activeNodes.contains(nodeIdent)) {
                     synchronized (lockObj) {
                         if (activeNodes.contains(nodeIdent)) {
-                            Set<InstanceIdentifier<FlowCapableNode>> set =
-                                    Sets.newHashSet(activeNodes);
+                            Set<InstanceIdentifier<FlowCapableNode>> set = Sets.newHashSet(activeNodes);
                             set.remove(nodeIdent);
                             activeNodes = Collections.unmodifiableSet(set);
-                            setNodeOperationalStatus(nodeIdent,false);
+                            setNodeOperationalStatus(nodeIdent, false);
                         }
                     }
                 }
@@ -180,20 +176,20 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
     }
 
     public void add(InstanceIdentifier<FlowCapableNode> identifier, FlowCapableNode add,
-                    InstanceIdentifier<FlowCapableNode> nodeIdent) {
-        if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE)){
+            InstanceIdentifier<FlowCapableNode> nodeIdent) {
+        if (compareInstanceIdentifierTail(identifier, II_TO_FLOW_CAPABLE_NODE)) {
             if (LOG.isDebugEnabled()) {
-                LOG.debug("Node added: {}",nodeIdent.firstKeyOf(Node.class).getId().getValue());
+                LOG.debug("Node added: {}", nodeIdent.firstKeyOf(Node.class).getId().getValue());
             }
 
-            if ( ! nodeIdent.isWildcarded()) {
+            if (!nodeIdent.isWildcarded()) {
                 if (!activeNodes.contains(nodeIdent)) {
                     synchronized (lockObj) {
                         if (!activeNodes.contains(nodeIdent)) {
                             Set<InstanceIdentifier<FlowCapableNode>> set = Sets.newHashSet(activeNodes);
                             set.add(nodeIdent);
                             activeNodes = Collections.unmodifiableSet(set);
-                            setNodeOperationalStatus(nodeIdent,true);
+                            setNodeOperationalStatus(nodeIdent, true);
                         }
                     }
                 }
@@ -204,12 +200,7 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
     @Override
     public void close() {
         if (listenerRegistration != null) {
-            try {
-                listenerRegistration.close();
-            } catch (Exception e) {
-                LOG.warn("Error occurred while closing operational Node listener: {}", e.getMessage());
-                LOG.debug("Error occurred while closing operational Node listener", e);
-            }
+            listenerRegistration.close();
             listenerRegistration = null;
         }
         if (notifListenerRegistration != null) {
@@ -217,35 +208,37 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
         }
     }
 
-
     private boolean compareInstanceIdentifierTail(InstanceIdentifier<?> identifier1,
-                                                  InstanceIdentifier<?> identifier2) {
-        return Iterables.getLast(identifier1.getPathArguments()).equals(Iterables.getLast(identifier2.getPathArguments()));
+            InstanceIdentifier<?> identifier2) {
+        return Iterables.getLast(identifier1.getPathArguments())
+                .equals(Iterables.getLast(identifier2.getPathArguments()));
     }
 
     private void setNodeOperationalStatus(InstanceIdentifier<FlowCapableNode> nodeIid, boolean status) {
         NodeId nodeId = nodeIid.firstKeyOf(Node.class).getId();
-        if (nodeId != null ) {
-            if (deviceMasterships.containsKey(nodeId) ) {
+        if (nodeId != null) {
+            if (deviceMasterships.containsKey(nodeId)) {
                 deviceMasterships.get(nodeId).setDeviceOperationalStatus(status);
-                LOG.debug("Operational status of device {} is set to {}",nodeId, status);
+                LOG.debug("Operational status of device {} is set to {}", nodeId, status);
             }
         }
     }
-    private void registerNodeListener(){
+
+    @SuppressWarnings("IllegalCatch")
+    private void registerNodeListener() {
 
         final InstanceIdentifier<FlowCapableNode> flowNodeWildCardIdentifier = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class).augmentation(FlowCapableNode.class);
 
-        final DataTreeIdentifier<FlowCapableNode> treeId =
-                new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, flowNodeWildCardIdentifier);
+        final DataTreeIdentifier<FlowCapableNode> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+                flowNodeWildCardIdentifier);
 
         try {
             SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK,
                     ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES);
 
-            listenerRegistration = looper.loopUntilNoException(() ->
-                    dataBroker.registerDataTreeChangeListener(treeId, DeviceMastershipManager.this));
+            listenerRegistration = looper.loopUntilNoException(
+                () -> dataBroker.registerDataTreeChangeListener(treeId, DeviceMastershipManager.this));
         } catch (Exception e) {
             LOG.warn("Data listener registration failed: {}", e.getMessage());
             LOG.debug("Data listener registration failed ", e);