Simplify session/state references 66/100666/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Apr 2022 11:33:49 +0000 (13:33 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Apr 2022 12:28:07 +0000 (14:28 +0200)
While we are update our object's state, make sure we use local variables
to it is clear that things cannot change. This makes invariants a bit
more visible.

JIRA: BGPCEP-1005
Change-Id: I1b3b1bd2b6a12822685acd4651f4ead4e769f175
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyNodeState.java

index 19f5571720ef59fe87e72f8ce618c963deca3003..838714885c0ff475094d63505b9bbfb0daff0399 100644 (file)
@@ -95,7 +95,7 @@ public abstract class AbstractTopologySessionListener<S, L> implements TopologyS
 
         @Override
         public ProtocolVersion getVersion() {
-            return this.version;
+            return version;
         }
     };
 
@@ -178,10 +178,10 @@ public abstract class AbstractTopologySessionListener<S, L> implements TopologyS
                             initialNodeState.augmentation(Node1.class).getPathComputationClient().getReportedLsp());
                 }
                 state.storeNode(topologyAugment,
-                        new Node1Builder().setPathComputationClient(pccBuilder.build()).build(), this.session);
+                        new Node1Builder().setPathComputationClient(pccBuilder.build()).build(), psession);
 
                 this.listenerState = new SessionStateImpl(this, psession);
-                this.serverSessionManager.bind(this.nodeState.getNodeId(), this.listenerState);
+                this.serverSessionManager.bind(state.getNodeId(), this.listenerState);
                 LOG.info("Session with {} attached to topology node {}", psession.getRemoteAddress(),
                         state.getNodeId());
             }
@@ -362,7 +362,7 @@ public abstract class AbstractTopologySessionListener<S, L> implements TopologyS
 
     final synchronized ListenableFuture<OperationResult> sendMessage(final Message message, final S requestId,
             final Metadata metadata) {
-        final io.netty.util.concurrent.Future<Void> f = this.session.sendMessage(message);
+        final var sendFuture = this.session.sendMessage(message);
         this.listenerState.updateStatefulSentMsg(message);
         final PCEPRequest req = new PCEPRequest(metadata);
         this.requests.put(requestId, req);
@@ -372,7 +372,7 @@ public abstract class AbstractTopologySessionListener<S, L> implements TopologyS
             setupTimeoutHandler(requestId, req, rpcTimeout);
         }
 
-        f.addListener((FutureListener<Void>) future -> {
+        sendFuture.addListener((FutureListener<Void>) future -> {
             if (!future.isSuccess()) {
                 synchronized (AbstractTopologySessionListener.this) {
                     AbstractTopologySessionListener.this.requests.remove(requestId);
@@ -464,8 +464,7 @@ public abstract class AbstractTopologySessionListener<S, L> implements TopologyS
             final String name, final boolean remove) {
         // just one path should be reported
         final Path path = Iterables.getOnlyElement(rlb.getPath().values());
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId reportedLspId =
-                path.getLspId();
+        final var reportedLspId = path.getLspId();
         final List<Path> updatedPaths;
         //lspId = 0 and remove = false -> tunnel is down, still exists but no path is signaled
         //remove existing tunnel's paths now, as explicit path remove will not come
@@ -648,11 +647,11 @@ public abstract class AbstractTopologySessionListener<S, L> implements TopologyS
         }
 
         void resolveRequest(final PCEPRequest req) {
-            this.requests.add(req);
+            requests.add(req);
         }
 
         private void notifyRequests() {
-            for (final PCEPRequest r : this.requests) {
+            for (final PCEPRequest r : requests) {
                 r.done(OperationResults.SUCCESS);
             }
         }
index fc70674b3f2ed5eb131335444921fd6abebb6696..ac82bc2dc969f07eecda137a42acedf9b2159499 100644 (file)
@@ -198,8 +198,8 @@ final class TopologyNodeState implements TransactionChainListener {
 
             @Override
             public void onFailure(final Throwable throwable) {
-                LOG.error("Failed to store node {} for session {}, terminating it",
-                        topologyAugment, session, throwable);
+                LOG.error("Failed to store node {} for session {}, terminating it", topologyAugment, session,
+                    throwable);
                 session.close(TerminationReason.UNKNOWN);
             }
         }, MoreExecutors.directExecutor());