Simplify session/state references 32/100732/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Apr 2022 11:33:49 +0000 (13:33 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 23 Apr 2022 04:18:56 +0000 (06:18 +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>
(cherry picked from commit fab2b26a1ba4baadd78a79b70734d863cb8e8bf5)

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 8b7c8b3d837e93f51bba811228f527023e1d085c..6829979d434b0a22eed26752420938761e503da0 100644 (file)
@@ -96,7 +96,7 @@ public abstract class AbstractTopologySessionListener<S, L> implements TopologyS
 
         @Override
         public ProtocolVersion getVersion() {
-            return this.version;
+            return version;
         }
     };
 
@@ -179,10 +179,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());
             }
@@ -363,7 +363,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);
@@ -373,7 +373,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);
@@ -465,8 +465,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
@@ -649,13 +648,13 @@ public abstract class AbstractTopologySessionListener<S, L> implements TopologyS
         }
 
         void resolveRequest(final PCEPRequest req) {
-            this.requests.add(req);
+            requests.add(req);
         }
 
         @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
                 justification = "https://github.com/spotbugs/spotbugs/issues/811")
         private void notifyRequests() {
-            for (final PCEPRequest r : this.requests) {
+            for (final PCEPRequest r : requests) {
                 r.done(OperationResults.SUCCESS);
             }
         }
index 9e40babe17e8269ae279f494857bc12218e49b46..02ba66871a05958197ee760c7c6dc23dd03c1fd1 100644 (file)
@@ -198,8 +198,8 @@ final class TopologyNodeState implements AutoCloseable, 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());