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) {

        return authorizer.authorize(headers).thenApply(result -> {
             if (result) {
                 return next.startCall(call, headers);
             } else {
                 throw new AuthenticationException("Invalid access");
             }
        });
    }
 }