Interface AsyncServerInterceptor

All Superinterfaces:
io.grpc.ServerInterceptor
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@UnstableApi @FunctionalInterface public interface AsyncServerInterceptor extends io.grpc.ServerInterceptor
A ServerInterceptor that is able to asynchronously execute the interceptor without blocking the caller thread. For example:

 class AuthServerInterceptor implements AsyncServerInterceptor {

     @Override
     <I, O> CompletableFuture<Listener<I>> asyncInterceptCall(
             ServerCall<I, O> call, Metadata headers, ServerCallHandler<I, O> next) {
        Context grpcContext = Context.current();
        return authorizer.authorize(headers).thenApply(result -> {
             if (result) {
                 // `next.startCall()` should be wrapped with `grpcContext.call()` if you want to propagate
                 // the context to the next interceptor.
                 return grpcContext.call(() -> next.startCall(call, headers));
             } else {
                 throw new AuthenticationException("Invalid access");
             }
        });
    }
 }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    <I, O> CompletableFuture<io.grpc.ServerCall.Listener<I>>
    asyncInterceptCall(io.grpc.ServerCall<I,O> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<I,O> next)
    Asynchronously intercepts ServerCall dispatch by the next ServerCallHandler.
    default <I, O> io.grpc.ServerCall.Listener<I>
    interceptCall(io.grpc.ServerCall<I,O> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<I,O> next)
     
  • Method Details

    • asyncInterceptCall

      <I, O> CompletableFuture<io.grpc.ServerCall.Listener<I>> asyncInterceptCall(io.grpc.ServerCall<I,O> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<I,O> next)
      Asynchronously intercepts ServerCall dispatch by the next ServerCallHandler.
    • interceptCall

      default <I, O> io.grpc.ServerCall.Listener<I> interceptCall(io.grpc.ServerCall<I,O> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<I,O> next)
      Specified by:
      interceptCall in interface io.grpc.ServerInterceptor