Package org.openremote.agent.protocol.io
Class AbstractNettyIOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>,W extends SocketAddress>
java.lang.Object
org.openremote.agent.protocol.io.AbstractNettyIOServer<T,U,V,W>
- All Implemented Interfaces:
IOServer<T,
U, W>
- Direct Known Subclasses:
AbstractTCPServer
,AbstractUDPServer
public abstract class AbstractNettyIOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>,W extends SocketAddress>
extends Object
implements IOServer<T,U,W>
Abstract implementation of
IOServer
that uses the Netty library.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.openremote.agent.protocol.io.IOServer
IOServer.IoServerMessageConsumer<T,
U, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.netty.channel.group.ChannelGroup
protected V
protected U
protected io.netty.channel.ChannelFuture
protected final List<BiConsumer<U,
org.openremote.model.asset.agent.ConnectionStatus>> protected int
protected org.openremote.model.asset.agent.ConnectionStatus
protected final ExecutorService
protected static final int
protected static final Logger
protected static final int
protected final List<IOServer.IoServerMessageConsumer<T,
U, W>> protected static final int
protected int
protected ScheduledFuture<?>
protected final ScheduledExecutorService
protected io.netty.channel.EventLoopGroup
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConnectionStatusConsumer
(BiConsumer<U, org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Add a consumer of client connection status changesvoid
addConnectionStatusConsumer
(Consumer<org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Add a consumer of server connection status changesprotected void
addDecoder
(U channel, io.netty.channel.ChannelInboundHandler decoder) protected abstract void
addDecoders
(U channel) protected void
addEncoder
(U channel, io.netty.channel.ChannelOutboundHandler encoder) protected abstract void
addEncoders
(U channel) void
addMessageConsumer
(IOServer.IoServerMessageConsumer<T, U, W> messageConsumer) Add a consumer of received messagesprotected abstract V
Create and configure the bootstrap to use for this instancevoid
disconnectClient
(U client) Forcibly close the connection to a clientprotected abstract String
getClientDescriptor
(U client) Should return a descriptor to identify the specified client for use in log files etc.org.openremote.model.asset.agent.ConnectionStatus
Get current connection status of the serverorg.openremote.model.asset.agent.ConnectionStatus
getConnectionStatus
(U client) Get current connection status of a client (eitherConnectionStatus.CONNECTED
orConnectionStatus.DISCONNECTED
)protected abstract String
Get a string identifier that uniquely identifies the current instance of this server.protected void
handleMessageReceived
(U channel, T message) protected void
initChannel
(U channel) protected void
initClientChannel
(U channel) Initialise the specified client channel (will be called when a new client connection is made)protected void
onClientConnected
(U client) protected void
onClientDisconnected
(U client) protected void
onConnectionStatusChanged
(org.openremote.model.asset.agent.ConnectionStatus connectionStatus) protected void
onDecodeException
(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) protected void
onEncodeException
(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) protected void
onMessageReceived
(T message, U channel, W sender) void
Remove every consumer of connection statusvoid
Remove every consumer of received messagesvoid
removeConnectionStatusConsumer
(BiConsumer<U, org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Remove a consumer of client connection status changesvoid
removeConnectionStatusConsumer
(Consumer<org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Remove a consumer of server connection status changesvoid
removeMessageConsumer
(IOServer.IoServerMessageConsumer<T, U, W> messageConsumer) Remove a consumer of received messagesprotected void
protected void
sendClientConnectionStatus
(U channel, org.openremote.model.asset.agent.ConnectionStatus connectionStatus) void
sendMessage
(T message) Send a message to all clientsvoid
sendMessage
(T message, U client) Send a message to a clientvoid
sendMessage
(T message, W recipient) 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.void
start()
Start the servervoid
stop()
Stop the server
-
Field Details
-
INITIAL_RECONNECT_DELAY_MILLIS
protected static final int INITIAL_RECONNECT_DELAY_MILLIS- See Also:
-
MAX_RECONNECT_DELAY_MILLIS
protected static final int MAX_RECONNECT_DELAY_MILLIS- See Also:
-
RECONNECT_BACKOFF_MULTIPLIER
protected static final int RECONNECT_BACKOFF_MULTIPLIER- See Also:
-
LOG
-
executorService
-
scheduledExecutorService
-
clientLimit
protected int clientLimit -
bootstrap
-
connectionStatus
protected org.openremote.model.asset.agent.ConnectionStatus connectionStatus -
channelFuture
protected io.netty.channel.ChannelFuture channelFuture -
workerGroup
protected io.netty.channel.EventLoopGroup workerGroup -
channel
-
allChannels
protected final io.netty.channel.group.ChannelGroup allChannels -
messageConsumers
protected final List<IOServer.IoServerMessageConsumer<T,U extends io.netty.channel.Channel, messageConsumersW extends SocketAddress>> -
connectionStatusConsumers
-
clientConnectionStatusConsumers
protected final List<BiConsumer<U extends io.netty.channel.Channel,org.openremote.model.asset.agent.ConnectionStatus>> clientConnectionStatusConsumers -
reconnectTask
-
reconnectDelayMilliseconds
protected int reconnectDelayMilliseconds
-
-
Constructor Details
-
AbstractNettyIOServer
public AbstractNettyIOServer()
-
-
Method Details
-
start
public void start()Description copied from interface:IOServer
Start the server -
stop
public void stop()Description copied from interface:IOServer
Stop the server -
addMessageConsumer
Description copied from interface:IOServer
Add a consumer of received messages- Specified by:
addMessageConsumer
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
removeMessageConsumer
Description copied from interface:IOServer
Remove a consumer of received messages- Specified by:
removeMessageConsumer
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
removeAllMessageConsumers
public void removeAllMessageConsumers()Description copied from interface:IOServer
Remove every consumer of received messages- Specified by:
removeAllMessageConsumers
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
addConnectionStatusConsumer
public void addConnectionStatusConsumer(Consumer<org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Description copied from interface:IOServer
Add a consumer of server connection status changes- Specified by:
addConnectionStatusConsumer
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
removeConnectionStatusConsumer
public void removeConnectionStatusConsumer(Consumer<org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Description copied from interface:IOServer
Remove a consumer of server connection status changes- Specified by:
removeConnectionStatusConsumer
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
addConnectionStatusConsumer
public void addConnectionStatusConsumer(BiConsumer<U, org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Description copied from interface:IOServer
Add a consumer of client connection status changes- Specified by:
addConnectionStatusConsumer
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
removeConnectionStatusConsumer
public void removeConnectionStatusConsumer(BiConsumer<U, org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Description copied from interface:IOServer
Remove a consumer of client connection status changes- Specified by:
removeConnectionStatusConsumer
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
removeAllConnectionStatusConsumers
public void removeAllConnectionStatusConsumers()Description copied from interface:IOServer
Remove every consumer of connection status- Specified by:
removeAllConnectionStatusConsumers
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
getConnectionStatus
public org.openremote.model.asset.agent.ConnectionStatus getConnectionStatus()Description copied from interface:IOServer
Get current connection status of the server- Specified by:
getConnectionStatus
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
getConnectionStatus
Description copied from interface:IOServer
Get current connection status of a client (eitherConnectionStatus.CONNECTED
orConnectionStatus.DISCONNECTED
)- Specified by:
getConnectionStatus
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
disconnectClient
Description copied from interface:IOServer
Forcibly close the connection to a client- Specified by:
disconnectClient
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
initChannel
-
initClientChannel
Initialise the specified client channel (will be called when a new client connection is made) -
handleMessageReceived
-
onClientDisconnected
-
onClientConnected
-
onConnectionStatusChanged
protected void onConnectionStatusChanged(org.openremote.model.asset.agent.ConnectionStatus connectionStatus) -
sendClientConnectionStatus
protected void sendClientConnectionStatus(U channel, org.openremote.model.asset.agent.ConnectionStatus connectionStatus) -
onMessageReceived
-
onDecodeException
-
onEncodeException
-
sendMessage
Description copied from interface:IOServer
Send a message to a client- Specified by:
sendMessage
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
sendMessage
Description copied from interface:IOServer
Send a message to all clients- Specified by:
sendMessage
in interfaceIOServer<T,
U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
sendMessage
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) -
scheduleReconnect
protected void scheduleReconnect() -
getSocketAddressString
Get a string identifier that uniquely identifies the current instance of this server. e.g. tcp://IP:PORT -
createAndConfigureBootstrap
Create and configure the bootstrap to use for this instance -
getClientDescriptor
Should return a descriptor to identify the specified client for use in log files etc. -
addDecoders
-
addEncoders
-
addDecoder
-
addEncoder
-