S - the concrete type of this stub.public abstract class AbstractStub<S extends AbstractStub<S>> extends Object
This is the base class of the stub classes from the generated code. It allows for reconfiguration, e.g., attaching interceptors to the stub.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractStub(io.grpc.Channel channel)
Constructor for use by subclasses, with the default
CallOptions. |
protected |
AbstractStub(io.grpc.Channel channel,
io.grpc.CallOptions callOptions)
Constructor for use by subclasses, with the default
CallOptions. |
| Modifier and Type | Method and Description |
|---|---|
protected abstract S |
build(io.grpc.Channel channel,
io.grpc.CallOptions callOptions)
Returns a new stub with the given channel for the provided method configurations.
|
io.grpc.CallOptions |
getCallOptions()
The
CallOptions of the stub. |
io.grpc.Channel |
getChannel()
The underlying channel of the stub.
|
S |
withCallCredentials(io.grpc.CallCredentials credentials)
Returns a new stub that uses the given call credentials.
|
S |
withChannel(io.grpc.Channel newChannel)
Returns a new stub that uses the given channel.
|
S |
withCompression(String compressorName)
Set's the compressor name to use for the call.
|
S |
withDeadline(io.grpc.Deadline deadline)
Returns a new stub with an absolute deadline.
|
S |
withDeadlineAfter(long duration,
TimeUnit unit)
Returns a new stub with a deadline that is after the given
duration from now. |
S |
withDeadlineNanoTime(Long deadlineNanoTime)
Deprecated.
Use
withDeadline(Deadline) instead. |
S |
withInterceptors(io.grpc.ClientInterceptor... interceptors)
Returns a new stub that has the given interceptors attached to the underlying channel.
|
<T> S |
withOption(io.grpc.CallOptions.Key<T> key,
T value)
Sets a custom option to be passed to client interceptors on the channel
ClientInterceptor via the CallOptions parameter. |
protected AbstractStub(io.grpc.Channel channel)
CallOptions.channel - the channel that this stub will use to do communicationsprotected AbstractStub(io.grpc.Channel channel,
io.grpc.CallOptions callOptions)
CallOptions.channel - the channel that this stub will use to do communicationscallOptions - the runtime call options to be applied to every call on this stubpublic final io.grpc.Channel getChannel()
public final io.grpc.CallOptions getCallOptions()
CallOptions of the stub.protected abstract S build(io.grpc.Channel channel, io.grpc.CallOptions callOptions)
channel - the channel that this stub will use to do communicationscallOptions - the runtime call options to be applied to every call on this stubpublic final S withDeadline(@Nullable io.grpc.Deadline deadline)
This is mostly used for propagating an existing deadline. withDeadlineAfter(long, java.util.concurrent.TimeUnit) is the
recommended way of setting a new deadline,
deadline - the deadline or null for unsetting the deadline.@Deprecated public final S withDeadlineNanoTime(@Nullable Long deadlineNanoTime)
withDeadline(Deadline) instead.System.nanoTime().
This is mostly used for propagating an existing deadline. withDeadlineAfter(long, java.util.concurrent.TimeUnit) is the
recommended way of setting a new deadline,
deadlineNanoTime - nanoseconds in the clock as per System.nanoTime()public final S withDeadlineAfter(long duration, TimeUnit unit)
duration from now.CallOptions.withDeadlineAfter(long, java.util.concurrent.TimeUnit)@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1704") public final S withCompression(String compressorName)
DecompressorRegistry
on the ManagedChannelBuilder.compressorName - the name (e.g. "gzip") of the compressor to use.public final S withChannel(io.grpc.Channel newChannel)
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1869") public final <T> S withOption(io.grpc.CallOptions.Key<T> key, T value)
ClientInterceptor via the CallOptions parameter.key - the option being setvalue - the value for the keypublic final S withInterceptors(io.grpc.ClientInterceptor... interceptors)
@ExperimentalApi(value="https//github.com/grpc/grpc-java/issues/1914") public final S withCallCredentials(io.grpc.CallCredentials credentials)