Top Description Inners Constructors Methods
io.grpc

public final Class ServerInterceptors

extends Object
Class Inheritance
Imports
com.google.common.base.Preconditions, java.io.BufferedInputStream, .InputStream, java.util.ArrayList, .Arrays, .Collections, .List

Utility methods for working with ServerInterceptors.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ServerServiceDefinition

Returns:

a wrapped version of serviceDef with the interceptors applied.
intercept
(ServerServiceDefinition
the service definition for which to intercept all its methods.
serviceDef
,
ServerInterceptor...
array of interceptors to apply to the service.
interceptors
)

Create a new ServerServiceDefinition whose ServerCallHandlers will call interceptors before calling the pre-existing ServerCallHandler.

public static ServerServiceDefinition
intercept(BindableService bindableService, ServerInterceptor... interceptors)

public static ServerServiceDefinition

Returns:

a wrapped version of serviceDef with the interceptors applied.
intercept
(ServerServiceDefinition
the service definition for which to intercept all its methods.
serviceDef
,
List<? extends ServerInterceptor>
list of interceptors to apply to the service.
interceptors
)

Create a new ServerServiceDefinition whose ServerCallHandlers will call interceptors before calling the pre-existing ServerCallHandler.

public static ServerServiceDefinition
intercept(BindableService bindableService, List<? extends ServerInterceptor> interceptors)

public static ServerServiceDefinition

Returns:

a wrapped version of serviceDef with the interceptors applied.
interceptForward
(ServerServiceDefinition
the service definition for which to intercept all its methods.
serviceDef
,
ServerInterceptor...
array of interceptors to apply to the service.
interceptors
)

Create a new ServerServiceDefinition whose ServerCallHandlers will call interceptors before calling the pre-existing ServerCallHandler.

public static ServerServiceDefinition
interceptForward(BindableService bindableService, ServerInterceptor... interceptors)

public static ServerServiceDefinition

Returns:

a wrapped version of serviceDef with the interceptors applied.
interceptForward
(ServerServiceDefinition
the service definition for which to intercept all its methods.
serviceDef
,
List<? extends ServerInterceptor>
list of interceptors to apply to the service.
interceptors
)

Create a new ServerServiceDefinition whose ServerCallHandlers will call interceptors before calling the pre-existing ServerCallHandler.

public static ServerServiceDefinition
interceptForward(BindableService bindableService, List<? extends ServerInterceptor> interceptors)

public static ServerServiceDefinition

Returns:

a wrapped version of serviceDef with the InputStream conversion applied.
useInputStreamMessages
(final ServerServiceDefinition
the service definition to convert messages to InputStream
serviceDef
)

Create a new ServerServiceDefinition whose MethodDescriptor serializes to and from InputStream for all methods.

public static <T> ServerServiceDefinition

Returns:

a wrapped version of serviceDef with the T conversion applied.
useMarshalledMessages
(final ServerServiceDefinition
the service definition to convert messages to T
serviceDef
,
final MethodDescriptor.Marshaller<T> marshaller)

Create a new ServerServiceDefinition whose MethodDescriptor serializes to and from T for all methods.

public static <
the request payload type
ReqT
,
the response payload type.
RespT
>
ServerServiceDefinition

Returns:

a wrapped version of serviceDef with the ReqT and RespT conversion applied.
useMarshalledMessages
(final ServerServiceDefinition
the sevice definition to add request and response marshallers to.
serviceDef
,
final MethodDescriptor.Marshaller<ReqT>
request marshaller
requestMarshaller
,
final MethodDescriptor.Marshaller<RespT>
response marshaller
responseMarshaller
)

Create a new ServerServiceDefinition with MethodDescriptor for deserializing requests and separate MethodDescriptor for serializing responses.

private static <ReqT, RespT> void
wrapAndAddMethod(ServerServiceDefinition.Builder serviceDefBuilder, ServerMethodDefinition<ReqT, RespT> method, List<? extends ServerInterceptor> interceptors)

private static <OReqT, ORespT, WReqT, WRespT> ServerCallHandler<WReqT, WRespT>
wrapHandler(final ServerCallHandler<OReqT, ORespT> originalHandler, final MethodDescriptor<OReqT, ORespT> originalMethod, final MethodDescriptor<WReqT, WRespT> wrappedMethod)

pack-priv static <OReqT, ORespT, WReqT, WRespT> ServerMethodDefinition<WReqT, WRespT>
wrapMethod(final ServerMethodDefinition<OReqT, ORespT> definition, final MethodDescriptor<WReqT, WRespT> wrappedMethod)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ServerInterceptorsback to summary
private ServerInterceptors()

Method Detail

interceptback to summary
public static ServerServiceDefinition intercept(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors)

Create a new ServerServiceDefinition whose ServerCallHandlers will call interceptors before calling the pre-existing ServerCallHandler. The last interceptor will have its ServerInterceptor#interceptCall called first.

Parameters
serviceDef:ServerServiceDefinition

the service definition for which to intercept all its methods.

interceptors:ServerInterceptor[]

array of interceptors to apply to the service.

Returns:ServerServiceDefinition

a wrapped version of serviceDef with the interceptors applied.

interceptback to summary
public static ServerServiceDefinition intercept(BindableService bindableService, ServerInterceptor... interceptors)
interceptback to summary
public static ServerServiceDefinition intercept(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors)

Create a new ServerServiceDefinition whose ServerCallHandlers will call interceptors before calling the pre-existing ServerCallHandler. The last interceptor will have its ServerInterceptor#interceptCall called first.

Parameters
serviceDef:ServerServiceDefinition

the service definition for which to intercept all its methods.

interceptors:List<? extends ServerInterceptor>

list of interceptors to apply to the service.

Returns:ServerServiceDefinition

a wrapped version of serviceDef with the interceptors applied.

interceptback to summary
public static ServerServiceDefinition intercept(BindableService bindableService, List<? extends ServerInterceptor> interceptors)
interceptForwardback to summary
public static ServerServiceDefinition interceptForward(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors)

Create a new ServerServiceDefinition whose ServerCallHandlers will call interceptors before calling the pre-existing ServerCallHandler. The first interceptor will have its ServerInterceptor#interceptCall called first.

Parameters
serviceDef:ServerServiceDefinition

the service definition for which to intercept all its methods.

interceptors:ServerInterceptor[]

array of interceptors to apply to the service.

Returns:ServerServiceDefinition

a wrapped version of serviceDef with the interceptors applied.

interceptForwardback to summary
public static ServerServiceDefinition interceptForward(BindableService bindableService, ServerInterceptor... interceptors)
interceptForwardback to summary
public static ServerServiceDefinition interceptForward(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors)

Create a new ServerServiceDefinition whose ServerCallHandlers will call interceptors before calling the pre-existing ServerCallHandler. The first interceptor will have its ServerInterceptor#interceptCall called first.

Parameters
serviceDef:ServerServiceDefinition

the service definition for which to intercept all its methods.

interceptors:List<? extends ServerInterceptor>

list of interceptors to apply to the service.

Returns:ServerServiceDefinition

a wrapped version of serviceDef with the interceptors applied.

interceptForwardback to summary
public static ServerServiceDefinition interceptForward(BindableService bindableService, List<? extends ServerInterceptor> interceptors)
useInputStreamMessagesback to summary
public static ServerServiceDefinition useInputStreamMessages(final ServerServiceDefinition serviceDef)

Create a new ServerServiceDefinition whose MethodDescriptor serializes to and from InputStream for all methods. The InputStream is guaranteed return true for markSupported(). The ServerCallHandler created will automatically convert back to the original types for request and response before calling the existing ServerCallHandler. Calling this method combined with the intercept methods will allow the developer to choose whether to intercept messages of InputStream, or the modeled types of their application.

Parameters
serviceDef:ServerServiceDefinition

the service definition to convert messages to InputStream

Returns:ServerServiceDefinition

a wrapped version of serviceDef with the InputStream conversion applied.

Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/1712
useMarshalledMessagesback to summary
public static <T> ServerServiceDefinition useMarshalledMessages(final ServerServiceDefinition serviceDef, final MethodDescriptor.Marshaller<T> marshaller)

Create a new ServerServiceDefinition whose MethodDescriptor serializes to and from T for all methods. The ServerCallHandler created will automatically convert back to the original types for request and response before calling the existing ServerCallHandler. Calling this method combined with the intercept methods will allow the developer to choose whether to intercept messages of T, or the modeled types of their application. This can also be chained to allow for interceptors to handle messages as multiple different T types within the chain if the added cost of serialization is not a concern.

Parameters
serviceDef:ServerServiceDefinition

the service definition to convert messages to T

Returns:ServerServiceDefinition

a wrapped version of serviceDef with the T conversion applied.

Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/1712
useMarshalledMessagesback to summary
public static <ReqT, RespT> ServerServiceDefinition useMarshalledMessages(final ServerServiceDefinition serviceDef, final MethodDescriptor.Marshaller<ReqT> requestMarshaller, final MethodDescriptor.Marshaller<RespT> responseMarshaller)

Create a new ServerServiceDefinition with MethodDescriptor for deserializing requests and separate MethodDescriptor for serializing responses. The ServerCallHandler created will automatically convert back to the original types for request and response before calling the existing ServerCallHandler. Calling this method combined with the intercept methods will allow the developer to choose whether to intercept messages of ReqT/RespT, or the modeled types of their application. This can also be chained to allow for interceptors to handle messages as multiple different ReqT/RespT types within the chain if the added cost of serialization is not a concern.

Parameters
<ReqT>
the request payload type
<RespT>
the response payload type.
serviceDef:ServerServiceDefinition

the sevice definition to add request and response marshallers to.

requestMarshaller:MethodDescriptor.Marshaller<ReqT>

request marshaller

responseMarshaller:MethodDescriptor.Marshaller<RespT>

response marshaller

Returns:ServerServiceDefinition

a wrapped version of serviceDef with the ReqT and RespT conversion applied.

Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/9870
wrapAndAddMethodback to summary
private static <ReqT, RespT> void wrapAndAddMethod(ServerServiceDefinition.Builder serviceDefBuilder, ServerMethodDefinition<ReqT, RespT> method, List<? extends ServerInterceptor> interceptors)
wrapHandlerback to summary
private static <OReqT, ORespT, WReqT, WRespT> ServerCallHandler<WReqT, WRespT> wrapHandler(final ServerCallHandler<OReqT, ORespT> originalHandler, final MethodDescriptor<OReqT, ORespT> originalMethod, final MethodDescriptor<WReqT, WRespT> wrappedMethod)
wrapMethodback to summary
pack-priv static <OReqT, ORespT, WReqT, WRespT> ServerMethodDefinition<WReqT, WRespT> wrapMethod(final ServerMethodDefinition<OReqT, ORespT> definition, final MethodDescriptor<WReqT, WRespT> wrappedMethod)
io.grpc back to summary

pack-priv final Class ServerInterceptors.InterceptCallHandler<ReqT, RespT>

extends Object
implements ServerCallHandler<ReqT, RespT>
Class Inheritance
All Implemented Interfaces
io.grpc.ServerCallHandler

Field Summary

Modifier and TypeField and Description
private final ServerCallHandler<ReqT, RespT>
private final ServerInterceptor

Constructor Summary

AccessConstructor and Description
private
InterceptCallHandler(ServerInterceptor interceptor, ServerCallHandler<ReqT, RespT> callHandler)

Method Summary

Modifier and TypeMethod and Description
public static <ReqT, RespT> ServerInterceptors.InterceptCallHandler<ReqT, RespT>
create(ServerInterceptor interceptor, ServerCallHandler<ReqT, RespT> callHandler)

public ServerCall.Listener<ReqT>
startCall(ServerCall<ReqT, RespT>
object for responding to the remote client.
call
,
Metadata
request headers received from the client but open to modification by an owner
headers
)

Implements io.grpc.ServerCallHandler.startCall.

Starts asynchronous processing of an incoming call.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callHandlerback to summary
private final ServerCallHandler<ReqT, RespT> callHandler
interceptorback to summary
private final ServerInterceptor interceptor

Constructor Detail

InterceptCallHandlerback to summary
private InterceptCallHandler(ServerInterceptor interceptor, ServerCallHandler<ReqT, RespT> callHandler)

Method Detail

createback to summary
public static <ReqT, RespT> ServerInterceptors.InterceptCallHandler<ReqT, RespT> create(ServerInterceptor interceptor, ServerCallHandler<ReqT, RespT> callHandler)
startCallback to summary
public ServerCall.Listener<ReqT> startCall(ServerCall<ReqT, RespT> call, Metadata headers)

Implements io.grpc.ServerCallHandler.startCall.

Doc from io.grpc.ServerCallHandler.startCall.

Starts asynchronous processing of an incoming call.

Callers of this method transfer their ownership of the non-thread-safe ServerCall and Metadata arguments to the ServerCallHandler implementation for processing. Ownership means that the implementation may invoke methods on call and headers while startCall runs and at any time after it returns normally. On the other hand, if startCall throws, ownership of call and headers reverts to the caller and the implementation loses the right to call methods on these objects (from some other thread, say).

Ownership also includes the responsibility to eventually close call. In particular, if startCall throws an exception, the caller must handle it by closing call with an error. Since call can only be closed once, an implementation can report errors either to ServerCall#close for itself or by throwing an exception, but not both.

Returns a non-null listener for the incoming call. Callers of this method must arrange for events associated with call to be delivered there.

Parameters
call:ServerCall<ReqT, RespT>

object for responding to the remote client.

headers:Metadata

request headers received from the client but open to modification by an owner

Returns:ServerCall.Listener<ReqT>

listener for processing incoming request messages for call

Annotations
@Override
io.grpc back to summary

private final Class ServerInterceptors.KnownLengthBufferedInputStream

extends BufferedInputStream
implements KnownLength
Class Inheritance
All Implemented Interfaces
io.grpc.KnownLength

BufferedInputStream that also implements KnownLength.

Field Summary

Inherited from java.io.BufferedInputStream:
bufcountmarklimitmarkpospos

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.io.BufferedInputStream:
availableclosemarkmarkSupportedreadreadresetskiptransferTo

Constructor Detail

KnownLengthBufferedInputStreamback to summary
pack-priv KnownLengthBufferedInputStream(InputStream in)