@@ -305,8 +305,9 @@ void checkResponse(RpcResponseHeaderProto header) throws IOException {
305305 }
306306 }
307307
308- Call createCall (RPC .RpcKind rpcKind , Writable rpcRequest ) {
309- return new Call (rpcKind , rpcRequest );
308+ Call createCall (RPC .RpcKind rpcKind , Writable rpcRequest ,
309+ AlignmentContext alignmentContext ) {
310+ return new Call (rpcKind , rpcRequest , alignmentContext );
310311 }
311312
312313 /**
@@ -319,11 +320,13 @@ static class Call {
319320 private final CompletableFuture <Writable > rpcResponseFuture ;
320321 final RPC .RpcKind rpcKind ; // Rpc EngineKind
321322 private final Object externalHandler ;
322- private AlignmentContext alignmentContext ;
323+ private final AlignmentContext alignmentContext ;
323324
324- private Call (RPC .RpcKind rpcKind , Writable param ) {
325+ private Call (RPC .RpcKind rpcKind , Writable param ,
326+ AlignmentContext alignmentContext ) {
325327 this .rpcKind = rpcKind ;
326328 this .rpcRequest = param ;
329+ this .alignmentContext = alignmentContext ;
327330
328331 final Integer id = callId .get ();
329332 if (id == null ) {
@@ -351,44 +354,32 @@ public String toString() {
351354
352355 /** Indicate when the call is complete and the
353356 * value or error are available. Notifies by default. */
354- protected synchronized void callComplete (Writable rpcResponse , IOException error ) {
355- if (error != null ) {
356- rpcResponseFuture .completeExceptionally (error );
357- } else {
358- rpcResponseFuture .complete (rpcResponse );
359- }
357+ protected void callComplete () {
360358 if (externalHandler != null ) {
361359 synchronized (externalHandler ) {
362360 externalHandler .notify ();
363361 }
364362 }
365363 }
366364
367- /**
368- * Set an AlignmentContext for the call to update when call is done.
369- *
370- * @param ac alignment context to update.
371- */
372- public synchronized void setAlignmentContext (AlignmentContext ac ) {
373- this .alignmentContext = ac ;
374- }
375-
376365 /** Set the exception when there is an error.
377366 * Notify the caller the call is done.
378367 *
379368 * @param error exception thrown by the call; either local or remote
380369 */
381- public synchronized void setException (IOException error ) {
382- callComplete (null , error );
370+ public void setException (IOException error ) {
371+ rpcResponseFuture .completeExceptionally (error );
372+ callComplete ();
383373 }
384374
385375 /** Set the return value when there is no error.
386376 * Notify the caller the call is done.
387377 *
388378 * @param rpcResponse return value of the rpc call.
389379 */
390- public synchronized void setRpcResponse (Writable rpcResponse ) {
391- callComplete (rpcResponse , null );
380+ public void setRpcResponse (Writable rpcResponse ) {
381+ rpcResponseFuture .complete (rpcResponse );
382+ callComplete ();
392383 }
393384 }
394385
@@ -1503,8 +1494,7 @@ Writable call(RPC.RpcKind rpcKind, Writable rpcRequest,
15031494 ConnectionId remoteId , int serviceClass ,
15041495 AtomicBoolean fallbackToSimpleAuth , AlignmentContext alignmentContext )
15051496 throws IOException {
1506- final Call call = createCall (rpcKind , rpcRequest );
1507- call .setAlignmentContext (alignmentContext );
1497+ final Call call = createCall (rpcKind , rpcRequest , alignmentContext );
15081498 final Connection connection = getConnection (remoteId , call , serviceClass ,
15091499 fallbackToSimpleAuth );
15101500
0 commit comments