Interface AsyncServerInterceptor

All Superinterfaces:
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 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");
             }
        });
    }
 }