Use final field as lock in AsyncSshHandlerWriter 09/47009/2
authorAndrej Mak <andrej.mak@pantheon.tech>
Mon, 17 Oct 2016 11:12:02 +0000 (13:12 +0200)
committerTomas Cere <tcere@cisco.com>
Thu, 29 Jun 2017 12:40:33 +0000 (12:40 +0000)
Change-Id: I355e626b90e5cd27dfb5da96ef76c13a36f77dde
Signed-off-by: Andrej Mak <andrej.mak@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java

index e333da2b7610ab6b210e4c158b5e9b2f2cbcf2e7..d116b99f828ac7e0bab6aba2e0f6521dafb22c84 100644 (file)
@@ -40,6 +40,7 @@ public final class AsyncSshHandlerWriter implements AutoCloseable {
     // 2. At this level we might be dealing with Chunks of messages(not whole messages)
     // and unexpected behavior might occur when we send/queue 1 chunk and fail the other chunks
 
+    private final Object asyncInLock = new Object();
     private volatile IoOutputStream asyncIn;
 
     // Order has to be preserved for queued writes
@@ -59,7 +60,7 @@ public final class AsyncSshHandlerWriter implements AutoCloseable {
         // writes and pending writes would lock the underlyinch channel session
         // window resize write would try to write the message on an already locked channelSession
         // while the pending write was in progress from the write callback
-        synchronized (asyncIn) {
+        synchronized (asyncInLock) {
             // TODO check for isClosed, isClosing might be performed by mina SSH internally and is not required here
             // If we are closed/closing, set immediate fail
             if (asyncIn.isClosed() || asyncIn.isClosing()) {
@@ -93,7 +94,7 @@ public final class AsyncSshHandlerWriter implements AutoCloseable {
                     // writes and pending writes would lock the underlyinch channel session
                     // window resize write would try to write the message on an already locked channelSession,
                     // while the pending write was in progress from the write callback
-                    synchronized (asyncIn) {
+                    synchronized (asyncInLock) {
                         if (LOG.isTraceEnabled()) {
                             LOG.trace(
                                 "Ssh write request finished on channel: {} with result: {}: and ex:{}, message: {}",
@@ -135,7 +136,7 @@ public final class AsyncSshHandlerWriter implements AutoCloseable {
     }
 
     private void writePendingIfAny() {
-        synchronized (asyncIn) {
+        synchronized (asyncInLock) {
             if (pending.peek() == null) {
                 return;
             }