# Class ReceiverBase

java.lang.Object
org.apache.catalina.tribes.transport.ReceiverBase

All Implemented Interfaces:
  `ChannelReceiver, Heartbeat, ListenCallback, RxTaskPool.TaskCreator`

Direct Known Subclasses:
  `NioReceiver`

public abstract class ReceiverBase extends Object implements ChannelReceiver, ListenCallback, RxTaskPool.TaskCreator
Base implementation of a channel receiver that handles TCP connections and provides configuration for socket options, thread pools, and message handling.

- ## Field Summary

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

  ### Fields inherited from interface ChannelReceiver

  `MAX_UDP_SIZE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ReceiverBase()`
  Default constructor for ReceiverBase.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `bind(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(DatagramSocket socket, int portstart, int retries)`
  Same as bind() except it does it for the UDP port
  `boolean`
  `doListen()`
  Deprecated.
  `int`
  `getActiveCount()`
  Return the current number of threads that are in use.
  `String`
  `getAddress()`
  Returns the bind address as a string.
  `int`
  `getAutoBind()`
  Returns the number of attempts to find an available port for auto-binding.
  `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.
  `ExecutorService`
  `getExecutor()`
  Returns the executor service used by this receiver.
  `String`
  `getHost()`
  String representation of the IPv4 or IPv6 address that this host is listening to.
  `MessageListener`
  `getListener()`
  Deprecated.
  `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 that is associated with 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 listening port
  `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(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(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(ExecutorService executor)`
  Sets the executor service for this receiver.
  `void`
  `setHost(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)`
  Deprecated.
  `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 to receive notification of incoming messages.
  `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 Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface RxTaskPool.TaskCreator

  `createRxTask`

- ## Field Details

  - ### 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 Details

  - ### ReceiverBase

    public ReceiverBase()
    Default constructor for ReceiverBase.

- ## Method Details

  - ### start

    public void start() throws IOException
    Starts the receiver by creating the executor service and registering with JMX.
    Specified by:
      `start` in interface `ChannelReceiver`
    Throws:
      `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`

  - ### getMessageListener

    public MessageListener getMessageListener()
    Description copied from interface: `ChannelReceiver`
    Returns the message listener that is associated with this receiver
    Specified by:
      `getMessageListener` in interface `ChannelReceiver`
    Returns:
      MessageListener
    See Also:
      - `MessageListener`

  - ### getPort

    public int getPort()
    Description copied from interface: `ChannelReceiver`
    Returns the listening port
    Specified by:
      `getPort` in interface `ChannelReceiver`
    Returns:
      port

  - ### 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

  - ### setMessageListener

    public void setMessageListener(MessageListener listener)
    Description copied from interface: `ChannelReceiver`
    Sets the message listener to receive notification of incoming messages.
    Specified by:
      `setMessageListener` in interface `ChannelReceiver`
    Parameters:
      `listener` - MessageListener

  - ### 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 InetAddress getBind()
    Returns the bind address.
    Returns:
      the bind address

  - ### bind

    protected void bind(ServerSocket socket, int portstart, int retries) throws 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:
      `IOException` - Socket bind error

  - ### bindUdp

    protected int bindUdp(DatagramSocket socket, int portstart, int retries) throws 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:
      `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(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 String getAddress()
    Returns the bind address as a string.
    Returns:
      the bind address

  - ### getHost

    public String getHost()
    Description copied from interface: `ChannelReceiver`
    String representation of the IPv4 or IPv6 address that this host is listening to.
    Specified by:
      `getHost` in interface `ChannelReceiver`
    Returns:
      the host that this receiver is listening to

  - ### getSelectorTimeout

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

  - ### doListen

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

  - ### getListener

    @Deprecated public MessageListener getListener()
    Deprecated.
    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 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(String host)
    Sets the bind address for this receiver.
    Parameters:
      `host` - the host address to bind to

  - ### setHost

    public void setHost(String host)
    Sets the host address for this receiver.
    Parameters:
      `host` - the host address to set

  - ### setListener

    @Deprecated public void setListener(MessageListener listener)
    Deprecated.
    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(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

  - ### getChannel

    public Channel getChannel()
    Description copied from interface: `ChannelReceiver`
    Return the channel that is related to this ChannelReceiver
    Specified by:
      `getChannel` in interface `ChannelReceiver`
    Returns:
      Channel

  - ### 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