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.ChannelGroupprotected Vprotected Uprotected io.netty.channel.ChannelFutureprotected final List<BiConsumer<U,org.openremote.model.asset.agent.ConnectionStatus>> protected intprotected org.openremote.model.asset.agent.ConnectionStatusprotected final ScheduledExecutorServiceprotected static final intprotected static final Loggerprotected static final intprotected final List<IOServer.IoServerMessageConsumer<T,U, W>> protected static final intprotected intprotected ScheduledFuture<?>protected io.netty.channel.EventLoopGroup -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnectionStatusConsumer(BiConsumer<U, org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Add a consumer of client connection status changesvoidaddConnectionStatusConsumer(Consumer<org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Add a consumer of server connection status changesprotected voidaddDecoder(U channel, io.netty.channel.ChannelInboundHandler decoder) protected abstract voidaddDecoders(U channel) protected voidaddEncoder(U channel, io.netty.channel.ChannelOutboundHandler encoder) protected abstract voidaddEncoders(U channel) voidaddMessageConsumer(IOServer.IoServerMessageConsumer<T, U, W> messageConsumer) Add a consumer of received messagesprotected abstract VCreate and configure the bootstrap to use for this instancevoiddisconnectClient(U client) Forcibly close the connection to a clientprotected abstract StringgetClientDescriptor(U client) Should return a descriptor to identify the speficied client for use in log files etc.org.openremote.model.asset.agent.ConnectionStatusGet current connection status of the serverorg.openremote.model.asset.agent.ConnectionStatusgetConnectionStatus(U client) Get current connection status of a client (eitherConnectionStatus.CONNECTEDorConnectionStatus.DISCONNECTED)protected abstract StringGet a string identifier that uniquely identifies the current instance of this server.protected voidhandleMessageReceived(U channel, T message) protected voidinitChannel(U channel) protected voidinitClientChannel(U channel) Initialise the specified client channel (will be called when a new client connection is made)protected voidonClientConnected(U client) protected voidonClientDisconnected(U client) protected voidonConnectionStatusChanged(org.openremote.model.asset.agent.ConnectionStatus connectionStatus) protected voidonDecodeException(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) protected voidonEncodeException(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) protected voidonMessageReceived(T message, U channel, W sender) voidRemove every consumer of connection statusvoidRemove every consumer of received messagesvoidremoveConnectionStatusConsumer(BiConsumer<U, org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Remove a consumer of client connection status changesvoidremoveConnectionStatusConsumer(Consumer<org.openremote.model.asset.agent.ConnectionStatus> connectionStatusConsumer) Remove a consumer of server connection status changesvoidremoveMessageConsumer(IOServer.IoServerMessageConsumer<T, U, W> messageConsumer) Remove a consumer of received messagesprotected voidprotected voidsendClientConnectionStatus(U channel, org.openremote.model.asset.agent.ConnectionStatus connectionStatus) voidsendMessage(T message) Send a message to all clientsvoidsendMessage(T message, U client) Send a message to a clientvoidsendMessage(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.voidstart()Start the servervoidstop()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
-
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:IOServerStart the server -
stop
public void stop()Description copied from interface:IOServerStop the server -
addMessageConsumer
Description copied from interface:IOServerAdd a consumer of received messages- Specified by:
addMessageConsumerin interfaceIOServer<T,U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
removeMessageConsumer
Description copied from interface:IOServerRemove a consumer of received messages- Specified by:
removeMessageConsumerin interfaceIOServer<T,U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
removeAllMessageConsumers
public void removeAllMessageConsumers()Description copied from interface:IOServerRemove every consumer of received messages- Specified by:
removeAllMessageConsumersin 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:IOServerAdd a consumer of server connection status changes- Specified by:
addConnectionStatusConsumerin 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:IOServerRemove a consumer of server connection status changes- Specified by:
removeConnectionStatusConsumerin 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:IOServerAdd a consumer of client connection status changes- Specified by:
addConnectionStatusConsumerin 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:IOServerRemove a consumer of client connection status changes- Specified by:
removeConnectionStatusConsumerin interfaceIOServer<T,U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
removeAllConnectionStatusConsumers
public void removeAllConnectionStatusConsumers()Description copied from interface:IOServerRemove every consumer of connection status- Specified by:
removeAllConnectionStatusConsumersin 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:IOServerGet current connection status of the server- Specified by:
getConnectionStatusin interfaceIOServer<T,U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
getConnectionStatus
Description copied from interface:IOServerGet current connection status of a client (eitherConnectionStatus.CONNECTEDorConnectionStatus.DISCONNECTED)- Specified by:
getConnectionStatusin interfaceIOServer<T,U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
disconnectClient
Description copied from interface:IOServerForcibly close the connection to a client- Specified by:
disconnectClientin 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:IOServerSend a message to a client- Specified by:
sendMessagein interfaceIOServer<T,U extends io.netty.channel.Channel, V extends io.netty.bootstrap.AbstractBootstrap<?, ?>>
-
sendMessage
Description copied from interface:IOServerSend a message to all clients- Specified by:
sendMessagein 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 speficied client for use in log files etc. -
addDecoders
-
addEncoders
-
addDecoder
-
addEncoder
-