Top Description Inners Constructors Methods
io.grpc

public final Class Contexts

extends Object
Class Inheritance
Imports
com.google.common.base.Preconditions, java.util.concurrent.TimeoutException

Utility methods for working with Contexts in GRPC.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Contexts.ContextualizedServerCallListener<ReqT>

Implementation of io.grpc.ForwardingServerCallListener that attaches a context before dispatching calls to the delegate and detaches them after the call completes.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <ReqT, RespT> ServerCall.Listener<ReqT>

Returns:

listener that will receive events in the scope of the provided context.
interceptCall
(Context context, ServerCall<ReqT, RespT>
used to send responses to client.
call
,
Metadata
received from client.
headers
,
ServerCallHandler<ReqT, RespT>
handler used to create the listener to be wrapped.
next
)

Make the provided Context Context#current() for the creation of a listener to a received call and for all events received by that listener.

public static Status
statusFromCancelled(Context context)

Returns the Status of a cancelled context or null if the context is not cancelled.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Contextsback to summary
private Contexts()

Method Detail

interceptCallback to summary
public static <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(Context context, ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next)

Make the provided Context Context#current() for the creation of a listener to a received call and for all events received by that listener.

This utility is expected to be used by ServerInterceptor implementations that need to augment the Context in which the application does work when receiving events from the client.

Parameters
context:Context

to make Context#current().

call:ServerCall<ReqT, RespT>

used to send responses to client.

headers:Metadata

received from client.

next:ServerCallHandler<ReqT, RespT>

handler used to create the listener to be wrapped.

Returns:ServerCall.Listener<ReqT>

listener that will receive events in the scope of the provided context.

statusFromCancelledback to summary
public static Status statusFromCancelled(Context context)

Returns the Status of a cancelled context or null if the context is not cancelled.

Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/1975
io.grpc back to summary

private Class Contexts.ContextualizedServerCallListener<ReqT>

extends ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>
Class Inheritance

Implementation of io.grpc.ForwardingServerCallListener that attaches a context before dispatching calls to the delegate and detaches them after the call completes.

Field Summary

Modifier and TypeField and Description
private final Context

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
onCancel()

Overrides io.grpc.PartialForwardingServerCallListener.onCancel.

The call was cancelled and the server is encouraged to abort processing to save resources, since the client will not process any further messages.
public void
onComplete()

Overrides io.grpc.PartialForwardingServerCallListener.onComplete.

The call is considered complete and onCancel is guaranteed not to be called.
public void
onHalfClose()

Overrides io.grpc.PartialForwardingServerCallListener.onHalfClose.

The client completed all message sending.
public void
onMessage(ReqT
a received request message.
message
)

Overrides io.grpc.ForwardingServerCallListener.onMessage.

A request message has been received.
public void
onReady()

Overrides io.grpc.PartialForwardingServerCallListener.onReady.

This indicates that the call may now be capable of sending additional messages (via sendMessage) without requiring excessive buffering internally.
Inherited from io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener:
delegate

Field Detail

contextback to summary
private final Context context

Constructor Detail

ContextualizedServerCallListenerback to summary
public ContextualizedServerCallListener(ServerCall.Listener<ReqT> delegate, Context context)

Method Detail

onCancelback to summary
public void onCancel()

Overrides io.grpc.PartialForwardingServerCallListener.onCancel.

Doc from io.grpc.ServerCall.Listener.onCancel.

The call was cancelled and the server is encouraged to abort processing to save resources, since the client will not process any further messages. Cancellations can be caused by timeouts, explicit cancellation by the client, network errors, etc.

There will be no further callbacks for the call.

Annotations
@Override
onCompleteback to summary
public void onComplete()

Overrides io.grpc.PartialForwardingServerCallListener.onComplete.

Doc from io.grpc.ServerCall.Listener.onComplete.

The call is considered complete and onCancel is guaranteed not to be called. However, the client is not guaranteed to have received all messages.

There will be no further callbacks for the call.

Annotations
@Override
onHalfCloseback to summary
public void onHalfClose()

Overrides io.grpc.PartialForwardingServerCallListener.onHalfClose.

Doc from io.grpc.ServerCall.Listener.onHalfClose.

The client completed all message sending. However, the call may still be cancelled.

Annotations
@Override
onMessageback to summary
public void onMessage(ReqT message)

Overrides io.grpc.ForwardingServerCallListener.onMessage.

Doc from io.grpc.ServerCall.Listener.onMessage.

A request message has been received. For streaming calls, there may be zero or more request messages.

Parameters
message:ReqT

a received request message.

Annotations
@Override
onReadyback to summary
public void onReady()

Overrides io.grpc.PartialForwardingServerCallListener.onReady.

Doc from io.grpc.ServerCall.Listener.onReady.

This indicates that the call may now be capable of sending additional messages (via sendMessage) without requiring excessive buffering internally. This event is just a suggestion and the application is free to ignore it, however doing so may result in excessive buffering within the call.

Because there is a processing delay to deliver this notification, it is possible for concurrent writes to cause isReady() == false within this callback. Handle "spurious" notifications by checking isReady()'s current value instead of assuming it is now true. If isReady() == false the normal expectations apply, so there would be another onReady() callback.

Annotations
@Override