Remove TopologyStatsRpcServiceImpl.init() 64/100664/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Apr 2022 08:00:51 +0000 (10:00 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Apr 2022 08:30:51 +0000 (10:30 +0200)
There is just no point in splitting initialization here, remove the
method and initialize in the constructor.

JIRA: BGPCEP-1005
Change-Id: I4fae3966888cc589e994106dc0d58014dd6ccf15
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/topology/topology-stats/src/main/java/org/opendaylight/bgpcep/pcep/topology/stats/rpc/TopologyStatsRpcServiceImpl.java
pcep/topology/topology-stats/src/main/resources/OSGI-INF/blueprint/pcep-stats.xml
pcep/topology/topology-stats/src/test/java/org/opendaylight/bgpcep/pcep/topology/stats/rpc/TopologyStatsRpcServiceImplTest.java

index 1138a00d20d41b70061f5e7756f1e60fb29f4026..f7850c523a02c8c1845a778012553ddf7138388d 100644 (file)
@@ -5,11 +5,8 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.bgpcep.pcep.topology.stats.rpc;
 
-import static java.util.Objects.requireNonNull;
-
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collection;
@@ -57,26 +54,21 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class TopologyStatsRpcServiceImpl
+public final class TopologyStatsRpcServiceImpl
         implements PcepTopologyStatsRpcService, ClusteredDataTreeChangeListener<PcepSessionState>, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(TopologyStatsRpcServiceImpl.class);
 
-    private final DataBroker dataBroker;
     private final ConcurrentMap<InstanceIdentifier<PcepSessionState>, PcepSessionState> sessionStateMap =
             new ConcurrentHashMap<>();
     private ListenerRegistration<TopologyStatsRpcServiceImpl> listenerRegistration;
 
     public TopologyStatsRpcServiceImpl(final DataBroker dataBroker) {
-        this.dataBroker = requireNonNull(dataBroker);
-    }
-
-    public synchronized void init() {
         LOG.info("Initializing PCEP Topology Stats RPC service.");
-        this.listenerRegistration = this.dataBroker.registerDataTreeChangeListener(
-                DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
-                        InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class).child(Node.class)
-                                .augmentation(PcepTopologyNodeStatsAug.class).child(PcepSessionState.class).build()),
-                this);
+        listenerRegistration = dataBroker.registerDataTreeChangeListener(
+            DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class).child(Node.class)
+                    .augmentation(PcepTopologyNodeStatsAug.class).child(PcepSessionState.class).build()),
+            this);
     }
 
     @Override
@@ -99,10 +91,10 @@ public class TopologyStatsRpcServiceImpl
 
     @Override
     public synchronized void close() {
-        LOG.info("Closing PCEP Topology Stats RPC service.");
-        if (this.listenerRegistration != null) {
-            this.listenerRegistration.close();
-            this.listenerRegistration = null;
+        if (listenerRegistration != null) {
+            LOG.info("Closing PCEP Topology Stats RPC service.");
+            listenerRegistration.close();
+            listenerRegistration = null;
         }
     }
 
index 08eddbd689d003038a744a5285a01a179982498b..b5a0b560e49935231bb80b8113d48210924cd277 100644 (file)
@@ -15,7 +15,7 @@
 
     <bean id="topologyStatsRpcService"
           class="org.opendaylight.bgpcep.pcep.topology.stats.rpc.TopologyStatsRpcServiceImpl"
-          init-method="init" destroy-method="close">
+          destroy-method="close">
         <argument ref="dataBroker"/>
     </bean>
     <odl:rpc-implementation ref="topologyStatsRpcService"/>
index f0ea7936ddd3b51d59690d77505b805dd81e5c69..bb1b67f51c7c8180816945e1c517de83d60f2a0c 100644 (file)
@@ -78,7 +78,6 @@ public class TopologyStatsRpcServiceImplTest extends AbstractConcurrentDataBroke
     @Before
     public void setUp() throws Exception {
         rpcService = new TopologyStatsRpcServiceImpl(getDataBroker());
-        rpcService.init();
 
         // PCEP topology with one PCC node
         final Topology t1 = createTopology(TOPOLOGY_ID1, BindingMap.of(createPcepNode(NODE_ID1)));