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 );
}
}