Clean up TcpClientChannelInitializer
[netconf.git] / netconf / netconf-client / src / main / java / org / opendaylight / netconf / client / SimpleNetconfClientSessionListener.java
index 654210a4a0e1685b032cdf3cb60fb10c9bd3a1d8..0390e637fa970068ca220b558dc6667e573806aa 100644 (file)
@@ -5,16 +5,17 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.client;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
 import java.util.ArrayDeque;
 import java.util.Queue;
-import javax.annotation.concurrent.GuardedBy;
+import org.checkerframework.checker.lock.qual.GuardedBy;
+import org.checkerframework.checker.lock.qual.Holding;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfTerminationReason;
 import org.slf4j.Logger;
@@ -25,9 +26,9 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL
         private final Promise<NetconfMessage> promise;
         private final NetconfMessage request;
 
-        RequestEntry(Promise<NetconfMessage> future, NetconfMessage request) {
-            this.promise = Preconditions.checkNotNull(future);
-            this.request = Preconditions.checkNotNull(request);
+        RequestEntry(final Promise<NetconfMessage> future, final NetconfMessage request) {
+            this.promise = requireNonNull(future);
+            this.request = requireNonNull(request);
         }
     }
 
@@ -39,7 +40,7 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL
     @GuardedBy("this")
     private NetconfClientSession clientSession;
 
-    @GuardedBy("this")
+    @Holding("this")
     private void dispatchRequest() {
         while (!requests.isEmpty()) {
             final RequestEntry e = requests.peek();
@@ -50,13 +51,14 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL
             }
 
             LOG.debug("Message {} has been cancelled, skipping it", e.request);
-            requests.poll();
+            requests.remove();
         }
     }
 
     @Override
-    public final synchronized void onSessionUp(NetconfClientSession clientSession) {
-        this.clientSession = Preconditions.checkNotNull(clientSession);
+    @SuppressWarnings("checkstyle:hiddenField")
+    public final synchronized void onSessionUp(final NetconfClientSession clientSession) {
+        this.clientSession = requireNonNull(clientSession);
         LOG.debug("Client session {} went up", clientSession);
         dispatchRequest();
     }
@@ -71,21 +73,23 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL
     }
 
     @Override
-    public final void onSessionDown(NetconfClientSession clientSession, Exception exception) {
+    @SuppressWarnings("checkstyle:hiddenField")
+    public final void onSessionDown(final NetconfClientSession clientSession, final Exception exception) {
         LOG.debug("Client Session {} went down unexpectedly", clientSession, exception);
         tearDown(exception);
     }
 
     @Override
-    public final void onSessionTerminated(NetconfClientSession clientSession,
-                                          NetconfTerminationReason netconfTerminationReason) {
+    @SuppressWarnings("checkstyle:hiddenField")
+    public final void onSessionTerminated(final NetconfClientSession clientSession,
+                                          final NetconfTerminationReason netconfTerminationReason) {
         LOG.debug("Client Session {} terminated, reason: {}", clientSession,
                 netconfTerminationReason.getErrorMessage());
         tearDown(new RuntimeException(netconfTerminationReason.getErrorMessage()));
     }
 
     @Override
-    public synchronized void onMessage(NetconfClientSession session, NetconfMessage message) {
+    public synchronized void onMessage(final NetconfClientSession session, final NetconfMessage message) {
         LOG.debug("New message arrived: {}", message);
 
         final RequestEntry e = requests.poll();
@@ -97,8 +101,8 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL
         }
     }
 
-    public final synchronized Future<NetconfMessage> sendRequest(NetconfMessage message) {
-        final RequestEntry req = new RequestEntry(GlobalEventExecutor.INSTANCE.<NetconfMessage>newPromise(), message);
+    public final synchronized Future<NetconfMessage> sendRequest(final NetconfMessage message) {
+        final RequestEntry req = new RequestEntry(GlobalEventExecutor.INSTANCE.newPromise(), message);
 
         requests.add(req);
         if (clientSession != null) {