S
- the concrete type of this stub.@ThreadSafe
@CheckReturnValue
public abstract class AbstractStub<S extends AbstractStub<S>>
extends java.lang.Object
withDeadlineAfter(long, java.util.concurrent.TimeUnit)
.
Configuration is stored in CallOptions
and is passed to the Channel
when
performing an RPC.
DO NOT MOCK: Customizing options doesn't work properly in mocks. Use InProcessChannelBuilder to create a real channel suitable for testing. It is also possible to mock Channel instead.
Modifier | Constructor | 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 | 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) |
Deprecated.
|
S |
withCompression(java.lang.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,
java.util.concurrent.TimeUnit unit) |
Returns a new stub with a deadline that is after the given
duration from now. |
S |
withExecutor(java.util.concurrent.Executor executor) |
Returns a new stub with the given executor that is to be used instead of the default one
specified with
ManagedChannelBuilder.executor(java.util.concurrent.Executor) . |
S |
withInterceptors(io.grpc.ClientInterceptor... interceptors) |
Returns a new stub that has the given interceptors attached to the underlying channel.
|
S |
withMaxInboundMessageSize(int maxSize) |
Returns a new stub that limits the maximum acceptable message size from a remote peer.
|
S |
withMaxOutboundMessageSize(int maxSize) |
Returns a new stub that limits the maximum acceptable message size to send a remote peer.
|
<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. |
S |
withWaitForReady() |
Returns a new stub that uses the 'wait for ready' call option.
|
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.public final S withDeadlineAfter(long duration, java.util.concurrent.TimeUnit unit)
duration
from now.CallOptions.withDeadlineAfter(long, java.util.concurrent.TimeUnit)
public final S withExecutor(java.util.concurrent.Executor executor)
ManagedChannelBuilder.executor(java.util.concurrent.Executor)
. Note that setting this option may not
take effect for blocking calls.@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1704") public final S withCompression(java.lang.String compressorName)
DecompressorRegistry
on the ManagedChannelBuilder
.compressorName
- the name (e.g. "gzip") of the compressor to use.@Deprecated public final S withChannel(io.grpc.Channel newChannel)
This method is vestigial and is unlikely to be useful. Instead, users should prefer to
use withInterceptors(io.grpc.ClientInterceptor...)
.
@ExperimentalApi("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)
public final S withCallCredentials(io.grpc.CallCredentials credentials)
public final S withWaitForReady()
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2563") public final S withMaxInboundMessageSize(int maxSize)
If unset, the ManagedChannelBuilder.maxInboundMessageSize(int)
limit is used.
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2563") public final S withMaxOutboundMessageSize(int maxSize)