public abstract class AbstractNettyClient<Req extends com.linkedin.r2.message.Request,Res extends com.linkedin.r2.message.Response>
extends java.lang.Object
implements com.linkedin.r2.transport.common.bridge.client.TransportClient
TransportClient on top of Netty libraries. Inheriting this class is
a good starting point for protocol specific implementation of TransportClient.| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.ScheduledExecutorService |
_scheduler |
protected java.util.concurrent.atomic.AtomicReference<NettyClientState> |
_state |
| Constructor and Description |
|---|
AbstractNettyClient(ChannelPoolFactory factory,
java.util.concurrent.ScheduledExecutorService executor,
int requestTimeout,
int shutdownTimeout) |
AbstractNettyClient(java.util.concurrent.ScheduledExecutorService executor,
long requestTimeout,
long shutdownTimeout,
com.linkedin.r2.transport.http.client.AbstractJmxManager jmxManager,
ChannelPoolManager channelPoolManager,
ChannelPoolManager sslChannelPoolManager)
Creates a new HttpNettyClient
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
doWriteRequest(Req request,
com.linkedin.r2.message.RequestContext context,
java.net.SocketAddress address,
java.util.Map<java.lang.String,java.lang.String> wireAttrs,
com.linkedin.r2.transport.http.client.TimeoutTransportCallback<Res> callback,
long requestTimeout)
Writes the given request to the given socket address and invokes the callback after request is sent.
|
static <T> void |
errorResponse(com.linkedin.r2.transport.common.bridge.common.TransportCallback<T> callback,
java.lang.Throwable e) |
protected ChannelPoolManager |
getChannelPoolManagerPerRequest(com.linkedin.r2.message.Request request) |
protected abstract com.linkedin.r2.transport.common.bridge.common.TransportCallback<Res> |
getExecutionCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback<Res> callback)
Given a callback, returns the wrapped callback that will be executed on a custom executor
|
java.util.Map<java.lang.String,com.linkedin.r2.transport.http.client.PoolStats> |
getPoolStats()
Gets statistics from each channel pool.
|
void |
restRequest(com.linkedin.r2.message.rest.RestRequest request,
com.linkedin.r2.message.RequestContext requestContext,
java.util.Map<java.lang.String,java.lang.String> wireAttrs,
com.linkedin.r2.transport.common.bridge.common.TransportCallback<com.linkedin.r2.message.rest.RestResponse> callback) |
void |
shutdown(com.linkedin.common.callback.Callback<com.linkedin.common.util.None> callback) |
void |
streamRequest(com.linkedin.r2.message.stream.StreamRequest request,
com.linkedin.r2.message.RequestContext requestContext,
java.util.Map<java.lang.String,java.lang.String> wireAttrs,
com.linkedin.r2.transport.common.bridge.common.TransportCallback<com.linkedin.r2.message.stream.StreamResponse> callback) |
static java.lang.Exception |
toException(java.lang.Throwable t) |
protected final java.util.concurrent.atomic.AtomicReference<NettyClientState> _state
protected final java.util.concurrent.ScheduledExecutorService _scheduler
public AbstractNettyClient(java.util.concurrent.ScheduledExecutorService executor,
long requestTimeout,
long shutdownTimeout,
com.linkedin.r2.transport.http.client.AbstractJmxManager jmxManager,
ChannelPoolManager channelPoolManager,
ChannelPoolManager sslChannelPoolManager)
executor - An executor; it is the caller's responsibility to shut it downrequestTimeout - Timeout, in ms, to get a connection from the pool or create oneshutdownTimeout - Timeout, in ms, the client should wait after shutdown is
initiated before terminating outstanding requestsjmxManager - A management class that is aware of the creation/shutdown event
of the underlying ChannelPoolManagerchannelPoolManager - channelPoolManager instance to retrieve http only channelssslChannelPoolManager - channelPoolManager instance to retrieve https only connectionpublic AbstractNettyClient(ChannelPoolFactory factory, java.util.concurrent.ScheduledExecutorService executor, int requestTimeout, int shutdownTimeout)
protected abstract com.linkedin.r2.transport.common.bridge.common.TransportCallback<Res> getExecutionCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback<Res> callback)
protected abstract void doWriteRequest(Req request, com.linkedin.r2.message.RequestContext context, java.net.SocketAddress address, java.util.Map<java.lang.String,java.lang.String> wireAttrs, com.linkedin.r2.transport.http.client.TimeoutTransportCallback<Res> callback, long requestTimeout)
request - Request to sendcontext - Request contextaddress - Socket address to send the request towireAttrs - attributes that should be sent over the wire to the servercallback - Callback invoked after request is sentpublic void restRequest(com.linkedin.r2.message.rest.RestRequest request,
com.linkedin.r2.message.RequestContext requestContext,
java.util.Map<java.lang.String,java.lang.String> wireAttrs,
com.linkedin.r2.transport.common.bridge.common.TransportCallback<com.linkedin.r2.message.rest.RestResponse> callback)
restRequest in interface com.linkedin.r2.transport.common.bridge.client.TransportClientpublic void streamRequest(com.linkedin.r2.message.stream.StreamRequest request,
com.linkedin.r2.message.RequestContext requestContext,
java.util.Map<java.lang.String,java.lang.String> wireAttrs,
com.linkedin.r2.transport.common.bridge.common.TransportCallback<com.linkedin.r2.message.stream.StreamResponse> callback)
streamRequest in interface com.linkedin.r2.transport.common.bridge.client.TransportClientprotected ChannelPoolManager getChannelPoolManagerPerRequest(com.linkedin.r2.message.Request request)
public final void shutdown(com.linkedin.common.callback.Callback<com.linkedin.common.util.None> callback)
shutdown in interface com.linkedin.r2.transport.common.bridge.client.TransportClientpublic static <T> void errorResponse(com.linkedin.r2.transport.common.bridge.common.TransportCallback<T> callback,
java.lang.Throwable e)
public static java.lang.Exception toException(java.lang.Throwable t)
public final java.util.Map<java.lang.String,com.linkedin.r2.transport.http.client.PoolStats> getPoolStats()
AsyncPoolStats objects.