Class FrameCollector

  • All Implemented Interfaces:
    java.lang.Runnable, Operation

    class FrameCollector
    extends java.lang.Object
    implements Operation
    The FrameCollector operation is used to collect frames from a channel and dispatch them to a FrameListener. To ensure that stale connections do not linger any connection that does not send a control ping or pong frame within two minutes will be terminated and the close control frame will be sent.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Channel channel
      This is the underlying channel for this frame collector.
      private ByteCursor cursor
      This is the cursor used to maintain a stream seek position.
      private FrameProcessor processor
      This decodes the frame bytes from the channel and processes it.
      private Reactor reactor
      This is the reactor used to schedule this operation for reads.
      private Trace trace
      This is the tracer that is used to trace the frame collection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      This is called when a read operation has timed out.
      java.nio.channels.SelectableChannel getChannel()
      This is the channel associated with this collector.
      Trace getTrace()
      This is used to acquire the trace object that is associated with the operation.
      void register​(FrameListener listener)
      This is used to register a FrameListener to this instance.
      void remove​(FrameListener listener)
      This is used to remove a FrameListener from this instance.
      void run()
      This is used to execute the collection operation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • processor

        private final FrameProcessor processor
        This decodes the frame bytes from the channel and processes it.
      • cursor

        private final ByteCursor cursor
        This is the cursor used to maintain a stream seek position.
      • channel

        private final Channel channel
        This is the underlying channel for this frame collector.
      • reactor

        private final Reactor reactor
        This is the reactor used to schedule this operation for reads.
      • trace

        private final Trace trace
        This is the tracer that is used to trace the frame collection.
    • Constructor Detail

      • FrameCollector

        public FrameCollector​(FrameEncoder encoder,
                              Session session,
                              Request request,
                              Reactor reactor)
        Constructor for the FrameCollector object. This is used to create a collector that will process and dispatch web socket frames as defined by RFC 6455.
        Parameters:
        encoder - this is the encoder used to send messages
        session - this is the web socket session
        channel - this is the underlying TCP communication channel
        reactor - this is the reactor used for read notifications
    • Method Detail

      • getTrace

        public Trace getTrace()
        This is used to acquire the trace object that is associated with the operation. A trace object is used to collection details on what operations are being performed. For instance it may contain information relating to I/O events or errors.
        Specified by:
        getTrace in interface Operation
        Returns:
        this returns the trace associated with this operation
      • getChannel

        public java.nio.channels.SelectableChannel getChannel()
        This is the channel associated with this collector. This is used to register for notification of read events. If at any time the remote endpoint is closed then this will cause the collector to perform a final execution before closing.
        Specified by:
        getChannel in interface Operation
        Returns:
        this returns the selectable TCP channel
      • register

        public void register​(FrameListener listener)
        This is used to register a FrameListener to this instance. The registered listener will receive all user frames and control frames sent from the client. Also, when the frame is closed or when an unexpected error occurs the listener is notified. Any number of listeners can be registered at any time.
        Parameters:
        listener - this is the listener that is to be registered
      • remove

        public void remove​(FrameListener listener)
        This is used to remove a FrameListener from this instance. After removal the listener will no longer receive any user frames or control messages from this specific instance.
        Parameters:
        listener - this is the listener to be removed
      • run

        public void run()
        This is used to execute the collection operation. Collection is done by reading the frame header from the incoming data, once consumed the remainder of the frame is collected until such time as it has been fully consumed. When consumed it will be dispatched to the registered frame listeners.
        Specified by:
        run in interface java.lang.Runnable
      • cancel

        public void cancel()
        This is called when a read operation has timed out. To ensure that stale channels do not remain registered they are cleared out with this method and a close frame is sent if possible.
        Specified by:
        cancel in interface Operation