@ChannelHandler.Sharable public class NettyClientRouter extends io.netty.channel.SimpleChannelInboundHandler<CorfuMsg> implements IClientRouter
Created by mwei on 12/8/15.
Modifier and Type | Field and Description |
---|---|
List<IClient> |
clientList
The clients registered to this router.
|
Map<CorfuMsgType,IClient> |
handlerMap
The handlers registered to this router.
|
Map<Long,CompletableFuture> |
outstandingRequests
The outstanding requests on this router.
|
AtomicLong |
requestID
Deprecated.
|
boolean |
shutdown
Whether or not this router is shutdown.
|
long |
timeoutConnect
New connection timeout (milliseconds).
|
long |
timeoutResponse
Sync call response timeout (milliseconds).
|
long |
timeoutRetry
Retry interval after timeout (milliseconds).
|
Constructor and Description |
---|
NettyClientRouter(NodeLocator node,
CorfuRuntime.CorfuRuntimeParameters parameters) |
NettyClientRouter(NodeLocator node,
io.netty.channel.EventLoopGroup eventLoopGroup,
CorfuRuntime.CorfuRuntimeParameters parameters)
Creates a new NettyClientRouter connected to the specified host and port with the
specified tls and sasl options.
|
NettyClientRouter(String endpoint)
Deprecated.
Use
this#NettyClientRouter(NodeLocator, CorfuRuntimeParameters) |
NettyClientRouter(String host,
Integer port)
Deprecated.
Use
this#NettyClientRouter(NodeLocator, CorfuRuntimeParameters) |
NettyClientRouter(String host,
Integer port,
Boolean tls,
String keyStore,
String ksPasswordFile,
String trustStore,
String tsPasswordFile,
Boolean saslPlainText,
String usernameFile,
String passwordFile)
Deprecated.
Use
this#NettyClientRouter(NodeLocator, CorfuRuntimeParameters) |
Modifier and Type | Method and Description |
---|---|
IClientRouter |
addClient(IClient client)
Add a new client to the router.
|
protected void |
channelRead0(io.netty.channel.ChannelHandlerContext ctx,
CorfuMsg m) |
void |
completeExceptionally(long requestID,
Throwable cause)
Exceptionally complete a request with a given cause.
|
<T> void |
completeRequest(long requestId,
T completion)
Complete a given outstanding request with a completion value.
|
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
<T extends IClient> |
getClient(Class<T> clientType)
Gets a client that matches a particular type.
|
String |
getHost()
Deprecated.
|
Integer |
getPort()
Deprecated.
|
void |
sendMessage(io.netty.channel.ChannelHandlerContext ctx,
CorfuMsg message)
Send a one way message, without adding a completable future.
|
<T> CompletableFuture<T> |
sendMessageAndGetCompletable(io.netty.channel.ChannelHandlerContext ctx,
CorfuMsg message)
Send a message and get a completable future to be fulfilled by the reply.
|
void |
sendResponseToServer(io.netty.channel.ChannelHandlerContext ctx,
CorfuMsg inMsg,
CorfuMsg outMsg)
Send a netty message through this router, setting the fields in the outgoing message.
|
void |
start()
Deprecated.
The router automatically starts now, so this function call is no
longer necessary
|
void |
stop()
Stops routing requests.
|
void |
stop(boolean shutdown)
Deprecated.
Deprecated, stopping a router without shutting it down is no longer supported.
Please use
this#stop() . |
void |
userEventTriggered(io.netty.channel.ChannelHandlerContext ctx,
Object evt) |
acceptInboundMessage, channelRead
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
sendMessage, sendMessageAndGetCompletable, setTimeoutConnect, setTimeoutResponse, setTimeoutRetry
public long timeoutConnect
public long timeoutResponse
public long timeoutRetry
@Deprecated public AtomicLong requestID
public Map<CorfuMsgType,IClient> handlerMap
public Map<Long,CompletableFuture> outstandingRequests
public volatile boolean shutdown
public NettyClientRouter(@Nonnull NodeLocator node, @Nonnull io.netty.channel.EventLoopGroup eventLoopGroup, @Nonnull CorfuRuntime.CorfuRuntimeParameters parameters)
this
will attempt connection to
the node until this#stop()
is called.node
- The node to connect to.eventLoopGroup
- The EventLoopGroup
for servicing I/O.parameters
- A CorfuRuntime.CorfuRuntimeParameters
with the desired configuration.@Deprecated public NettyClientRouter(String endpoint)
this#NettyClientRouter(NodeLocator, CorfuRuntimeParameters)
endpoint
- Endpoint to connectAsync to.@Deprecated public NettyClientRouter(String host, Integer port)
this#NettyClientRouter(NodeLocator, CorfuRuntimeParameters)
host
- Host to connectAsync to.port
- Port to connectAsync to.@Deprecated public NettyClientRouter(String host, Integer port, Boolean tls, String keyStore, String ksPasswordFile, String trustStore, String tsPasswordFile, Boolean saslPlainText, String usernameFile, String passwordFile)
this#NettyClientRouter(NodeLocator, CorfuRuntimeParameters)
host
- Host to connectAsync to.port
- Port to connectAsync to.public NettyClientRouter(@Nonnull NodeLocator node, @Nonnull CorfuRuntime.CorfuRuntimeParameters parameters)
public IClientRouter addClient(IClient client)
addClient
in interface IClientRouter
client
- The client to add to the router.public <T extends IClient> T getClient(Class<T> clientType)
getClient
in interface IClientRouter
T
- The type of the client to match.clientType
- The class of the client to match.NoSuchElementException
- If there are no clients matching that type.@Deprecated public void start()
start
in interface IClientRouter
public void stop()
stop
in interface IClientRouter
@Deprecated public void stop(boolean shutdown)
this#stop()
.stop
in interface IClientRouter
public <T> CompletableFuture<T> sendMessageAndGetCompletable(io.netty.channel.ChannelHandlerContext ctx, @NonNull CorfuMsg message)
sendMessageAndGetCompletable
in interface IClientRouter
T
- The type of completable to return.ctx
- The channel handler context to send the message under.message
- The message to send.public void sendMessage(io.netty.channel.ChannelHandlerContext ctx, CorfuMsg message)
sendMessage
in interface IClientRouter
ctx
- The context to send the message under.message
- The message to send.public void sendResponseToServer(io.netty.channel.ChannelHandlerContext ctx, CorfuMsg inMsg, CorfuMsg outMsg)
sendResponseToServer
in interface IClientRouter
ctx
- Channel handler context to use.inMsg
- Incoming message to respond to.outMsg
- Outgoing message.public <T> void completeRequest(long requestId, T completion)
completeRequest
in interface IClientRouter
T
- The type of the completion.requestId
- The request to complete.completion
- The value to complete the request withpublic void completeExceptionally(long requestID, @Nonnull Throwable cause)
completeExceptionally
in interface IClientRouter
requestID
- The request to complete.cause
- The cause to give for the exceptional completion.protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, CorfuMsg m) throws Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception
userEventTriggered
in interface io.netty.channel.ChannelInboundHandler
userEventTriggered
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
@Deprecated public Integer getPort()
IClientRouter
getPort
in interface IClientRouter
@Deprecated public String getHost()
IClientRouter
getHost
in interface IClientRouter
Copyright © 2019 CorfuDB. All rights reserved.