50
50
final class ServerConnection <REQ extends MessageBody , RESP extends MessageBody > {
51
51
private static final Logger LOG = LoggerFactory .getLogger (ServerConnection .class );
52
52
53
- private final Object connectionLock = new Object () ;
53
+ private final Object connectionLock ;
54
54
55
55
@ GuardedBy ("connectionLock" )
56
56
private InternalConnection <REQ , RESP > internalConnection ;
@@ -60,7 +60,8 @@ final class ServerConnection<REQ extends MessageBody, RESP extends MessageBody>
60
60
61
61
private final CompletableFuture <Void > closeFuture = new CompletableFuture <>();
62
62
63
- private ServerConnection (InternalConnection <REQ , RESP > internalConnection ) {
63
+ private ServerConnection (Object lock , InternalConnection <REQ , RESP > internalConnection ) {
64
+ this .connectionLock = lock ;
64
65
this .internalConnection = internalConnection ;
65
66
forwardCloseFuture ();
66
67
}
@@ -119,11 +120,14 @@ ServerConnection<REQ, RESP> createPendingConnection(
119
120
final String clientName ,
120
121
final MessageSerializer <REQ , RESP > serializer ,
121
122
final KvStateRequestStats stats ) {
123
+ final Object lock = new Object ();
124
+
122
125
return new ServerConnection <>(
126
+ lock ,
123
127
new PendingConnection <>(
124
128
channel ->
125
129
new EstablishedConnection <>(
126
- clientName , serializer , channel , stats )));
130
+ lock , clientName , serializer , channel , stats )));
127
131
}
128
132
129
133
interface InternalConnection <REQ , RESP > {
@@ -288,7 +292,7 @@ public REQ getRequest() {
288
292
private static class EstablishedConnection <REQ extends MessageBody , RESP extends MessageBody >
289
293
implements ClientHandlerCallback <RESP >, InternalConnection <REQ , RESP > {
290
294
291
- private final Object lock = new Object () ;
295
+ private final Object lock ;
292
296
293
297
/** The actual TCP channel. */
294
298
private final Channel channel ;
@@ -315,11 +319,13 @@ private static class EstablishedConnection<REQ extends MessageBody, RESP extends
315
319
* @param channel The actual TCP channel
316
320
*/
317
321
EstablishedConnection (
322
+ final Object lock ,
318
323
final String clientName ,
319
324
final MessageSerializer <REQ , RESP > serializer ,
320
325
final Channel channel ,
321
326
final KvStateRequestStats stats ) {
322
327
328
+ this .lock = lock ;
323
329
this .channel = Preconditions .checkNotNull (channel );
324
330
325
331
// Add the client handler with the callback
0 commit comments