Class NioSender
java.lang.Object
org.apache.catalina.tribes.transport.AbstractSender
org.apache.catalina.tribes.transport.nio.NioSender
- All Implemented Interfaces:
DataSender
This class is NOT thread safe and should never be used with more than one thread at a time. This is a state machine,
handled by the process method. States are:
- NOT_CONNECTED -> connect() -> CONNECTED
- CONNECTED -> setMessage() -> READY TO WRITE
- READY_TO_WRITE -> write() -> READY TO WRITE | READY TO READ
- READY_TO_READ -> read() -> READY_TO_READ | TRANSFER_COMPLETE
- TRANSFER_COMPLETE -> CONNECTED
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final XByteBufferAcknowledgment buffer.protected booleanFlag indicating send completion.protected booleanFlag indicating connection in progress.protected byte[]Current message being processed.protected DatagramChannelThe UDP datagram channel.protected ByteBufferBuffer for reading from the channel.protected intNumber of remaining bytes to send.protected SelectorThe NIO selector for multiplexing channels.protected static final StringManagerString manager for this class.protected SocketChannelThe TCP socket channel.protected ByteBufferBuffer for writing to the channel. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Connect.voidDisconnect.byte[]Returns the current message being sent.Returns the NIO selector.booleanChecks if the send operation is complete.booleanprocess(SelectionKey key, boolean waitForAck) State machine to send data.protected booleanread()Reads acknowledgment data from the channel.voidreset()Resets the sender state for reuse.voidsetComplete(boolean complete) Sets the completion flag.voidsetMessage(byte[] data) Send message.voidsetMessage(byte[] data, int offset, int length) Sets the message to be sent.voidsetSelector(Selector selector) Sets the NIO selector.protected booleanwrite()Writes the current message to the channel.Methods inherited from class AbstractSender
getAddress, getAttempt, getConnectTime, getDestination, getDirectBuffer, getKeepAliveCount, getKeepAliveTime, getMaxRetryAttempts, getOoBInline, getPort, getRequestCount, getRxBufSize, getSoKeepAlive, getSoLingerOn, getSoLingerTime, getSoReuseAddress, getSoTrafficClass, getTcpNoDelay, getThrowOnFailedAck, getTimeout, getTxBufSize, getUdpPort, getUdpRxBufSize, getUdpTxBufSize, isConnected, isUdpBased, keepalive, setAddress, setAttempt, setConnected, setConnectTime, setDestination, setDirectBuffer, setKeepAliveCount, setKeepAliveTime, setMaxRetryAttempts, setOoBInline, setPort, setRequestCount, setRxBufSize, setSoKeepAlive, setSoLingerOn, setSoLingerTime, setSoReuseAddress, setSoTrafficClass, setTcpNoDelay, setThrowOnFailedAck, setTimeout, setTxBufSize, setUdpBased, setUdpPort, setUdpRxBufSize, setUdpTxBufSize, transferProperties
-
Field Details
-
sm
String manager for this class. -
selector
The NIO selector for multiplexing channels. -
socketChannel
The TCP socket channel. -
dataChannel
The UDP datagram channel. -
readbuf
Buffer for reading from the channel. -
writebuf
Buffer for writing to the channel. -
current
protected volatile byte[] currentCurrent message being processed. -
ackbuf
Acknowledgment buffer. -
remaining
protected int remainingNumber of remaining bytes to send. -
complete
protected boolean completeFlag indicating send completion. -
connecting
protected boolean connectingFlag indicating connection in progress.
-
-
Constructor Details
-
NioSender
public NioSender()Default constructor.
-
-
Method Details
-
process
State machine to send data.- Parameters:
key- The key to usewaitForAck- Wait for an ack- Returns:
trueif the processing was successful- Throws:
IOException- An IO error occurred
-
read
Reads acknowledgment data from the channel.- Returns:
trueif there is more data to read- Throws:
IOException- If an I/O error occurs
-
write
Writes the current message to the channel.- Returns:
trueif the message was fully written- Throws:
IOException- If an I/O error occurs
-
connect
-
disconnect
-
reset
public void reset()Resets the sender state for reuse. -
setMessage
Send message.- Parameters:
data- ChannelMessage- Throws:
IOException- if an error occurs
-
setMessage
Sets the message to be sent.- Parameters:
data- The message dataoffset- The offset in the data arraylength- The length of the data to send- Throws:
IOException- If an I/O error occurs
-
getMessage
public byte[] getMessage()Returns the current message being sent.- Returns:
- the current message byte array
-
isComplete
public boolean isComplete()Checks if the send operation is complete.- Returns:
trueif the send is complete
-
getSelector
-
setSelector
Sets the NIO selector.- Parameters:
selector- the selector
-
setComplete
public void setComplete(boolean complete) Sets the completion flag.- Parameters:
complete- the completion status
-