Convert ListenerRegistrationHelper into a component
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / frm / impl / ListenerRegistrationHelper.java
index 9410feae01261884371fc849b5ecbf80a1cfb4d2..9b3b98928296deefb8496111f2c8e717f7a75b28 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -7,61 +7,16 @@
  */
 package org.opendaylight.openflowplugin.applications.frm.impl;
 
-import static org.opendaylight.openflowplugin.applications.frm.util.FrmUtil.getInventoryConfigDataStoreStatus;
-
 import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.common.util.concurrent.MoreExecutors;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import javax.inject.Inject;
-import javax.inject.Singleton;
+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.DataTreeIdentifier;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
 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 ListeningExecutorService listeningExecutorService;
-    private final DataBroker dataBroker;
-
-    @Inject
-    public ListenerRegistrationHelper(final DataBroker dataBroker) {
-        this.dataBroker = dataBroker;
-        listeningExecutorService = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor(
-            new ThreadFactoryBuilder()
-                .setNameFormat("frm-listener" + "%d")
-                .setDaemon(false)
-                .setUncaughtExceptionHandler((thread, ex) -> LOG.error("Uncaught exception {}", thread, ex))
-                .build()));
-    }
 
-    public <T extends DataObject, L extends ClusteredDataTreeChangeListener<T>>
-            ListenableFuture<ListenerRegistration<L>> checkedRegisterListener(
-                final DataTreeIdentifier<T> treeId, final L listener) {
-        return listeningExecutorService.submit(() -> {
-            while (!getInventoryConfigDataStoreStatus().equals("OPERATIONAL")) {
-                try {
-                    LOG.debug("Retrying for datastore to become operational for listener {}", listener);
-                    Thread.sleep(INVENTORY_CHECK_TIMER * 1000);
-                } catch (InterruptedException e) {
-                    LOG.info("registerDataTreeChangeListener thread is interrupted");
-                    Thread.currentThread().interrupt();
-                }
-            }
-            return dataBroker.registerDataTreeChangeListener(treeId, listener);
-        });
-    }
+// Needed only for BluePrint coexistence
+public interface ListenerRegistrationHelper {
 
-    public void close() throws Exception {
-        MoreExecutors.shutdownAndAwaitTermination(listeningExecutorService, 5, TimeUnit.SECONDS);
-    }
-}
+    <T extends DataObject> @NonNull ListenableFuture<ObjectRegistration<?>> checkedRegisterListener(
+        DataTreeIdentifier<T> treeId, ClusteredDataTreeChangeListener<T> listener);
+}
\ No newline at end of file