Just handle the ServerCall directly. Since you don't actually need the
listener, you can give a no-op one. If you need to provide additional error
information, you can provide it in the Metadata.

if (isCancelled) {
  call.close(Status.SOME_STATUS.withDescription("some description"), new
Metadata());
  return new ServerCall.Listener<R>() {};
}

On Thu, Jan 25, 2018 at 10:04 AM, <[email protected]> wrote:

>
> Hi Guys,
>
> I have a grpc service which does some cpu intensive work.
> Before starting the work, I want to ensure that the client hasn't
> cancelled this aforementioned work.
> Rather than checking in every service, I would like to write an
> interceptor which would check and drop the request if it has been cancelled.
>
> This is what I have come up with but I can't figure out how to drop the
> request and signal to the client.
> Any pointers are much appreciated.
>
> Cheers
>
> public final class CancelledRequestInterceptor implements
> ServerInterceptor{
>
> @Override
> public final <R, S> Server.Listener<R> interceptCall( ServerCall<R,S> call
> , Metadata meta, ServerCallHandler<R, S> next ){
>
>     boolean isCancelled = Context.current().isCancelled();
>     if( isCancelled ){
>        //How do I discard the call and signal to the client that it has
> been discarded
>     }else{
>        return next.startCall( call, headers );
>     }
>
> }
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "
> grpc.io" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/grpc-io.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/grpc-io/44bd8313-88c9-4758-a007-28be38cc4c25%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/44bd8313-88c9-4758-a007-28be38cc4c25%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CA%2B4M1oPGZnaOqa9tk8k%3DxXKL9GwgdwJpM0R%3D8GsD7oeQSjWE9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to