@Override public void start(Listener<O> responseListener, Metadata unused) { requireNonNull(responseListener, "responseListener"); final Compressor compressor; if (callOptions.getCompressor() != null) { compressor = compressorRegistry.lookupCompressor(callOptions.getCompressor()); if (compressor == null) { responseListener.onClose( Status.INTERNAL.withDescription( "Unable to find compressor by name " + callOptions.getCompressor()), EMPTY_METADATA); return; } } else { compressor = Identity.NONE; } messageFramer.setCompressor(compressor); prepareHeaders(req.headers(), compressor); listener = responseListener; final HttpResponse res; try (SafeCloseable ignored = ctx.push()) { res = httpClient.execute(ctx, req); } catch (Exception e) { close(Status.fromThrowable(e)); return; } res.subscribe(responseReader, ctx.eventLoop(), true); res.completionFuture().handleAsync(responseReader, ctx.eventLoop()); }
); responseListener.onMessage(responseObject); responseListener.onClose(Status.OK, new Metadata());
@Override public void sendMessage(ReqT message) { Preconditions.checkState(delegateCall == null, "ThrottlingClientInterceptor only supports unary operations"); Preconditions.checkState(id == null, "ThrottlingClientInterceptor only supports unary operations"); Preconditions.checkState(delegateListener != null, "start() has to be called before sendMessage()."); Preconditions.checkState(headers != null, "start() has to be called before sendMessage()."); try { id = resourceLimiter .registerOperationWithHeapSize(((MessageLite) message).getSerializedSize()); } catch (InterruptedException e) { delegateListener.onClose(Status.INTERNAL.withDescription("Operation was interrupted"), new Metadata()); return; } delegateCall = delegateChannel.newCall(method, callOptions); SimpleForwardingClientCallListener<RespT> markCompletionListener = new SimpleForwardingClientCallListener<RespT>(this.delegateListener) { @Override public void onClose(io.grpc.Status status, Metadata trailers) { resourceLimiter.markCanBeCompleted(id); delegate().onClose(status, trailers); } }; delegate().start(markCompletionListener, headers); delegate().request(numMessagesRequested); delegate().sendMessage(message); }
assertFalse(trailingMetadataHandlerCalled.value); captor.getValue().onClose(Status.fromCodeValue(0), new Metadata());
@Override public void start(Listener<O> responseListener, Metadata unused) { requireNonNull(responseListener, "responseListener"); final Compressor compressor; if (callOptions.getCompressor() != null) { compressor = compressorRegistry.lookupCompressor(callOptions.getCompressor()); if (compressor == null) { responseListener.onClose( Status.INTERNAL.withDescription( "Unable to find compressor by name " + callOptions.getCompressor()), EMPTY_METADATA); return; } } else { compressor = Identity.NONE; } messageFramer.setCompressor(compressor); prepareHeaders(req.headers(), compressor); listener = responseListener; final HttpResponse res; try (SafeCloseable ignored = ctx.push()) { res = httpClient.execute(ctx, req); } catch (Exception e) { close(Status.fromThrowable(e)); return; } res.subscribe(responseReader, ctx.eventLoop(), true); res.completionFuture().handleAsync(responseReader, ctx.eventLoop()); }
@Override public void start(Listener<RespT> responseListener, Metadata headers) { final long timeout; if (callOptions.getDeadline() != null) { timeout = callOptions.getDeadline().timeRemaining(TimeUnit.MILLISECONDS); } else { timeout = TIMEOUT_MILLISECONDS; } HeaderToken token = store.getHeader(timeout, TimeUnit.MILLISECONDS); if (!token.getStatus().isOk()) { unauthorized = true; responseListener.onClose(token.getStatus(), new Metadata()); return; } headers.put(AUTHORIZATION_HEADER_KEY, token.getHeader()); delegate().start(new UnAuthResponseListener<>(responseListener, token), headers); }
@Override @SuppressWarnings("unchecked") public final void start(Listener<RespT> responseListener, Metadata headers) { try { checkedStart(responseListener, headers); } catch (Exception e) { // Because start() doesn't throw, the caller may still try to call other methods on this // call object. Passing these invocations to the original delegate will cause // IllegalStateException because delegate().start() was not called. We switch the delegate // to a NO-OP one to prevent the IllegalStateException. The user will finally get notified // about the error through the listener. delegate = (ClientCall<ReqT, RespT>) NOOP_CALL; responseListener.onClose(Status.fromThrowable(e), new Metadata()); } } }
@Override @SuppressWarnings("unchecked") public final void start(Listener<RespT> responseListener, Metadata headers) { try { checkedStart(responseListener, headers); } catch (Exception e) { // Because start() doesn't throw, the caller may still try to call other methods on this // call object. Passing these invocations to the original delegate will cause // IllegalStateException because delegate().start() was not called. We switch the delegate // to a NO-OP one to prevent the IllegalStateException. The user will finally get notified // about the error through the listener. delegate = (ClientCall<ReqT, RespT>) NOOP_CALL; responseListener.onClose(Status.fromThrowable(e), new Metadata()); } } }
private void closeObserver(Listener<RespT> observer, Status status, Metadata trailers) { observer.onClose(status, trailers); }
private void closeObserver(Listener<RespT> observer, Status status, Metadata trailers) { observer.onClose(status, trailers); }
@Override public void start(ClientCall.Listener<RespT> listener, Metadata headers) { listener.onClose(error, new Metadata()); }
@Override public void onClose(Status status, Metadata trailers) { delegate().onClose(status, trailers); }
@Override public void sendMessage(RequestT message) { responseListener.onHeaders(headers); responseListener.onMessage(response); responseListener.onClose(status, headers); } }
@Override public void onClose(Status status, Metadata trailers) { delegate().onClose(status, trailers); }
private void close(Status status) { ctx.logBuilder().responseContent(GrpcLogUtil.rpcResponse(status, firstResponse), null); req.abort(); responseReader.cancel(); try (SafeCloseable ignored = ctx.push()) { listener.onClose(status, EMPTY_METADATA); } notifyExecutor(); }
private void useResponse(AttemptListener attempt) { responseListener.onHeaders(attempt.responseHeaders); if (attempt.responseMessage != null) { responseListener.onMessage(attempt.responseMessage); } responseListener.onClose(attempt.responseStatus, attempt.responseTrailers); }
private void close(Status status) { ctx.logBuilder().responseContent(GrpcLogUtil.rpcResponse(status, firstResponse), null); req.abort(); responseReader.cancel(); try (SafeCloseable ignored = ctx.push()) { listener.onClose(status, EMPTY_METADATA); } notifyExecutor(); }