Class AbstractUDPServer<T>
java.lang.Object
org.openremote.agent.protocol.io.AbstractNettyIOServer<T,io.netty.channel.socket.DatagramChannel,io.netty.bootstrap.Bootstrap,InetSocketAddress>
org.openremote.agent.protocol.udp.AbstractUDPServer<T>
- All Implemented Interfaces:
IOServer<T,
io.netty.channel.socket.DatagramChannel, InetSocketAddress>
- Direct Known Subclasses:
UDPStringServer
public abstract class AbstractUDPServer<T>
extends AbstractNettyIOServer<T,io.netty.channel.socket.DatagramChannel,io.netty.bootstrap.Bootstrap,InetSocketAddress>
UDP in Netty is crap; everything goes through the single server channel as it is connectionless but there is no way
of tracking packet origin across decoders. From reading each channel is single threaded so making an assumption that
we can store packet origin for processing in
AbstractNettyIOServer.onMessageReceived(T, U, W)
.
For outbound messages we wrap each decoder in a DatagramPacketEncoder
which unfortunately only supports
MessageToMessageEncoder
s.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.openremote.agent.protocol.io.IOServer
IOServer.IoServerMessageConsumer<T,
U, V> -
Field Summary
FieldsFields inherited from class org.openremote.agent.protocol.io.AbstractNettyIOServer
allChannels, bootstrap, channel, channelFuture, clientConnectionStatusConsumers, clientLimit, connectionStatus, connectionStatusConsumers, executorService, INITIAL_RECONNECT_DELAY_MILLIS, LOG, MAX_RECONNECT_DELAY_MILLIS, messageConsumers, RECONNECT_BACKOFF_MULTIPLIER, reconnectDelayMilliseconds, reconnectTask, scheduledExecutorService, workerGroup
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addEncoder
(io.netty.channel.socket.DatagramChannel channel, io.netty.channel.ChannelOutboundHandler encoder) protected io.netty.bootstrap.Bootstrap
Create and configure the bootstrap to use for this instanceprotected String
getClientDescriptor
(io.netty.channel.socket.DatagramChannel client) Should return a descriptor to identify the specified client for use in log files etc.protected String
Get a string identifier that uniquely identifies the current instance of this server.protected void
handleMessageReceived
(io.netty.channel.socket.DatagramChannel channel, T message) protected void
initChannel
(io.netty.channel.socket.DatagramChannel channel) void
sendMessage
(T message) Send a message to all clientsvoid
sendMessage
(T message, io.netty.channel.socket.DatagramChannel client) Send a message to a clientvoid
sendMessage
(T message, InetSocketAddress destination) Send a message to a recipient by address; for connection based protocols then the recipient must already be connected; this is mostly useful for connectionless protocols (i.e.Methods inherited from class org.openremote.agent.protocol.io.AbstractNettyIOServer
addConnectionStatusConsumer, addConnectionStatusConsumer, addDecoder, addDecoders, addEncoders, addMessageConsumer, disconnectClient, getConnectionStatus, getConnectionStatus, initClientChannel, onClientConnected, onClientDisconnected, onConnectionStatusChanged, onDecodeException, onEncodeException, onMessageReceived, removeAllConnectionStatusConsumers, removeAllMessageConsumers, removeConnectionStatusConsumer, removeConnectionStatusConsumer, removeMessageConsumer, scheduleReconnect, sendClientConnectionStatus, start, stop
-
Field Details
-
localAddress
-
lastMessageSender
-
-
Constructor Details
-
AbstractUDPServer
-
-
Method Details
-
getSocketAddressString
Description copied from class:AbstractNettyIOServer
Get a string identifier that uniquely identifies the current instance of this server. e.g. tcp://IP:PORT- Specified by:
getSocketAddressString
in classAbstractNettyIOServer<T,
io.netty.channel.socket.DatagramChannel, io.netty.bootstrap.Bootstrap, InetSocketAddress>
-
getClientDescriptor
Description copied from class:AbstractNettyIOServer
Should return a descriptor to identify the specified client for use in log files etc.- Specified by:
getClientDescriptor
in classAbstractNettyIOServer<T,
io.netty.channel.socket.DatagramChannel, io.netty.bootstrap.Bootstrap, InetSocketAddress>
-
createAndConfigureBootstrap
protected io.netty.bootstrap.Bootstrap createAndConfigureBootstrap()Description copied from class:AbstractNettyIOServer
Create and configure the bootstrap to use for this instance- Specified by:
createAndConfigureBootstrap
in classAbstractNettyIOServer<T,
io.netty.channel.socket.DatagramChannel, io.netty.bootstrap.Bootstrap, InetSocketAddress>
-
initChannel
protected void initChannel(io.netty.channel.socket.DatagramChannel channel) - Overrides:
initChannel
in classAbstractNettyIOServer<T,
io.netty.channel.socket.DatagramChannel, io.netty.bootstrap.Bootstrap, InetSocketAddress>
-
sendMessage
Description copied from interface:IOServer
Send a message to all clients- Specified by:
sendMessage
in interfaceIOServer<T,
io.netty.channel.socket.DatagramChannel, InetSocketAddress> - Overrides:
sendMessage
in classAbstractNettyIOServer<T,
io.netty.channel.socket.DatagramChannel, io.netty.bootstrap.Bootstrap, InetSocketAddress>
-
sendMessage
Description copied from interface:IOServer
Send a message to a client- Specified by:
sendMessage
in interfaceIOServer<T,
io.netty.channel.socket.DatagramChannel, InetSocketAddress> - Overrides:
sendMessage
in classAbstractNettyIOServer<T,
io.netty.channel.socket.DatagramChannel, io.netty.bootstrap.Bootstrap, InetSocketAddress>
-
sendMessage
Description copied from class:AbstractNettyIOServer
Send a message to a recipient by address; for connection based protocols then the recipient must already be connected; this is mostly useful for connectionless protocols (i.e. UDP where only a single channel exists)- Overrides:
sendMessage
in classAbstractNettyIOServer<T,
io.netty.channel.socket.DatagramChannel, io.netty.bootstrap.Bootstrap, InetSocketAddress>
-
addEncoder
protected void addEncoder(io.netty.channel.socket.DatagramChannel channel, io.netty.channel.ChannelOutboundHandler encoder) - Overrides:
addEncoder
in classAbstractNettyIOServer<T,
io.netty.channel.socket.DatagramChannel, io.netty.bootstrap.Bootstrap, InetSocketAddress>
-
handleMessageReceived
- Overrides:
handleMessageReceived
in classAbstractNettyIOServer<T,
io.netty.channel.socket.DatagramChannel, io.netty.bootstrap.Bootstrap, InetSocketAddress>
-