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.
  • 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

      protected static final Logger LOG
    • executorService

      protected final ExecutorService executorService
    • scheduledExecutorService

      protected final ScheduledExecutorService scheduledExecutorService
    • clientLimit

      protected int clientLimit
    • bootstrap

      protected V extends io.netty.bootstrap.AbstractBootstrap<?,?> 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

      protected U extends io.netty.channel.Channel channel
    • allChannels

      protected final io.netty.channel.group.ChannelGroup allChannels
    • messageConsumers

      protected final List<IOServer.IoServerMessageConsumer<T,U extends io.netty.channel.Channel,W extends SocketAddress>> messageConsumers
    • connectionStatusConsumers

      protected final List<Consumer<org.openremote.model.asset.agent.ConnectionStatus>> connectionStatusConsumers
    • clientConnectionStatusConsumers

      protected final List<BiConsumer<U extends io.netty.channel.Channel,org.openremote.model.asset.agent.ConnectionStatus>> clientConnectionStatusConsumers
    • reconnectTask

      protected ScheduledFuture<?> reconnectTask
    • reconnectDelayMilliseconds

      protected int reconnectDelayMilliseconds
  • Constructor Details

    • AbstractNettyIOServer

      public AbstractNettyIOServer()
  • Method Details

    • start

      public void start()
      Description copied from interface: IOServer
      Start the server
      Specified by:
      start in interface IOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>>
    • stop

      public void stop()
      Description copied from interface: IOServer
      Stop the server
      Specified by:
      stop in interface IOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>>
    • addMessageConsumer

      public void addMessageConsumer(IOServer.IoServerMessageConsumer<T,U,W> messageConsumer)
      Description copied from interface: IOServer
      Add a consumer of received messages
      Specified by:
      addMessageConsumer in interface IOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>>
    • removeMessageConsumer

      public void removeMessageConsumer(IOServer.IoServerMessageConsumer<T,U,W> messageConsumer)
      Description copied from interface: IOServer
      Remove a consumer of received messages
      Specified by:
      removeMessageConsumer in interface IOServer<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 interface IOServer<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 interface IOServer<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 interface IOServer<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 interface IOServer<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 interface IOServer<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 interface IOServer<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 interface IOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>>
    • getConnectionStatus

      public org.openremote.model.asset.agent.ConnectionStatus getConnectionStatus(U client)
      Description copied from interface: IOServer
      Get current connection status of a client (either ConnectionStatus.CONNECTED or ConnectionStatus.DISCONNECTED)
      Specified by:
      getConnectionStatus in interface IOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>>
    • disconnectClient

      public void disconnectClient(U client)
      Description copied from interface: IOServer
      Forcibly close the connection to a client
      Specified by:
      disconnectClient in interface IOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>>
    • initChannel

      protected void initChannel(U channel)
    • initClientChannel

      protected void initClientChannel(U channel)
      Initialise the specified client channel (will be called when a new client connection is made)
    • handleMessageReceived

      protected void handleMessageReceived(U channel, T message)
    • onClientDisconnected

      protected void onClientDisconnected(U client)
    • onClientConnected

      protected void onClientConnected(U client)
    • 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

      protected void onMessageReceived(T message, U channel, W sender)
    • onDecodeException

      protected void onDecodeException(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
    • onEncodeException

      protected void onEncodeException(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
    • sendMessage

      public void sendMessage(T message, U client)
      Description copied from interface: IOServer
      Send a message to a client
      Specified by:
      sendMessage in interface IOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>>
    • sendMessage

      public void sendMessage(T message)
      Description copied from interface: IOServer
      Send a message to all clients
      Specified by:
      sendMessage in interface IOServer<T,U extends io.netty.channel.Channel,V extends io.netty.bootstrap.AbstractBootstrap<?,?>>
    • sendMessage

      public void 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. UDP where only a single channel exists)
    • scheduleReconnect

      protected void scheduleReconnect()
    • getSocketAddressString

      protected abstract String getSocketAddressString()
      Get a string identifier that uniquely identifies the current instance of this server. e.g. tcp://IP:PORT
    • createAndConfigureBootstrap

      protected abstract V createAndConfigureBootstrap()
      Create and configure the bootstrap to use for this instance
    • getClientDescriptor

      protected abstract String getClientDescriptor(U client)
      Should return a descriptor to identify the specified client for use in log files etc.
    • addDecoders

      protected abstract void addDecoders(U channel)
    • addEncoders

      protected abstract void addEncoders(U channel)
    • addDecoder

      protected void addDecoder(U channel, io.netty.channel.ChannelInboundHandler decoder)
    • addEncoder

      protected void addEncoder(U channel, io.netty.channel.ChannelOutboundHandler encoder)