Class NioSender

  • All Implemented Interfaces:
    DataSender

    public class NioSender
    extends AbstractSender
    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
    Version:
    1.0
    • Field Detail

      • selector

        protected java.nio.channels.Selector selector
      • socketChannel

        protected java.nio.channels.SocketChannel socketChannel
      • dataChannel

        protected java.nio.channels.DatagramChannel dataChannel
      • readbuf

        protected java.nio.ByteBuffer readbuf
      • writebuf

        protected java.nio.ByteBuffer writebuf
      • current

        protected volatile byte[] current
      • remaining

        protected int remaining
      • complete

        protected boolean complete
      • connecting

        protected boolean connecting
    • Constructor Detail

      • NioSender

        public NioSender()
    • Method Detail

      • process

        public boolean process​(java.nio.channels.SelectionKey key,
                               boolean waitForAck)
                        throws java.io.IOException
        State machine to send data.
        Parameters:
        key - The key to use
        waitForAck - Wait for an ack
        Returns:
        true if the processing was successful
        Throws:
        java.io.IOException - An IO error occurred
      • read

        protected boolean read()
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        protected boolean write()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • connect

        public void connect()
                     throws java.io.IOException
        connect - blocking in this operation
        Specified by:
        connect in interface DataSender
        Specified by:
        connect in class AbstractSender
        Throws:
        java.io.IOException - TODO Implement this org.apache.catalina.tribes.transport.IDataSender method
      • disconnect

        public void disconnect()
        disconnect TODO Implement this org.apache.catalina.tribes.transport.IDataSender method
        Specified by:
        disconnect in interface DataSender
        Specified by:
        disconnect in class AbstractSender
      • reset

        public void reset()
      • setMessage

        public void setMessage​(byte[] data)
                        throws java.io.IOException
        sendMessage
        Parameters:
        data - ChannelMessage
        Throws:
        java.io.IOException - TODO Implement this org.apache.catalina.tribes.transport.IDataSender method
      • setMessage

        public void setMessage​(byte[] data,
                               int offset,
                               int length)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getMessage

        public byte[] getMessage()
      • isComplete

        public boolean isComplete()
      • getSelector

        public java.nio.channels.Selector getSelector()
      • setSelector

        public void setSelector​(java.nio.channels.Selector selector)
      • setComplete

        public void setComplete​(boolean complete)