public class NettyTCPClient extends Object
Modifier and Type | Field and Description |
---|---|
static org.jboss.netty.channel.group.ChannelGroup |
ALL_CHANNELS
Any successful TCP connection opened by the client to server is also
added to this
ChannelGroup . |
private org.jboss.netty.bootstrap.ClientBootstrap |
bootstrap |
private ExecutorService |
boss
The boss executor which will provide threads to Netty
ChannelFactory for reading from the NIO selectors. |
private org.jboss.netty.channel.ChannelFactory |
channelFactory
The instance of
NioClientSocketChannelFactory created by
constructor, or the one passed in to constructor. |
private int |
maxShutdownWaitTime
The amount of time in seconds to wait for this client to close all
Channel s and shutdown gracefully. |
private InetSocketAddress |
serverAddress
The remote server address to which this client should connect.
|
private ExecutorService |
worker
The worker executor which will provide threads to Netty
ChannelFactory for decoding encoding done on the
ChannelPipeline . |
Constructor and Description |
---|
NettyTCPClient(InetSocketAddress serverAddress) |
NettyTCPClient(InetSocketAddress serverAddress,
ExecutorService boss,
ExecutorService worker,
org.jboss.netty.channel.ChannelFactory channelFactory,
int maxShutdownWaitTime)
Creates a new instance of the
NettyTCPClient . |
NettyTCPClient(String jetserverHost,
int port)
Creates an instance of a Netty TCP client which can then be used to
connect to a remote jet-server.
|
Modifier and Type | Method and Description |
---|---|
org.jboss.netty.channel.Channel |
connect(org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory,
Event loginEvent)
This method delegates to the
connect(ChannelPipelineFactory, Event, int, TimeUnit)
method internally. |
org.jboss.netty.channel.Channel |
connect(org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory,
Event loginEvent,
int timeout,
TimeUnit unit)
Method that is used to create the connection or
Channel to
communicated with the remote jetserver. |
org.jboss.netty.bootstrap.ClientBootstrap |
getBootstrap() |
ExecutorService |
getBoss() |
org.jboss.netty.channel.ChannelFactory |
getChannelFactory() |
int |
getMaxShutdownWaitTime() |
InetSocketAddress |
getServerAddress() |
ExecutorService |
getWorker() |
private final InetSocketAddress serverAddress
private final org.jboss.netty.channel.ChannelFactory channelFactory
NioClientSocketChannelFactory
created by
constructor, or the one passed in to constructor.private final ExecutorService boss
ChannelFactory
for reading from the NIO selectors.private final ExecutorService worker
ChannelFactory
for decoding encoding done on the
ChannelPipeline
.private final org.jboss.netty.bootstrap.ClientBootstrap bootstrap
private final int maxShutdownWaitTime
Channel
s and shutdown gracefully.public static final org.jboss.netty.channel.group.ChannelGroup ALL_CHANNELS
ChannelGroup
. This will be used for shutting down
the client gracefully.public NettyTCPClient(String jetserverHost, int port)
NettyTCPClient(InetSocketAddress)
constructor after creating a
InetSocketAddress
instance based on the host and port number
passed in.jetserverHost
- The host name of the remote server on which jetserver is
running.port
- The port to connect to, on the remote server.public NettyTCPClient(InetSocketAddress serverAddress)
public NettyTCPClient(InetSocketAddress serverAddress, ExecutorService boss, ExecutorService worker, org.jboss.netty.channel.ChannelFactory channelFactory, int maxShutdownWaitTime)
NettyTCPClient
. This constructor
also registers a shutdown hook which will call close on
ALL_CHANNELS
and call bootstrap.releaseExternalResources() to
enable a graceful shutdown.serverAddress
- The remote servers address. This address will be used when any
of the default write/connect methods are used.boss
- Executor
used for creating the channelFactory
instance. Can be null if channelFactory
is not
null.worker
- Executor
used for creating the channelFactory
instance. Can be null if channelFactory
is not
null.channelFactory
- Can be provided as null. If so, it will by default use
NioClientSocketChannelFactory
. If not null, then the
provided factory is set.maxShutdownWaitTime
- The amount of time in seconds to wait for this client to close
all Channel
s and shutdown gracefully.public org.jboss.netty.channel.Channel connect(org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory, Event loginEvent) throws InterruptedException
connect(ChannelPipelineFactory, Event, int, TimeUnit)
method internally. It will pass in a default of 5 seconds wait time to
the delegated method.pipelineFactory
- The factory used to create a pipeline of decoders and encoders
for each Channel
that it creates on connection.loginEvent
- The event contains the ChannelBuffer
to be transmitted
to jetserver for logging in. Values inside this buffer include
username, password, connection key, optional local
address of the UDP channel used by this session.Channel
which is the connection to the
remote jetserver.InterruptedException
public org.jboss.netty.channel.Channel connect(org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory, Event loginEvent, int timeout, TimeUnit unit) throws InterruptedException
Channel
to
communicated with the remote jetserver.pipelineFactory
- The factory used to create a pipeline of decoders and encoders
for each Channel
that it creates on connection.loginEvent
- The event contains the ChannelBuffer
to be transmitted
to jetserver for logging in. Values inside this buffer include
username, password, connection key, optional local
address of the UDP channel used by this session.timeout
- The amount of time to wait for this connection be created
successfully.unit
- The unit of timeout SECONDS, MILLISECONDS etc. Default is 5
seconds.Channel
which is the connection to the
remote jetserver.InterruptedException
public InetSocketAddress getServerAddress()
public org.jboss.netty.channel.ChannelFactory getChannelFactory()
public ExecutorService getBoss()
public ExecutorService getWorker()
public org.jboss.netty.bootstrap.ClientBootstrap getBootstrap()
public int getMaxShutdownWaitTime()
Copyright © 2012. All Rights Reserved.