Class ReceiverBase

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int OPTION_DIRECT_BUFFER
      Option flag to use direct (off-heap) buffers for data transfer.
      protected static StringManager sm
      String manager for localized messages in this package.
    • Constructor Summary

      Constructors 
      Constructor Description
      ReceiverBase()
      Default constructor for ReceiverBase.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void bind​(java.net.ServerSocket socket, int portstart, int retries)
      Attempts to bind using the provided port and if that fails attempts to bind to each of the ports from portstart to (portstart + retries -1) until either there are no more ports or the bind is successful.
      protected int bindUdp​(java.net.DatagramSocket socket, int portstart, int retries)
      Same as bind() except it does it for the UDP port
      boolean doListen()
      Returns whether the receiver is in listen mode.
      int getActiveCount()
      Return the current number of threads that are in use.
      java.lang.String getAddress()
      Returns the bind address as a string.
      int getAutoBind()
      Returns the number of attempts to find an available port for auto-binding.
      java.net.InetAddress getBind()
      Returns the bind address.
      Channel getChannel()
      Return the channel that is related to this ChannelReceiver
      long getCompletedTaskCount()
      Return the total number of tasks that have completed execution by the pool.
      boolean getDirect()
      Returns whether direct (off-heap) buffers are used.
      java.util.concurrent.ExecutorService getExecutor()
      Returns the executor service used by this receiver.
      java.lang.String getHost()
      Returns the host address for this receiver.
      MessageListener getListener()
      Returns the message listener for this receiver.
      long getMaxIdleTime()
      Returns the maximum idle time for threads in the executor pool.
      int getMaxTasks()
      Returns the maximum number of tasks in the pool.
      int getMaxThreads()
      Returns the maximum number of threads in the executor pool.
      MessageListener getMessageListener()
      Returns the message listener for this receiver.
      int getMinTasks()
      Returns the minimum number of tasks in the pool.
      int getMinThreads()
      Returns the minimum number of threads in the executor pool.
      boolean getOoBInline()
      Returns whether OOBINLINE (out-of-band data) is enabled.
      int getPoolSize()
      Return the current number of threads that are managed by the pool.
      int getPort()
      Returns the port on which this receiver is listening.
      int getRxBufSize()
      Returns the size of the receive buffer for TCP connections.
      int getSecurePort()
      Returns the secure port number.
      long getSelectorTimeout()
      Returns the TCP selector timeout in milliseconds.
      boolean getSoKeepAlive()
      Returns whether SO_KEEPALIVE is enabled.
      boolean getSoLingerOn()
      Returns whether SO_LINGER is enabled.
      int getSoLingerTime()
      Returns the SO_LINGER timeout value in seconds.
      boolean getSoReuseAddress()
      Returns whether SO_REUSEADDR is enabled.
      int getSoTrafficClass()
      Returns the IP traffic class (TOS) value for sockets.
      long getTaskCount()
      Return the total number of tasks that have ever been scheduled for execution by the pool.
      RxTaskPool getTaskPool()
      Returns the task pool used by this receiver.
      boolean getTcpNoDelay()
      Returns whether TCP_NODELAY is enabled.
      int getTimeout()
      Returns the socket timeout in milliseconds.
      int getTxBufSize()
      Returns the size of the transmit buffer for TCP connections.
      int getUdpPort()
      Returns the UDP port number.
      int getUdpRxBufSize()
      Returns the size of the receive buffer for UDP connections.
      int getUdpTxBufSize()
      Returns the size of the transmit buffer for UDP connections.
      boolean getUseBufferPool()
      Returns whether a buffer pool is used for message handling.
      int getWorkerThreadOptions()
      Returns the options flags for worker threads.
      void heartbeat()
      Performs a heartbeat operation.
      boolean isDaemon()
      Returns whether the worker threads are daemon threads.
      boolean isListening()
      Returns whether the receiver is currently listening for connections.
      void messageDataReceived​(ChannelMessage data)
      Receives a channel message and forwards it to the listener if the listener accepts it.
      void setAddress​(java.lang.String host)
      Sets the bind address for this receiver.
      void setAutoBind​(int autoBind)
      Sets the number of attempts to find an available port for auto-binding.
      void setBind​(java.net.InetAddress bind)
      Sets the bind address.
      void setChannel​(Channel channel)
      Set the channel that is related to this ChannelReceiver
      void setDaemon​(boolean daemon)
      Sets whether the worker threads should be daemon threads.
      void setDirect​(boolean direct)
      Sets whether direct (off-heap) buffers should be used.
      void setExecutor​(java.util.concurrent.ExecutorService executor)
      Sets the executor service for this receiver.
      void setHost​(java.lang.String host)
      Sets the host address for this receiver.
      void setListen​(boolean doListen)
      Sets whether the receiver should listen for incoming connections.
      void setListener​(MessageListener listener)
      Sets the message listener for this receiver.
      void setMaxIdleTime​(long maxIdleTime)
      Sets the maximum idle time for threads in the executor pool.
      void setMaxTasks​(int maxTasks)
      Sets the maximum number of tasks in the pool.
      void setMaxThreads​(int maxThreads)
      Sets the maximum number of threads in the executor pool.
      void setMessageListener​(MessageListener listener)
      Sets the message listener for this receiver.
      void setMinTasks​(int minTasks)
      Sets the minimum number of tasks in the pool.
      void setMinThreads​(int minThreads)
      Sets the minimum number of threads in the executor pool.
      void setOoBInline​(boolean ooBInline)
      Sets whether OOBINLINE (out-of-band data) should be enabled.
      void setPool​(RxTaskPool pool)
      Sets the task pool for this receiver.
      void setPort​(int port)
      Sets the port on which this receiver listens.
      void setRxBufSize​(int rxBufSize)
      Sets the size of the receive buffer for TCP connections.
      void setSecurePort​(int securePort)
      Sets the secure port number.
      void setSelectorTimeout​(long selTimeout)
      Sets the TCP selector timeout in milliseconds.
      void setSoKeepAlive​(boolean soKeepAlive)
      Sets whether SO_KEEPALIVE should be enabled.
      void setSoLingerOn​(boolean soLingerOn)
      Sets whether SO_LINGER should be enabled.
      void setSoLingerTime​(int soLingerTime)
      Sets the SO_LINGER timeout value in seconds.
      void setSoReuseAddress​(boolean soReuseAddress)
      Sets whether SO_REUSEADDR should be enabled.
      void setSoTrafficClass​(int soTrafficClass)
      Sets the IP traffic class (TOS) value for sockets.
      void setTcpNoDelay​(boolean tcpNoDelay)
      Sets whether TCP_NODELAY should be enabled.
      void setTimeout​(int timeout)
      Sets the socket timeout in milliseconds.
      void setTxBufSize​(int txBufSize)
      Sets the size of the transmit buffer for TCP connections.
      void setUdpPort​(int udpPort)
      Sets the UDP port number.
      void setUdpRxBufSize​(int udpRxBufSize)
      Sets the size of the receive buffer for UDP connections.
      void setUdpTxBufSize​(int udpTxBufSize)
      Sets the size of the transmit buffer for UDP connections.
      void setUseBufferPool​(boolean useBufferPool)
      Sets whether a buffer pool should be used for message handling.
      void start()
      Starts the receiver by creating the executor service and registering with JMX.
      void stop()
      Stops the receiver by shutting down the executor and unregistering from JMX.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • OPTION_DIRECT_BUFFER

        public static final int OPTION_DIRECT_BUFFER
        Option flag to use direct (off-heap) buffers for data transfer.
        See Also:
        Constant Field Values
      • sm

        protected static final StringManager sm
        String manager for localized messages in this package.
    • Constructor Detail

      • ReceiverBase

        public ReceiverBase()
        Default constructor for ReceiverBase.
    • Method Detail

      • start

        public void start()
                   throws java.io.IOException
        Starts the receiver by creating the executor service and registering with JMX.
        Specified by:
        start in interface ChannelReceiver
        Throws:
        java.io.IOException - if an I/O error occurs during startup
      • stop

        public void stop()
        Stops the receiver by shutting down the executor and unregistering from JMX.
        Specified by:
        stop in interface ChannelReceiver
      • getPort

        public int getPort()
        Returns the port on which this receiver is listening.
        Specified by:
        getPort in interface ChannelReceiver
        Returns:
        the port number
      • getRxBufSize

        public int getRxBufSize()
        Returns the size of the receive buffer for TCP connections.
        Returns:
        the receive buffer size
      • getTxBufSize

        public int getTxBufSize()
        Returns the size of the transmit buffer for TCP connections.
        Returns:
        the transmit buffer size
      • setRxBufSize

        public void setRxBufSize​(int rxBufSize)
        Sets the size of the receive buffer for TCP connections.
        Parameters:
        rxBufSize - the receive buffer size to set
      • setTxBufSize

        public void setTxBufSize​(int txBufSize)
        Sets the size of the transmit buffer for TCP connections.
        Parameters:
        txBufSize - the transmit buffer size to set
      • getBind

        public java.net.InetAddress getBind()
        Returns the bind address.
        Returns:
        the bind address
      • bind

        protected void bind​(java.net.ServerSocket socket,
                            int portstart,
                            int retries)
                     throws java.io.IOException
        Attempts to bind using the provided port and if that fails attempts to bind to each of the ports from portstart to (portstart + retries -1) until either there are no more ports or the bind is successful. The address to bind to is obtained via a call to getBind().
        Parameters:
        socket - The socket to bind
        portstart - Starting port for bind attempts
        retries - Number of times to attempt to bind (port incremented between attempts)
        Throws:
        java.io.IOException - Socket bind error
      • bindUdp

        protected int bindUdp​(java.net.DatagramSocket socket,
                              int portstart,
                              int retries)
                       throws java.io.IOException
        Same as bind() except it does it for the UDP port
        Parameters:
        socket - The socket to bind
        portstart - Starting port for bind attempts
        retries - Number of times to attempt to bind (port incremented between attempts)
        Returns:
        int The retry count
        Throws:
        java.io.IOException - Socket bind error
      • messageDataReceived

        public void messageDataReceived​(ChannelMessage data)
        Receives a channel message and forwards it to the listener if the listener accepts it.
        Specified by:
        messageDataReceived in interface ListenCallback
        Parameters:
        data - the channel message received
      • getWorkerThreadOptions

        public int getWorkerThreadOptions()
        Returns the options flags for worker threads.
        Returns:
        the worker thread options
      • setBind

        public void setBind​(java.net.InetAddress bind)
        Sets the bind address.
        Parameters:
        bind - the bind address to set
      • getDirect

        public boolean getDirect()
        Returns whether direct (off-heap) buffers are used.
        Returns:
        true if direct buffers are used
      • setDirect

        public void setDirect​(boolean direct)
        Sets whether direct (off-heap) buffers should be used.
        Parameters:
        direct - true to use direct buffers
      • getAddress

        public java.lang.String getAddress()
        Returns the bind address as a string.
        Returns:
        the bind address
      • getHost

        public java.lang.String getHost()
        Returns the host address for this receiver.
        Specified by:
        getHost in interface ChannelReceiver
        Returns:
        the host address
      • getSelectorTimeout

        public long getSelectorTimeout()
        Returns the TCP selector timeout in milliseconds.
        Returns:
        the selector timeout
      • doListen

        public boolean doListen()
        Returns whether the receiver is in listen mode.
        Returns:
        true if the receiver is listening
      • getListener

        public MessageListener getListener()
        Returns the message listener for this receiver.
        Returns:
        the message listener
      • getTaskPool

        public RxTaskPool getTaskPool()
        Returns the task pool used by this receiver.
        Returns:
        the task pool
      • getAutoBind

        public int getAutoBind()
        Returns the number of attempts to find an available port for auto-binding.
        Returns:
        the auto-bind retry count
      • getMaxThreads

        public int getMaxThreads()
        Returns the maximum number of threads in the executor pool.
        Returns:
        the maximum thread count
      • getMinThreads

        public int getMinThreads()
        Returns the minimum number of threads in the executor pool.
        Returns:
        the minimum thread count
      • getTcpNoDelay

        public boolean getTcpNoDelay()
        Returns whether TCP_NODELAY is enabled.
        Returns:
        true if TCP_NODELAY is enabled
      • getSoKeepAlive

        public boolean getSoKeepAlive()
        Returns whether SO_KEEPALIVE is enabled.
        Returns:
        true if SO_KEEPALIVE is enabled
      • getOoBInline

        public boolean getOoBInline()
        Returns whether OOBINLINE (out-of-band data) is enabled.
        Returns:
        true if OOBINLINE is enabled
      • getSoLingerOn

        public boolean getSoLingerOn()
        Returns whether SO_LINGER is enabled.
        Returns:
        true if SO_LINGER is enabled
      • getSoLingerTime

        public int getSoLingerTime()
        Returns the SO_LINGER timeout value in seconds.
        Returns:
        the SO_LINGER timeout
      • getSoReuseAddress

        public boolean getSoReuseAddress()
        Returns whether SO_REUSEADDR is enabled.
        Returns:
        true if SO_REUSEADDR is enabled
      • getSoTrafficClass

        public int getSoTrafficClass()
        Returns the IP traffic class (TOS) value for sockets.
        Returns:
        the traffic class value
      • getTimeout

        public int getTimeout()
        Returns the socket timeout in milliseconds.
        Returns:
        the socket timeout
      • getUseBufferPool

        public boolean getUseBufferPool()
        Returns whether a buffer pool is used for message handling.
        Returns:
        true if a buffer pool is used
      • getSecurePort

        public int getSecurePort()
        Returns the secure port number.
        Specified by:
        getSecurePort in interface ChannelReceiver
        Returns:
        the secure port number, or -1 if not configured
      • getMinTasks

        public int getMinTasks()
        Returns the minimum number of tasks in the pool.
        Returns:
        the minimum task count
      • getMaxTasks

        public int getMaxTasks()
        Returns the maximum number of tasks in the pool.
        Returns:
        the maximum task count
      • getExecutor

        public java.util.concurrent.ExecutorService getExecutor()
        Returns the executor service used by this receiver.
        Returns:
        the executor service
      • isListening

        public boolean isListening()
        Returns whether the receiver is currently listening for connections.
        Returns:
        true if the receiver is listening
      • setSelectorTimeout

        public void setSelectorTimeout​(long selTimeout)
        Sets the TCP selector timeout in milliseconds.
        Parameters:
        selTimeout - the selector timeout in milliseconds
      • setListen

        public void setListen​(boolean doListen)
        Sets whether the receiver should listen for incoming connections.
        Parameters:
        doListen - true to enable listening
      • setAddress

        public void setAddress​(java.lang.String host)
        Sets the bind address for this receiver.
        Parameters:
        host - the host address to bind to
      • setHost

        public void setHost​(java.lang.String host)
        Sets the host address for this receiver.
        Parameters:
        host - the host address to set
      • setListener

        public void setListener​(MessageListener listener)
        Sets the message listener for this receiver.
        Parameters:
        listener - the message listener to set
      • setPool

        public void setPool​(RxTaskPool pool)
        Sets the task pool for this receiver.
        Parameters:
        pool - the task pool to set
      • setPort

        public void setPort​(int port)
        Sets the port on which this receiver listens.
        Parameters:
        port - the port number to set
      • setAutoBind

        public void setAutoBind​(int autoBind)
        Sets the number of attempts to find an available port for auto-binding.
        Parameters:
        autoBind - the number of retry attempts
      • setMaxThreads

        public void setMaxThreads​(int maxThreads)
        Sets the maximum number of threads in the executor pool.
        Parameters:
        maxThreads - the maximum thread count
      • setMinThreads

        public void setMinThreads​(int minThreads)
        Sets the minimum number of threads in the executor pool.
        Parameters:
        minThreads - the minimum thread count
      • setTcpNoDelay

        public void setTcpNoDelay​(boolean tcpNoDelay)
        Sets whether TCP_NODELAY should be enabled.
        Parameters:
        tcpNoDelay - true to enable TCP_NODELAY
      • setSoKeepAlive

        public void setSoKeepAlive​(boolean soKeepAlive)
        Sets whether SO_KEEPALIVE should be enabled.
        Parameters:
        soKeepAlive - true to enable SO_KEEPALIVE
      • setOoBInline

        public void setOoBInline​(boolean ooBInline)
        Sets whether OOBINLINE (out-of-band data) should be enabled.
        Parameters:
        ooBInline - true to enable OOBINLINE
      • setSoLingerOn

        public void setSoLingerOn​(boolean soLingerOn)
        Sets whether SO_LINGER should be enabled.
        Parameters:
        soLingerOn - true to enable SO_LINGER
      • setSoLingerTime

        public void setSoLingerTime​(int soLingerTime)
        Sets the SO_LINGER timeout value in seconds.
        Parameters:
        soLingerTime - the SO_LINGER timeout in seconds
      • setSoReuseAddress

        public void setSoReuseAddress​(boolean soReuseAddress)
        Sets whether SO_REUSEADDR should be enabled.
        Parameters:
        soReuseAddress - true to enable SO_REUSEADDR
      • setSoTrafficClass

        public void setSoTrafficClass​(int soTrafficClass)
        Sets the IP traffic class (TOS) value for sockets.
        Parameters:
        soTrafficClass - the traffic class value
      • setTimeout

        public void setTimeout​(int timeout)
        Sets the socket timeout in milliseconds.
        Parameters:
        timeout - the socket timeout in milliseconds
      • setUseBufferPool

        public void setUseBufferPool​(boolean useBufferPool)
        Sets whether a buffer pool should be used for message handling.
        Parameters:
        useBufferPool - true to use a buffer pool
      • setSecurePort

        public void setSecurePort​(int securePort)
        Sets the secure port number.
        Parameters:
        securePort - the secure port number
      • setMinTasks

        public void setMinTasks​(int minTasks)
        Sets the minimum number of tasks in the pool.
        Parameters:
        minTasks - the minimum task count
      • setMaxTasks

        public void setMaxTasks​(int maxTasks)
        Sets the maximum number of tasks in the pool.
        Parameters:
        maxTasks - the maximum task count
      • setExecutor

        public void setExecutor​(java.util.concurrent.ExecutorService executor)
        Sets the executor service for this receiver.
        Parameters:
        executor - the executor service to set
      • heartbeat

        public void heartbeat()
        Performs a heartbeat operation. No-op in this base implementation.
        Specified by:
        heartbeat in interface Heartbeat
      • getUdpPort

        public int getUdpPort()
        Returns the UDP port number.
        Specified by:
        getUdpPort in interface ChannelReceiver
        Returns:
        the UDP port number, or -1 if not configured
      • setUdpPort

        public void setUdpPort​(int udpPort)
        Sets the UDP port number.
        Parameters:
        udpPort - the UDP port number
      • getUdpRxBufSize

        public int getUdpRxBufSize()
        Returns the size of the receive buffer for UDP connections.
        Returns:
        the UDP receive buffer size
      • setUdpRxBufSize

        public void setUdpRxBufSize​(int udpRxBufSize)
        Sets the size of the receive buffer for UDP connections.
        Parameters:
        udpRxBufSize - the UDP receive buffer size
      • getUdpTxBufSize

        public int getUdpTxBufSize()
        Returns the size of the transmit buffer for UDP connections.
        Returns:
        the UDP transmit buffer size
      • setUdpTxBufSize

        public void setUdpTxBufSize​(int udpTxBufSize)
        Sets the size of the transmit buffer for UDP connections.
        Parameters:
        udpTxBufSize - the UDP transmit buffer size
      • setChannel

        public void setChannel​(Channel channel)
        Description copied from interface: ChannelReceiver
        Set the channel that is related to this ChannelReceiver
        Specified by:
        setChannel in interface ChannelReceiver
        Parameters:
        channel - The channel
      • getPoolSize

        public int getPoolSize()
        Return the current number of threads that are managed by the pool.
        Returns:
        the current number of threads that are managed by the pool
      • getActiveCount

        public int getActiveCount()
        Return the current number of threads that are in use.
        Returns:
        the current number of threads that are in use
      • getTaskCount

        public long getTaskCount()
        Return the total number of tasks that have ever been scheduled for execution by the pool.
        Returns:
        the total number of tasks that have ever been scheduled for execution by the pool
      • getCompletedTaskCount

        public long getCompletedTaskCount()
        Return the total number of tasks that have completed execution by the pool.
        Returns:
        the total number of tasks that have completed execution by the pool
      • isDaemon

        public boolean isDaemon()
        Returns whether the worker threads are daemon threads.
        Returns:
        true if worker threads are daemon threads
      • getMaxIdleTime

        public long getMaxIdleTime()
        Returns the maximum idle time for threads in the executor pool.
        Returns:
        the maximum idle time in milliseconds
      • setDaemon

        public void setDaemon​(boolean daemon)
        Sets whether the worker threads should be daemon threads.
        Parameters:
        daemon - true to use daemon threads
      • setMaxIdleTime

        public void setMaxIdleTime​(long maxIdleTime)
        Sets the maximum idle time for threads in the executor pool.
        Parameters:
        maxIdleTime - the maximum idle time in milliseconds