BUG-731: hide serverSessionManager
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / AbstractTopologySessionListener.java
index 6281d4151a9ff8623146a130a62a48ee402eedea..c3cdc667a2fe9abc5dd2697eac8d8b67cf7ac277 100644 (file)
@@ -42,6 +42,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -71,13 +72,11 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
        };
        private static final Logger LOG = LoggerFactory.getLogger(AbstractTopologySessionListener.class);
 
-       // FIXME: make this private
-       protected final ServerSessionManager serverSessionManager;
-
        private final Map<SRPID, PCEPRequest> waitingRequests = new HashMap<>();
        private final Map<SRPID, PCEPRequest> sendingRequests = new HashMap<>();
        private final Map<String, ReportedLsp> lspData = new HashMap<>();
        private final Map<PLSPID, String> lsps = new HashMap<>();
+       private final ServerSessionManager serverSessionManager;
        private InstanceIdentifier<Node> topologyNode;
        private InstanceIdentifier<Node1> topologyAugment;
        private PathComputationClientBuilder pccBuilder;
@@ -102,7 +101,7 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
                for (final Node n : topo.getNode()) {
                        LOG.debug("Matching topology node {} to id {}", n, pccId);
                        if (n.getNodeId().getValue().equals(pccId)) {
-                               this.topologyNode = InstanceIdentifier.builder(this.serverSessionManager.getTopology()).child(Node.class, n.getKey()).toInstance();
+                               this.topologyNode = this.serverSessionManager.getTopology().child(Node.class, n.getKey());
                                LOG.debug("Reusing topology node {} for id {} at {}", n, pccId, this.topologyNode);
                                return n;
                        }
@@ -114,7 +113,7 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
                 */
                final NodeId id = new NodeId(pccId);
                final NodeKey nk = new NodeKey(id);
-               final InstanceIdentifier<Node> nti = InstanceIdentifier.builder(this.serverSessionManager.getTopology()).child(Node.class, nk).toInstance();
+               final InstanceIdentifier<Node> nti = this.serverSessionManager.getTopology().child(Node.class, nk);
 
                final Node ret = new NodeBuilder().setKey(nk).setNodeId(id).build();
 
@@ -147,7 +146,7 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
                onSessionUp(session, this.pccBuilder);
 
                this.topologyAugmentBuilder = new Node1Builder().setPathComputationClient(this.pccBuilder.build());
-               this.topologyAugment = InstanceIdentifier.builder(this.topologyNode).augmentation(Node1.class).toInstance();
+               this.topologyAugment = this.topologyNode.augmentation(Node1.class);
                final Node1 ta = this.topologyAugmentBuilder.build();
 
                trans.putOperationalData(this.topologyAugment, ta);
@@ -243,7 +242,7 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
                        this.topologyAugmentBuilder.setPathComputationClient(this.pccBuilder.build());
                        final Node1 ta = this.topologyAugmentBuilder.build();
 
-                       //trans.removeOperationalData(this.topologyAugment);
+                       trans.removeOperationalData(this.topologyAugment);
                        trans.putOperationalData(this.topologyAugment, ta);
                        LOG.debug("Peer data {} set to {}", this.topologyAugment, ta);
                        dirty = false;
@@ -273,7 +272,7 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
        }
 
        protected InstanceIdentifierBuilder<PathComputationClient> pccIdentifier() {
-               return InstanceIdentifier.builder(this.topologyAugment).child(PathComputationClient.class);
+               return this.topologyAugment.builder().child(PathComputationClient.class);
        }
 
        protected final synchronized PCEPRequest removeRequest(final SRPID id) {
@@ -308,15 +307,20 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
                return req.getFuture();
        }
 
-       protected final synchronized void updateLsp(final DataModificationTransaction trans, final PLSPID id, String name,
+       protected final synchronized void updateLsp(final DataModificationTransaction trans, final PLSPID id, final String lspName,
                        final ReportedLspBuilder rlb, final boolean solicited) {
-               if (name == null) {
+
+               final String name;
+               if (lspName == null) {
                        name = this.lsps.get(id);
                        if (name == null) {
                                LOG.error("PLSPID {} seen for the first time, not reporting the LSP", id);
                                return;
                        }
+               } else {
+                       name = lspName;
                }
+
                LOG.debug("Saved LSP {} with name {}", id, name);
                this.lsps.put(id, name);
 
@@ -363,12 +367,16 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
                lspData.remove(name);
        }
 
-       abstract protected void onSessionUp(PCEPSession session, PathComputationClientBuilder pccBuilder);
+       protected abstract void onSessionUp(PCEPSession session, PathComputationClientBuilder pccBuilder);
 
-       abstract protected boolean onMessage(DataModificationTransaction trans, Message message);
+       protected abstract boolean onMessage(DataModificationTransaction trans, Message message);
 
        protected String lookupLspName(final PLSPID id) {
                Preconditions.checkNotNull(id, "ID parameter null.");
                return this.lsps.get(id);
        }
+
+       protected final <T extends DataObject> T readOperationalData(final InstanceIdentifier<T> id) {
+               return serverSessionManager.readOperationalData(id);
+       }
 }