code: @Override
    public <O extends Message> ListenableFuture<O> encodeMethodCall(final ClientMethod<O> method,
        Message input) {
      // Channel was manually closed earlier
      if (refuseNewRequests.get()) {
        return Futures.immediateFailedFuture(new RuntimeException("Client is closed"));
      }
  
      // Channel was closed by the server - we make an attempt to reopen.
      if (shouldCreateNewChannel.get()) {
        try {
          reopenChannel();
          channel.closeFuture().addListener(new ChannelCloser());
        } catch (IOException ioe) {
          return Futures.immediateFailedFuture(ioe);
        }
      }
  
      // Normal operation mode
      clientLogger.logMethodCall(method);
      final EnvelopeFuture<O> output = handler.newProvisionalResponse(method);
      Envelope request = Envelope.newBuilder()
          .setRequestId(output.requestId())
          .setService(method.serviceName())
          .setMethod(method.name())
          .setPayload(input.toByteString())
          .build();
  
      HttpRequest httpRequest = handler.convertRequest(request);
      channel.writeAndFlush(httpRequest).addListener(new GenericFutureListener<ChannelFuture>() {
  
        public void operationComplete(ChannelFuture future) {
          if (!future.isSuccess()) {
            clientLogger.logLinkError(method, future.cause());
            handler.finish(output.requestId());
            output.setException(future.cause());
          }
        }
  
      });
  
      return output;
    }
docs: {@inheritDoc}