public class NettyUDPClient extends Object
Modifier and Type | Field and Description |
---|---|
private org.jboss.netty.channel.socket.DatagramChannelFactory |
channelFactory
The instance of
NioDatagramChannelFactory created by constructor,
or the one passed in to constructor. |
static Map<InetSocketAddress,Session> |
CLIENTS
This map is used to store the local address to which a session has bound
itself using the
Channel.bind(java.net.SocketAddress)
method. |
private org.jboss.netty.channel.ChannelPipelineFactory |
pipelineFactory
For UDP there can only be one pipelineFactory per
ConnectionlessBootstrap . |
private InetSocketAddress |
serverAddress
The remote server address to which this client should connect.
|
private org.jboss.netty.bootstrap.ConnectionlessBootstrap |
udpBootstrap |
private ExecutorService |
worker
The worker executor which will provide threads to Netty
ChannelFactory for decoding encoding done on the
ChannelPipeline . |
Constructor and Description |
---|
NettyUDPClient(InetSocketAddress serverAddress,
org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory) |
NettyUDPClient(InetSocketAddress serverAddress,
org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory,
org.jboss.netty.channel.socket.DatagramChannelFactory channelFactory,
ExecutorService worker)
Creates a new instance of the
NettyUDPClient . |
NettyUDPClient(String jetserverHost,
int port,
org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory)
Creates an instance of a Netty UDP client which can then be used to
connect to a remote jet-server.
|
Modifier and Type | Method and Description |
---|---|
org.jboss.netty.channel.ChannelFuture |
connect(Session session,
org.jboss.netty.channel.socket.DatagramChannel datagramChannel)
This method will connect the datagram channel with the server and send
the
Events.CONNECT message to server. |
org.jboss.netty.channel.ChannelFuture |
connect(Session session,
org.jboss.netty.channel.socket.DatagramChannel datagramChannel,
InetSocketAddress serverAddress,
int timeout,
TimeUnit unit)
This method will connect the datagram channel with the server and send
the
Events.CONNECT message to server. |
org.jboss.netty.channel.socket.DatagramChannel |
createDatagramChannel()
Creates a new datagram channel instance using the
udpBootstrap
by binding to local host. |
org.jboss.netty.channel.socket.DatagramChannel |
createDatagramChannel(String localhostName)
Creates a new datagram channel instance using the
udpBootstrap
by binding to local host. |
org.jboss.netty.channel.socket.DatagramChannelFactory |
getChannelFactory() |
InetSocketAddress |
getLocalAddress(org.jboss.netty.channel.socket.DatagramChannel c) |
org.jboss.netty.channel.ChannelPipelineFactory |
getPipelineFactory() |
InetSocketAddress |
getServerAddress() |
org.jboss.netty.bootstrap.ConnectionlessBootstrap |
getUdpBootstrap() |
ExecutorService |
getWorker() |
org.jboss.netty.channel.ChannelFuture |
write(org.jboss.netty.channel.socket.DatagramChannel datagramChannel,
Object message)
Utility method used to send a message to the server.
|
static org.jboss.netty.channel.ChannelFuture |
write(org.jboss.netty.channel.socket.DatagramChannel datagramChannel,
Object message,
InetSocketAddress serverAddress)
Utility method used to send a message to the server.
|
private final InetSocketAddress serverAddress
private final ExecutorService worker
ChannelFactory
for decoding encoding done on the
ChannelPipeline
.private final org.jboss.netty.bootstrap.ConnectionlessBootstrap udpBootstrap
private final org.jboss.netty.channel.socket.DatagramChannelFactory channelFactory
NioDatagramChannelFactory
created by constructor,
or the one passed in to constructor.private final org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory
ConnectionlessBootstrap
. This factory is hence part of the client
class.public static final Map<InetSocketAddress,Session> CLIENTS
Channel.bind(java.net.SocketAddress)
method. When an incoming UDP packet is recieved the
UDPUpstreamHandler
will resolve which session to pass the event,
using this map.public NettyUDPClient(String jetserverHost, int port, org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory) throws UnknownHostException, Exception
NettyUDPClient(InetSocketAddress, ChannelPipelineFactory)
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.pipelineFactory
- The pipeline factory to be used while creating a Netty
Channel
UnknownHostException
Exception
public NettyUDPClient(InetSocketAddress serverAddress, org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory) throws UnknownHostException, Exception
UnknownHostException
Exception
public NettyUDPClient(InetSocketAddress serverAddress, org.jboss.netty.channel.ChannelPipelineFactory pipelineFactory, org.jboss.netty.channel.socket.DatagramChannelFactory channelFactory, ExecutorService worker) throws UnknownHostException, Exception
NettyUDPClient
.serverAddress
- The remote servers address. This address will be used when any
of the default write/connect methods are used.pipelineFactory
- The Netty factory used for creating a pipeline. For UDP, this
pipeline factory should not have any stateful i.e non
share-able handlers in it. Since Netty only has one channel
for ALL UPD traffic.channelFactory
- Can be provided as null. If so, it will by default use
NioDatagramChannelFactory
. If not null, then the
provided factory is set.worker
- The executor used for creating worker threads. Can be null if
channelFactory parameter is Not null.UnknownHostException
Exception
public org.jboss.netty.channel.socket.DatagramChannel createDatagramChannel() throws UnknownHostException
udpBootstrap
by binding to local host. This method delegates to
createDatagramChannel(String)
internally, by passing the
localhost's host name to it.UnknownHostException
public org.jboss.netty.channel.socket.DatagramChannel createDatagramChannel(String localhostName) throws UnknownHostException
udpBootstrap
by binding to local host.localhostName
- The host machine (for e.g. 'localhost') to which it needs to
bind to. This is Not the remote jet-server hostname.UnknownHostException
public org.jboss.netty.channel.ChannelFuture connect(Session session, org.jboss.netty.channel.socket.DatagramChannel datagramChannel) throws UnknownHostException, InterruptedException
Events.CONNECT
message to server. This method will use
serverAddress
by default when sending the
Events.CONNECT
message. Note Even if this connect
message does not reach server, the first UDP message that the server
receives from this particular DatagramChannels local address will be
converted by server and used as Events.CONNECT
.session
- The session for which the datagram channel is being created.datagramChannel
- The channel on which the message is to be sent to remote
server.UnknownHostException
InterruptedException
public org.jboss.netty.channel.ChannelFuture connect(Session session, org.jboss.netty.channel.socket.DatagramChannel datagramChannel, InetSocketAddress serverAddress, int timeout, TimeUnit unit) throws UnknownHostException, InterruptedException
Events.CONNECT
message to server.session
- The session for which the datagram channel is being created.datagramChannel
- The channel on which the message is to be sent to remote
server.serverAddress
- The remote address of the server to which to send this
message.timeout
- Amount of time to wait for the connection to happen.
NOTE Since this is UDP there is actually no "real"
connection.UnknownHostException
InterruptedException
public org.jboss.netty.channel.ChannelFuture write(org.jboss.netty.channel.socket.DatagramChannel datagramChannel, Object message)
write(DatagramChannel, Object, InetSocketAddress)
by passing in the InetSocketAddress stored in the class variable
serverAddress
datagramChannel
- The channel on which the message is to be sent to remote
server.message
- The message to be sent. NOTE The message should be a
valid and encode-able by the encoders in the ChannelPipeline
of this server.public static org.jboss.netty.channel.ChannelFuture write(org.jboss.netty.channel.socket.DatagramChannel datagramChannel, Object message, InetSocketAddress serverAddress)
datagramChannel
- The channel on which the message is to be sent to remote
server.message
- The message to be sent. NOTE The message should be a
valid and encode-able by the encoders in the ChannelPipeline
of this server.public InetSocketAddress getLocalAddress(org.jboss.netty.channel.socket.DatagramChannel c)
public InetSocketAddress getServerAddress()
public ExecutorService getWorker()
public org.jboss.netty.bootstrap.ConnectionlessBootstrap getUdpBootstrap()
public org.jboss.netty.channel.socket.DatagramChannelFactory getChannelFactory()
public org.jboss.netty.channel.ChannelPipelineFactory getPipelineFactory()
Copyright © 2012. All Rights Reserved.