Do not guard registration with retries 17/104117/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 24 Jan 2023 22:35:17 +0000 (23:35 +0100)
committerSangwook Ha <sangwook.ha@verizon.com>
Wed, 25 Jan 2023 16:17:20 +0000 (08:17 -0800)
DTCL registration cannot really fail, do not loop on it needlessly.

Change-Id: Ifd0c1b820ada46cca921e09c3866e0bbc25fa9b4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Sangwook Ha <sangwook.ha@verizon.com>
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManager.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeConnectorInventoryTranslatorImpl.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ForwardingRulesManagerImpl.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ListenerRegistrationHelper.java
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/NodeConnectorInventoryEventTranslator.java
applications/of-switch-config-pusher/src/main/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusher.java
applications/table-miss-enforcer/src/main/java/org/opendaylight/openflowplugin/applications/tablemissenforcer/LLDPPacketPuntEnforcer.java
applications/topology-manager/src/main/java/org/opendaylight/openflowplugin/applications/topology/manager/DataTreeChangeListenerImpl.java

index f10635c544a13adaf7dddeb556eaed1153e80964..575de426b3dd8f4f83c0dd3e99b0fc2ac5537849 100644 (file)
@@ -29,7 +29,6 @@ import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeR
 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeService;
 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
 import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -52,7 +51,6 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
 
     private final ClusterSingletonServiceProvider clusterSingletonService;
     private final FlowNodeReconciliation reconcliationAgent;
-    private final DataBroker dataBroker;
     private final ConcurrentHashMap<NodeId, DeviceMastership> deviceMasterships = new ConcurrentHashMap<>();
     private final Object lockObj = new Object();
     private final RpcProviderService rpcProviderService;
@@ -73,8 +71,9 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
         this.reconcliationAgent = reconcliationAgent;
         this.rpcProviderService = rpcProviderService;
         reconcliationService = reconciliationService;
-        this.dataBroker = dataBroker;
-        registerNodeListener();
+        listenerRegistration = dataBroker.registerDataTreeChangeListener(
+            DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)), this);
         mastershipChangeServiceRegistration = mastershipChangeServiceManager.register(this);
     }
 
@@ -188,28 +187,6 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
         }
     }
 
-    @SuppressWarnings("IllegalCatch")
-    private void registerNodeListener() {
-
-        final InstanceIdentifier<FlowCapableNode> flowNodeWildCardIdentifier = InstanceIdentifier.create(Nodes.class)
-                .child(Node.class).augmentation(FlowCapableNode.class);
-
-        final DataTreeIdentifier<FlowCapableNode> treeId = DataTreeIdentifier.create(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));
-        } catch (Exception e) {
-            LOG.warn("Data listener registration failed: {}", e.getMessage());
-            LOG.debug("Data listener registration failed ", e);
-            throw new IllegalStateException("Node listener registration failed!", e);
-        }
-    }
-
     @Override
     public void onBecomeOwner(@NonNull final DeviceInfo deviceInfo) {
         LOG.debug("Mastership role notification received for device : {}", deviceInfo.getDatapathId());
index 95e5cadc5101efc88574157c732f0255399db0e4..b3b1519ea5df8edf3984cfd68a6b972b8bf89162 100644 (file)
@@ -18,12 +18,11 @@ import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.applications.frm.FlowNodeConnectorInventoryTranslator;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,40 +30,24 @@ import org.slf4j.LoggerFactory;
 public final class FlowNodeConnectorInventoryTranslatorImpl
         extends AbstractNodeConnectorCommitter<FlowCapableNodeConnector>
         implements FlowNodeConnectorInventoryTranslator {
-
     private static final Logger LOG = LoggerFactory.getLogger(FlowNodeConnectorInventoryTranslatorImpl.class);
-
-    private ListenerRegistration<FlowNodeConnectorInventoryTranslatorImpl> dataTreeChangeListenerRegistration;
-
     private static final String SEPARATOR = ":";
-
-    private static final InstanceIdentifier<FlowCapableNodeConnector> II_TO_FLOW_CAPABLE_NODE_CONNECTOR
-            = InstanceIdentifier.builder(Nodes.class)
+    private static final InstanceIdentifier<FlowCapableNodeConnector> II_TO_FLOW_CAPABLE_NODE_CONNECTOR =
+        InstanceIdentifier.builder(Nodes.class)
             .child(Node.class)
             .child(NodeConnector.class)
             .augmentation(FlowCapableNodeConnector.class)
             .build();
 
-    private final Multimap<BigInteger, String> dpnToPortMultiMap = Multimaps
-            .synchronizedListMultimap(ArrayListMultimap.create());
+    private Registration listenerRegistration;
+
+    private final Multimap<BigInteger, String> dpnToPortMultiMap = Multimaps.synchronizedListMultimap(
+        ArrayListMultimap.create());
 
-    @SuppressWarnings("IllegalCatch")
     public FlowNodeConnectorInventoryTranslatorImpl(final DataBroker dataBroker) {
         requireNonNull(dataBroker, "DataBroker can not be null!");
-
-        final DataTreeIdentifier<FlowCapableNodeConnector> treeId =
-                DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, getWildCardPath());
-        try {
-            SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK,
-                    ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES);
-            dataTreeChangeListenerRegistration = looper.loopUntilNoException(() -> dataBroker
-                    .registerDataTreeChangeListener(treeId, FlowNodeConnectorInventoryTranslatorImpl.this));
-        } catch (final Exception e) {
-            LOG.warn(" FlowNodeConnectorInventoryTranslatorImpl listener registration fail!");
-            LOG.debug("FlowNodeConnectorInventoryTranslatorImpl DataTreeChangeListener registration fail ..", e);
-            throw new
-            IllegalStateException("FlowNodeConnectorInventoryTranslatorImpl startup fail! System needs restart.", e);
-        }
+        listenerRegistration = dataBroker.registerDataTreeChangeListener(
+            DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, getWildCardPath()), this);
     }
 
     @Override
@@ -77,9 +60,9 @@ public final class FlowNodeConnectorInventoryTranslatorImpl
 
     @Override
     public void close() {
-        if (dataTreeChangeListenerRegistration != null) {
-            dataTreeChangeListenerRegistration.close();
-            dataTreeChangeListenerRegistration = null;
+        if (listenerRegistration != null) {
+            listenerRegistration.close();
+            listenerRegistration = null;
         }
     }
 
index 7b62d7025051613953224c27a6e6c65c769f7670..cd0f6722063f99b76cc929315979d3b84da46cfa 100644 (file)
@@ -71,8 +71,6 @@ import org.slf4j.LoggerFactory;
 public final class ForwardingRulesManagerImpl implements ForwardingRulesManager {
     private static final Logger LOG = LoggerFactory.getLogger(ForwardingRulesManagerImpl.class);
 
-    static final int STARTUP_LOOP_TICK = 1000;
-    static final int STARTUP_LOOP_MAX_RETRIES = 240;
     private static final int FRM_RECONCILIATION_PRIORITY = Integer.getInteger("frm.reconciliation.priority", 1);
     private static final String SERVICE_NAME = "FRM";
 
@@ -165,7 +163,7 @@ public final class ForwardingRulesManagerImpl implements ForwardingRulesManager
         devicesGroupRegistry = new DevicesGroupRegistry();
         nodeListener = new FlowNodeReconciliationImpl(this, dataService, SERVICE_NAME, FRM_RECONCILIATION_PRIORITY,
                 ResultState.DONOTHING, flowGroupCacheManager);
-        if (this.isReconciliationDisabled()) {
+        if (isReconciliationDisabled()) {
             LOG.debug("Reconciliation is disabled by user");
         } else {
             reconciliationNotificationRegistration = reconciliationManager.registerService(nodeListener);
index cf64fdf22b1b5cf0697bde431cb160555afc919b..e01c3cd43492bf5c543d24b9c20c8ccceff2d2c8 100644 (file)
@@ -20,17 +20,16 @@ import javax.inject.Singleton;
 import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 @Singleton
 public class ListenerRegistrationHelper {
     private static final Logger LOG = LoggerFactory.getLogger(ListenerRegistrationHelper.class);
     private static final long INVENTORY_CHECK_TIMER = 1;
+
     private final String operational = "OPERATIONAL";
     private final ListeningExecutorService listeningExecutorService;
     private final DataBroker dataBroker;
@@ -39,7 +38,7 @@ public class ListenerRegistrationHelper {
     public ListenerRegistrationHelper(final DataBroker dataBroker) {
         this.dataBroker = dataBroker;
         listeningExecutorService = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor(
-                 new ThreadFactoryBuilder()
+            new ThreadFactoryBuilder()
                 .setNameFormat("frm-listener" + "%d")
                 .setDaemon(false)
                 .setUncaughtExceptionHandler((thread, ex) -> LOG.error("Uncaught exception {}", thread, ex))
@@ -47,10 +46,10 @@ public class ListenerRegistrationHelper {
     }
 
     public <T extends DataObject, L extends ClusteredDataTreeChangeListener<T>>
-        ListenableFuture<ListenerRegistration<L>>
-        checkedRegisterListener(DataTreeIdentifier<T> treeId, L listener) {
+            ListenableFuture<ListenerRegistration<L>> checkedRegisterListener(
+                DataTreeIdentifier<T> treeId, L listener) {
         return listeningExecutorService.submit(() -> {
-            while (! getInventoryConfigDataStoreStatus().equals(operational)) {
+            while (!getInventoryConfigDataStoreStatus().equals(operational)) {
                 try {
                     LOG.debug("Retrying for datastore to become operational for listener {}", listener);
                     Thread.sleep(INVENTORY_CHECK_TIMER * 1000);
@@ -59,13 +58,11 @@ public class ListenerRegistrationHelper {
                     Thread.currentThread().interrupt();
                 }
             }
-            SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK,
-                    ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES);
-            return looper.loopUntilNoException(() -> dataBroker.registerDataTreeChangeListener(treeId, listener));
+            return dataBroker.registerDataTreeChangeListener(treeId, listener);
         });
     }
 
     public void close() throws Exception {
         MoreExecutors.shutdownAndAwaitTermination(listeningExecutorService, 5, TimeUnit.SECONDS);
     }
-}
\ No newline at end of file
+}
index fe59607dc3c36a4acd8bb7db209ae16788da794d..dbeb3dd89b0c5525e229b4d0a3abff608716a2cb 100644 (file)
@@ -16,11 +16,9 @@ import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
@@ -29,7 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.f
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -39,7 +37,7 @@ import org.slf4j.LoggerFactory;
  * NodeConnectorInventoryEventTranslator is listening for changes in inventory operational DOM tree
  * and update LLDPSpeaker and topology.
  */
-public class NodeConnectorInventoryEventTranslator<T extends DataObject>
+public final class NodeConnectorInventoryEventTranslator<T extends DataObject>
         implements ClusteredDataTreeChangeListener<T>, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(NodeConnectorInventoryEventTranslator.class);
 
@@ -51,35 +49,22 @@ public class NodeConnectorInventoryEventTranslator<T extends DataObject>
             = InstanceIdentifier.builder(Nodes.class).child(Node.class).child(NodeConnector.class)
             .augmentation(FlowCapableNodeConnector.class).build();
 
-    private static final long STARTUP_LOOP_TICK = 500L;
-    private static final int STARTUP_LOOP_MAX_RETRIES = 8;
-
-    private final ListenerRegistration<DataTreeChangeListener> listenerOnPortRegistration;
-    private final ListenerRegistration<DataTreeChangeListener> listenerOnPortStateRegistration;
+    private final Registration listenerOnPortRegistration;
+    private final Registration listenerOnPortStateRegistration;
     private final Set<NodeConnectorEventsObserver> observers;
     private final Map<InstanceIdentifier<?>, FlowCapableNodeConnector> iiToDownFlowCapableNodeConnectors
             = new HashMap<>();
 
-    @SuppressWarnings("IllegalCatch")
     public NodeConnectorInventoryEventTranslator(final DataBroker dataBroker,
             final NodeConnectorEventsObserver... observers) {
         this.observers = ImmutableSet.copyOf(observers);
+
         final DataTreeIdentifier dtiToNodeConnector = DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
                                                                                    II_TO_FLOW_CAPABLE_NODE_CONNECTOR);
         final DataTreeIdentifier dtiToNodeConnectorState = DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
                                                                                    II_TO_STATE);
-        final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
-        try {
-            listenerOnPortRegistration = looper.loopUntilNoException(() ->
-                    dataBroker.registerDataTreeChangeListener(dtiToNodeConnector,
-                            NodeConnectorInventoryEventTranslator.this));
-            listenerOnPortStateRegistration = looper.loopUntilNoException(() ->
-                    dataBroker.registerDataTreeChangeListener(dtiToNodeConnectorState,
-                            NodeConnectorInventoryEventTranslator.this));
-        } catch (Exception e) {
-            LOG.error("DataTreeChangeListeners registration failed", e);
-            throw new IllegalStateException("NodeConnectorInventoryEventTranslator startup failed!", e);
-        }
+        listenerOnPortRegistration = dataBroker.registerDataTreeChangeListener(dtiToNodeConnector, this);
+        listenerOnPortStateRegistration = dataBroker.registerDataTreeChangeListener(dtiToNodeConnectorState, this);
         LOG.info("NodeConnectorInventoryEventTranslator has started.");
     }
 
index 4f891948446e4608835765ef17d67db1d6001085..12a1094b55dcc4871dacebff483d776eed4e506b 100644 (file)
@@ -23,7 +23,6 @@ import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -31,7 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N
 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,12 +38,12 @@ import org.slf4j.LoggerFactory;
 @Singleton
 public class DefaultConfigPusher implements AutoCloseable, ClusteredDataTreeChangeListener<FlowCapableNode> {
     private static final Logger LOG = LoggerFactory.getLogger(DefaultConfigPusher.class);
-    private static final long STARTUP_LOOP_TICK = 500L;
-    private static final int STARTUP_LOOP_MAX_RETRIES = 8;
+
     private final NodeConfigService nodeConfigService;
     private final DataBroker dataBroker;
     private final DeviceOwnershipService deviceOwnershipService;
-    private ListenerRegistration<?> listenerRegistration;
+
+    private Registration listenerRegistration;
 
     @Inject
     public DefaultConfigPusher(final NodeConfigService nodeConfigService, final DataBroker dataBroker,
@@ -54,21 +53,12 @@ public class DefaultConfigPusher implements AutoCloseable, ClusteredDataTreeChan
         this.deviceOwnershipService = requireNonNull(deviceOwnershipService, "DeviceOwnershipService can not be null");
     }
 
-    @SuppressWarnings("checkstyle:IllegalCatch")
     @PostConstruct
     public void start() {
-        try {
-            final InstanceIdentifier<FlowCapableNode> path = InstanceIdentifier.create(Nodes.class).child(Node.class)
-                    .augmentation(FlowCapableNode.class);
-            final DataTreeIdentifier<FlowCapableNode> identifier = DataTreeIdentifier.create(
-                    LogicalDatastoreType.OPERATIONAL, path);
-            final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
-            listenerRegistration = looper.loopUntilNoException(
-                () -> dataBroker.registerDataTreeChangeListener(identifier, DefaultConfigPusher.this));
-        } catch (Exception e) {
-            LOG.error("DataTreeChangeListener registration failed", e);
-            throw new IllegalStateException("DefaultConfigPusher startup failed!", e);
-        }
+        listenerRegistration = dataBroker.registerDataTreeChangeListener(
+            DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)),
+            this);
         LOG.info("DefaultConfigPusher has started.");
     }
 
index 4736de4491db94aaf3d0ffc52f809e6ea2b06117..b9bd16d3e26708216131f0a254161bc9ed747976 100644 (file)
@@ -19,7 +19,6 @@ import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
@@ -42,7 +41,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.Uint16;
@@ -53,15 +52,14 @@ import org.slf4j.LoggerFactory;
 
 public class LLDPPacketPuntEnforcer implements AutoCloseable, ClusteredDataTreeChangeListener<FlowCapableNode> {
     private static final Logger LOG = LoggerFactory.getLogger(LLDPPacketPuntEnforcer.class);
-    private static final long STARTUP_LOOP_TICK = 500L;
-    private static final int STARTUP_LOOP_MAX_RETRIES = 8;
     private static final Uint8 TABLE_ID = Uint8.ZERO;
     private static final String LLDP_PUNT_WHOLE_PACKET_FLOW = "LLDP_PUNT_WHOLE_PACKET_FLOW";
     private static final String DEFAULT_FLOW_ID = "42";
+
     private final SalFlowService flowService;
     private final DataBroker dataBroker;
     private final DeviceOwnershipService deviceOwnershipService;
-    private ListenerRegistration<?> listenerRegistration;
+    private Registration listenerRegistration;
 
     public LLDPPacketPuntEnforcer(final SalFlowService flowService, final DataBroker dataBroker,
             final DeviceOwnershipService deviceOwnershipService) {
@@ -70,19 +68,11 @@ public class LLDPPacketPuntEnforcer implements AutoCloseable, ClusteredDataTreeC
         this.deviceOwnershipService = requireNonNull(deviceOwnershipService, "DeviceOwnershipService can not be null");
     }
 
-    @SuppressWarnings("IllegalCatch")
     public void start() {
-        final InstanceIdentifier<FlowCapableNode> path = InstanceIdentifier.create(Nodes.class).child(Node.class)
-                .augmentation(FlowCapableNode.class);
-        final DataTreeIdentifier<FlowCapableNode> identifier = DataTreeIdentifier.create(
-                LogicalDatastoreType.OPERATIONAL, path);
-        SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
-        try {
-            listenerRegistration = looper.loopUntilNoException(() ->
-                dataBroker.registerDataTreeChangeListener(identifier, LLDPPacketPuntEnforcer.this));
-        } catch (Exception e) {
-            throw new IllegalStateException("registerDataTreeChangeListener failed", e);
-        }
+        listenerRegistration = dataBroker.registerDataTreeChangeListener(
+            DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)),
+            this);
     }
 
     @Override
@@ -102,7 +92,7 @@ public class LLDPPacketPuntEnforcer implements AutoCloseable, ClusteredDataTreeC
                     AddFlowInputBuilder addFlowInput = new AddFlowInputBuilder(createFlow());
                     addFlowInput.setNode(new NodeRef(modification.getRootPath()
                             .getRootIdentifier().firstIdentifierOf(Node.class)));
-                    LoggingFutures.addErrorLogging(this.flowService.addFlow(addFlowInput.build()), LOG, "addFlow");
+                    LoggingFutures.addErrorLogging(flowService.addFlow(addFlowInput.build()), LOG, "addFlow");
                 } else {
                     LOG.debug("Node {} is not owned by this controller, so skip adding LLDP table miss flow", nodeId);
                 }
index 61860351094d97238d9e52a1340f2b5c4d17d70f..46f70c3a8ade66bde3ac63379f3ebda1e019f0b4 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.openflowplugin.applications.topology.manager;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
@@ -22,33 +22,21 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public abstract class DataTreeChangeListenerImpl<T extends DataObject> implements DataTreeChangeListener<T>,
         AutoCloseable {
+    static final InstanceIdentifier<Topology> II_TO_TOPOLOGY = InstanceIdentifier.create(NetworkTopology.class)
+        .child(Topology.class, new TopologyKey(new TopologyId(FlowCapableTopologyProvider.TOPOLOGY_ID)));
 
-    private static final Logger LOG = LoggerFactory.getLogger(DataTreeChangeListenerImpl.class);
-    private static final long STARTUP_LOOP_TICK = 500L;
-    private static final int STARTUP_LOOP_MAX_RETRIES = 8;
     protected final ListenerRegistration<?> listenerRegistration;
     protected OperationProcessor operationProcessor;
 
-    static final InstanceIdentifier<Topology> II_TO_TOPOLOGY = InstanceIdentifier.create(NetworkTopology.class)
-            .child(Topology.class, new TopologyKey(new TopologyId(FlowCapableTopologyProvider.TOPOLOGY_ID)));
-
-    @SuppressWarnings("checkstyle:IllegalCatch")
+    @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR",
+        justification = "'this' passed to registerDataTreeChangeListener")
     public DataTreeChangeListenerImpl(final OperationProcessor operationProcessor, final DataBroker dataBroker,
-                               final InstanceIdentifier<T> ii) {
-        final DataTreeIdentifier<T> identifier = DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, ii);
-        final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
-        try {
-            listenerRegistration = looper.loopUntilNoException(
-                () -> dataBroker.registerDataTreeChangeListener(identifier, DataTreeChangeListenerImpl.this));
-        } catch (Exception e) {
-            LOG.error("Data listener registration failed!");
-            throw new IllegalStateException("TopologyManager startup fail! TM bundle needs restart.", e);
-        }
+            final InstanceIdentifier<T> ii) {
+        listenerRegistration = dataBroker.registerDataTreeChangeListener(
+            DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, ii), this);
         this.operationProcessor = operationProcessor;
     }
 
@@ -57,7 +45,7 @@ public abstract class DataTreeChangeListenerImpl<T extends DataObject> implement
         listenerRegistration.close();
     }
 
-    <T extends DataObject> void sendToTransactionChain(final T node, final InstanceIdentifier<T> iiToTopologyNode) {
+    <O extends DataObject> void sendToTransactionChain(final O node, final InstanceIdentifier<O> iiToTopologyNode) {
         operationProcessor.enqueueOperation(
             manager -> manager.mergeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTopologyNode, node, true));
     }