Remove LocRibWriter registration on close() 27/22327/1
authorRobert Varga <rovarga@cisco.com>
Wed, 10 Jun 2015 18:23:25 +0000 (20:23 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Thu, 11 Jun 2015 07:04:16 +0000 (07:04 +0000)
Retain the DataTreeChangeListenerRegistration we get when we subscribe
and cancel it when we are being shut down. Also place two FIXMEs for
future work.

Change-Id: I74364473736e863e63557e8ebf652424ea312a59
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit c1206aa82aaf35f93a2b74f83dea8fd2dd5eb048)

bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java

index 26f95b1c6442a6b0ba0286579aefe2d2a99e8b6d..7743d2d4939d67b71e0ce88f68356d30aa7f3d83 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -71,6 +72,7 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
     private final RIBSupport ribSupport;
     private final NodeIdentifierWithPredicates tableKey;
     private final RIBSupportContextRegistry registry;
+    private final ListenerRegistration<LocRibWriter> reg;
 
     LocRibWriter(final RIBSupportContextRegistry registry, final DOMTransactionChain chain, final YangInstanceIdentifier target, final Long ourAs,
         final DOMDataTreeChangeService service, final PolicyDatabase pd, final TablesKey tablesKey) {
@@ -89,7 +91,8 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
         tx.submit();
 
         final YangInstanceIdentifier tableId = target.node(Peer.QNAME).node(Peer.QNAME);
-        service.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, tableId), this);
+
+        this.reg = service.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, tableId), this);
     }
 
     public static LocRibWriter create(@Nonnull final RIBSupportContextRegistry registry, @Nonnull final TablesKey tablesKey, @Nonnull final DOMTransactionChain chain, @Nonnull final YangInstanceIdentifier target,
@@ -99,6 +102,9 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
 
     @Override
     public void close() {
+        this.reg.close();
+        // FIXME: wipe the local rib
+        // FIXME: wait for the chain to close? unfortunately RIBImpl is the listener, so that may require some work
         this.chain.close();
     }
 
index 13571b8a57a537f6687abf0ef4fc7d48db4e8fa1..d4182622536c0219d433cf079c19156eca51f19b 100644 (file)
@@ -178,6 +178,8 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
         } catch (final TransactionCommitFailedException e1) {
             LOG.error("Failed to initiate LocRIB for key {}", key, e1);
         }
+
+        // FIXME: do not lose the writer so we clean it up on shutdown
         LocRibWriter.create(this.ribContextRegistry, key, this.createPeerChain(this), getYangRibId(), this.localAs, getService(), pd);
     }