Fix transaction manager closing.
[openflowplugin.git] / applications / topology-manager / src / main / java / org / opendaylight / openflowplugin / applications / topology / manager / DataTreeChangeListenerImpl.java
index b295bcb8493aae43e258a7ce81c4e042d417fdae..362857368d4f8e379806100397ba87fcd743faac 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -7,11 +7,9 @@
  */
 package org.opendaylight.openflowplugin.applications.topology.manager;
 
-import java.util.concurrent.Callable;
 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.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
@@ -38,23 +36,19 @@ public abstract class DataTreeChangeListenerImpl<T extends DataObject> implement
     /**
      * instance identifier to Node in network topology model (yangtools)
      */
-    protected static final InstanceIdentifier<Topology> II_TO_TOPOLOGY =
+    static final InstanceIdentifier<Topology> II_TO_TOPOLOGY =
             InstanceIdentifier
             .create(NetworkTopology.class)
             .child(Topology.class, new TopologyKey(new TopologyId(FlowCapableTopologyProvider.TOPOLOGY_ID)));
 
-    public DataTreeChangeListenerImpl(final OperationProcessor operationProcessor,
-                                      final DataBroker dataBroker,
-                                      final InstanceIdentifier<T> ii) {
+    DataTreeChangeListenerImpl(final OperationProcessor operationProcessor,
+                               final DataBroker dataBroker,
+                               final InstanceIdentifier<T> ii) {
         final DataTreeIdentifier<T> identifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, ii);
         final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
         try {
-            listenerRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<DataTreeChangeListener>>() {
-                @Override
-                public ListenerRegistration<DataTreeChangeListener> call() throws Exception {
-                    return dataBroker.registerDataTreeChangeListener(identifier, DataTreeChangeListenerImpl.this);
-                }
-            });
+            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);
@@ -67,16 +61,11 @@ public abstract class DataTreeChangeListenerImpl<T extends DataObject> implement
         listenerRegistration.close();
     }
 
-    protected <T extends DataObject> void sendToTransactionChain(final T node, final InstanceIdentifier<T> iiToTopologyNode) {
-        operationProcessor.enqueueOperation(new TopologyOperation() {
-            @Override
-            public void applyOperation(ReadWriteTransaction transaction) {
-                transaction.merge(LogicalDatastoreType.OPERATIONAL, iiToTopologyNode, node, true);
-            }
-        });
+    <T extends DataObject> void sendToTransactionChain(final T node, final InstanceIdentifier<T> iiToTopologyNode) {
+        operationProcessor.enqueueOperation(manager -> manager.mergeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTopologyNode, node, true));
     }
 
-    protected InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> provideIIToTopologyNode(
+    InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> provideIIToTopologyNode(
             final NodeId nodeIdInTopology) {
         org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey nodeKeyInTopology = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey(
                 nodeIdInTopology);
@@ -86,8 +75,8 @@ public abstract class DataTreeChangeListenerImpl<T extends DataObject> implement
                         nodeKeyInTopology).build();
     }
 
-    protected NodeId provideTopologyNodeId(InstanceIdentifier<T> iiToNodeInInventory) {
-        final NodeKey inventoryNodeKey = iiToNodeInInventory.firstKeyOf(Node.class, NodeKey.class);
+    NodeId provideTopologyNodeId(InstanceIdentifier<T> iiToNodeInInventory) {
+        final NodeKey inventoryNodeKey = iiToNodeInInventory.firstKeyOf(Node.class);
         if (inventoryNodeKey != null) {
             return new NodeId(inventoryNodeKey.getId().getValue());
         }