Class NioReceiver

    • Field Detail

      • sm

        protected static final StringManager sm
        The string manager for this package.
      • events

        protected final java.util.Deque<java.lang.Runnable> events
        Queue of events to be processed by the selector thread.
      • lastCheck

        protected long lastCheck
        Timestamp of the last socket timeout check.
    • Constructor Detail

      • NioReceiver

        public NioReceiver()
        Default constructor.
    • Method Detail

      • stop

        public void stop()
        Description copied from class: ReceiverBase
        Stops the receiver by shutting down the executor and unregistering from JMX.
        Specified by:
        stop in interface ChannelReceiver
        Overrides:
        stop in class ReceiverBase
      • start

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

        protected void bind()
                     throws java.io.IOException
        Binds the server socket and datagram channels to their respective ports.
        Throws:
        java.io.IOException - If binding fails
      • addEvent

        public void addEvent​(java.lang.Runnable event)
        Adds a runnable event to the selector's event queue.
        Parameters:
        event - The event to add
      • events

        public void events()
        Processes all pending events in the event queue.
      • cancelledKey

        public static void cancelledKey​(java.nio.channels.SelectionKey key)
        Handles a cancelled selection key by closing associated channels and cleaning up resources.
        Parameters:
        key - The cancelled selection key
      • socketTimeouts

        protected void socketTimeouts()
        Checks for socket timeouts and handles expired connections.
      • listen

        protected void listen()
                       throws java.lang.Exception
        Get data from channel and store in byte array send it to cluster
        Throws:
        java.io.IOException - IO error
        java.lang.Exception
      • registerChannel

        protected void registerChannel​(java.nio.channels.Selector selector,
                                       java.nio.channels.SelectableChannel channel,
                                       int ops,
                                       java.lang.Object attach)
                                throws java.lang.Exception
        Register the given channel with the given selector for the given operations of interest
        Parameters:
        selector - The selector to use
        channel - The channel
        ops - The operations to register
        attach - Attachment object
        Throws:
        java.lang.Exception - IO error with channel
      • run

        public void run()
        Start thread and listen
        Specified by:
        run in interface java.lang.Runnable
      • readDataFromSocket

        protected void readDataFromSocket​(java.nio.channels.SelectionKey key)
                                   throws java.lang.Exception
        Sample data handler method for a channel with data ready to read.
        Parameters:
        key - A SelectionKey object associated with a channel determined by the selector to be ready for reading. If the channel returns an EOF condition, it is closed here, which automatically invalidates the associated key. The selector will then de-register the channel on the next select call.
        Throws:
        java.lang.Exception - IO error with channel