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
FieldsModifier and TypeFieldDescriptionstatic final intOption flag to use direct (off-heap) buffers for data transfer.protected static final StringManagerString manager for localized messages in this package.Fields inherited from interface ChannelReceiver
MAX_UDP_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbind(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 intbindUdp(DatagramSocket socket, int portstart, int retries) Same as bind() except it does it for the UDP portbooleandoListen()Returns whether the receiver is in listen mode.intReturn the current number of threads that are in use.Returns the bind address as a string.intReturns the number of attempts to find an available port for auto-binding.getBind()Returns the bind address.Return the channel that is related to this ChannelReceiverlongReturn the total number of tasks that have completed execution by the pool.booleanReturns whether direct (off-heap) buffers are used.Returns the executor service used by this receiver.getHost()Returns the host address for this receiver.Returns the message listener for this receiver.longReturns the maximum idle time for threads in the executor pool.intReturns the maximum number of tasks in the pool.intReturns the maximum number of threads in the executor pool.Returns the message listener for this receiver.intReturns the minimum number of tasks in the pool.intReturns the minimum number of threads in the executor pool.booleanReturns whether OOBINLINE (out-of-band data) is enabled.intReturn the current number of threads that are managed by the pool.intgetPort()Returns the port on which this receiver is listening.intReturns the size of the receive buffer for TCP connections.intReturns the secure port number.longReturns the TCP selector timeout in milliseconds.booleanReturns whether SO_KEEPALIVE is enabled.booleanReturns whether SO_LINGER is enabled.intReturns the SO_LINGER timeout value in seconds.booleanReturns whether SO_REUSEADDR is enabled.intReturns the IP traffic class (TOS) value for sockets.longReturn the total number of tasks that have ever been scheduled for execution by the pool.Returns the task pool used by this receiver.booleanReturns whether TCP_NODELAY is enabled.intReturns the socket timeout in milliseconds.intReturns the size of the transmit buffer for TCP connections.intReturns the UDP port number.intReturns the size of the receive buffer for UDP connections.intReturns the size of the transmit buffer for UDP connections.booleanReturns whether a buffer pool is used for message handling.intReturns the options flags for worker threads.voidPerforms a heartbeat operation.booleanisDaemon()Returns whether the worker threads are daemon threads.booleanReturns whether the receiver is currently listening for connections.voidReceives a channel message and forwards it to the listener if the listener accepts it.voidsetAddress(String host) Sets the bind address for this receiver.voidsetAutoBind(int autoBind) Sets the number of attempts to find an available port for auto-binding.voidsetBind(InetAddress bind) Sets the bind address.voidsetChannel(Channel channel) Set the channel that is related to this ChannelReceivervoidsetDaemon(boolean daemon) Sets whether the worker threads should be daemon threads.voidsetDirect(boolean direct) Sets whether direct (off-heap) buffers should be used.voidsetExecutor(ExecutorService executor) Sets the executor service for this receiver.voidSets the host address for this receiver.voidsetListen(boolean doListen) Sets whether the receiver should listen for incoming connections.voidsetListener(MessageListener listener) Sets the message listener for this receiver.voidsetMaxIdleTime(long maxIdleTime) Sets the maximum idle time for threads in the executor pool.voidsetMaxTasks(int maxTasks) Sets the maximum number of tasks in the pool.voidsetMaxThreads(int maxThreads) Sets the maximum number of threads in the executor pool.voidsetMessageListener(MessageListener listener) Sets the message listener for this receiver.voidsetMinTasks(int minTasks) Sets the minimum number of tasks in the pool.voidsetMinThreads(int minThreads) Sets the minimum number of threads in the executor pool.voidsetOoBInline(boolean ooBInline) Sets whether OOBINLINE (out-of-band data) should be enabled.voidsetPool(RxTaskPool pool) Sets the task pool for this receiver.voidsetPort(int port) Sets the port on which this receiver listens.voidsetRxBufSize(int rxBufSize) Sets the size of the receive buffer for TCP connections.voidsetSecurePort(int securePort) Sets the secure port number.voidsetSelectorTimeout(long selTimeout) Sets the TCP selector timeout in milliseconds.voidsetSoKeepAlive(boolean soKeepAlive) Sets whether SO_KEEPALIVE should be enabled.voidsetSoLingerOn(boolean soLingerOn) Sets whether SO_LINGER should be enabled.voidsetSoLingerTime(int soLingerTime) Sets the SO_LINGER timeout value in seconds.voidsetSoReuseAddress(boolean soReuseAddress) Sets whether SO_REUSEADDR should be enabled.voidsetSoTrafficClass(int soTrafficClass) Sets the IP traffic class (TOS) value for sockets.voidsetTcpNoDelay(boolean tcpNoDelay) Sets whether TCP_NODELAY should be enabled.voidsetTimeout(int timeout) Sets the socket timeout in milliseconds.voidsetTxBufSize(int txBufSize) Sets the size of the transmit buffer for TCP connections.voidsetUdpPort(int udpPort) Sets the UDP port number.voidsetUdpRxBufSize(int udpRxBufSize) Sets the size of the receive buffer for UDP connections.voidsetUdpTxBufSize(int udpTxBufSize) Sets the size of the transmit buffer for UDP connections.voidsetUseBufferPool(boolean useBufferPool) Sets whether a buffer pool should be used for message handling.voidstart()Starts the receiver by creating the executor service and registering with JMX.voidstop()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, waitMethods inherited from interface RxTaskPool.TaskCreator
createRxTask
-
Field Details
-
OPTION_DIRECT_BUFFER
public static final int OPTION_DIRECT_BUFFEROption flag to use direct (off-heap) buffers for data transfer.- See Also:
-
sm
String manager for localized messages in this package.
-
-
Constructor Details
-
ReceiverBase
public ReceiverBase()Default constructor for ReceiverBase.
-
-
Method Details
-
start
Starts the receiver by creating the executor service and registering with JMX.- Specified by:
startin interfaceChannelReceiver- 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:
stopin interfaceChannelReceiver
-
getMessageListener
Returns the message listener for this receiver.- Specified by:
getMessageListenerin interfaceChannelReceiver- Returns:
- the message listener
- See Also:
-
getPort
public int getPort()Returns the port on which this receiver is listening.- Specified by:
getPortin interfaceChannelReceiver- 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
-
setMessageListener
Sets the message listener for this receiver.- Specified by:
setMessageListenerin interfaceChannelReceiver- Parameters:
listener- the message listener to set- See Also:
-
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
-
bind
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 togetBind().- Parameters:
socket- The socket to bindportstart- Starting port for bind attemptsretries- Number of times to attempt to bind (port incremented between attempts)- Throws:
IOException- Socket bind error
-
bindUdp
Same as bind() except it does it for the UDP port- Parameters:
socket- The socket to bindportstart- Starting port for bind attemptsretries- Number of times to attempt to bind (port incremented between attempts)- Returns:
- int The retry count
- Throws:
IOException- Socket bind error
-
messageDataReceived
Receives a channel message and forwards it to the listener if the listener accepts it.- Specified by:
messageDataReceivedin interfaceListenCallback- Parameters:
data- the channel message received
-
getWorkerThreadOptions
public int getWorkerThreadOptions()Returns the options flags for worker threads.- Returns:
- the worker thread options
-
setBind
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
-
getHost
Returns the host address for this receiver.- Specified by:
getHostin interfaceChannelReceiver- 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
Returns the message listener for this receiver.- Returns:
- the message listener
-
getTaskPool
-
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:
getSecurePortin interfaceChannelReceiver- 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
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
Sets the bind address for this receiver.- Parameters:
host- the host address to bind to
-
setHost
Sets the host address for this receiver.- Parameters:
host- the host address to set
-
setListener
Sets the message listener for this receiver.- Parameters:
listener- the message listener to set
-
setPool
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
Sets the executor service for this receiver.- Parameters:
executor- the executor service to set
-
heartbeat
-
getUdpPort
public int getUdpPort()Returns the UDP port number.- Specified by:
getUdpPortin interfaceChannelReceiver- 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
Description copied from interface:ChannelReceiverReturn the channel that is related to this ChannelReceiver- Specified by:
getChannelin interfaceChannelReceiver- Returns:
- Channel
-
setChannel
Description copied from interface:ChannelReceiverSet the channel that is related to this ChannelReceiver- Specified by:
setChannelin interfaceChannelReceiver- 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
-