BUG-4117: Adding Retries during DTCL registration 67/39967/8
authorShuva Kar <shuva.jyoti.kar@ericsson.com>
Tue, 7 Jun 2016 17:46:22 +0000 (23:16 +0530)
committerShuva Jyoti Kar <shuva.jyoti.kar@ericsson.com>
Thu, 21 Jul 2016 07:53:58 +0000 (07:53 +0000)
Change-Id: I38427b63e4047895dcbcd976f02d57e2981d3518
Signed-off-by: Shuva Kar <shuva.jyoti.kar@ericsson.com>
applications/notification-supplier/pom.xml
applications/notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/notification/supplier/impl/AbstractNotificationSupplierBase.java

index 4f8cf5cf32f11d32172dd881bd4fa4cca12f193b..1211609e12efed8e0e2008add6f1621c969a76be 100644 (file)
             <artifactId>config-api</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.opendaylight.openflowplugin</groupId>
+            <artifactId>openflowplugin-common</artifactId>
+        </dependency>
+
         <!-- Test dependencies -->
         <dependency>
             <groupId>org.mockito</groupId>
@@ -53,7 +58,6 @@
             <scope>test</scope>
         </dependency>
     </dependencies>
-
     <build>
         <plugins>
             <plugin>
index 10a1262778cf535d9a1738eb460e96cf2630e089..4ae214f7c91d7f94c2a66ab6878e737f147ca0e7 100644 (file)
@@ -12,9 +12,9 @@ import com.google.common.base.Preconditions;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.applications.notification.supplier.NotificationSupplierDefinition;
+import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -24,6 +24,10 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.Callable;
 
 /**
  * Public abstract basic Supplier implementation contains code for a make Supplier instance,
@@ -35,9 +39,16 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 public abstract class AbstractNotificationSupplierBase<O extends DataObject> implements
         NotificationSupplierDefinition<O> {
 
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractNotificationSupplierBase.class);
+
     protected final Class<O> clazz;
-    private ListenerRegistration<DataTreeChangeListener> listenerRegistration;
+    private ListenerRegistration<DataTreeChangeListener<O>> listenerRegistration;
+    private static final int STARTUP_LOOP_TICK = 500;
+    private static final int STARTUP_LOOP_MAX_RETRIES = 8;
+
 
+    final DataTreeIdentifier<O> treeId =
+            new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, getWildCardPath());
     /**
      * Default constructor for all Notification Supplier implementation
      *
@@ -46,10 +57,20 @@ public abstract class AbstractNotificationSupplierBase<O extends DataObject> imp
      */
     public AbstractNotificationSupplierBase(final DataBroker db, final Class<O> clazz) {
         Preconditions.checkArgument(db != null, "DataBroker can not be null!");
-        //TODO retries
-        listenerRegistration = db.registerDataTreeChangeListener( new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
-                getWildCardPath()),this);
         this.clazz = clazz;
+
+        SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
+        try {
+            listenerRegistration =  looper.loopUntilNoException(new Callable<ListenerRegistration<DataTreeChangeListener<O>>>() {
+                @Override
+                public ListenerRegistration<DataTreeChangeListener<O>> call() throws Exception {
+                    return db.registerDataTreeChangeListener(treeId, AbstractNotificationSupplierBase.this);
+                }
+            });
+        }catch(final Exception ex){
+            LOG.debug(" AbstractNotificationSupplierBase DataChange listener registration fail ..{}", ex.getMessage());
+            throw new IllegalStateException("Notification supplier startup fail! System needs restart.", ex);
+        }
     }
 
     @Override