Class FrameProcessor


  • class FrameProcessor
    extends java.lang.Object
    The FrameProcessor object is used to process incoming data and dispatch that data as WebSocket frames. Dispatching of the frames is done by making a callback to FrameListener objects registered. In addition to frames this will also notify of any errors that occur or on connection closure.
    See Also:
    FrameConsumer
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Channel channel
      This is the underlying TCP channel this reads frames from.
      private java.util.concurrent.atomic.AtomicBoolean closed
      This is used to determine if a close notification was sent.
      private FrameConsumer consumer
      This is used to consume the frames from the underling channel.
      private ByteCursor cursor
      This is the cursor used to maintain a read seek position.
      private FrameEncoder encoder
      This is the encoder that is used to send control messages.
      private ReasonExtractor extractor
      This is used to extract the reason description from a frame.
      private java.util.Set<FrameListener> listeners
      This is the set of listeners to dispatch frames to.
      private Reason normal
      This is the reason message used for a normal closure.
      private Session session
      This is the session associated with the WebSocket connection.
      private Trace trace
      This is used to trace the events that occur on the channel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      This is used to close the connection when it has not responded to any activity for a configured period of time.
      void close​(Reason reason)
      This is used to close the connection without a specific reason.
      void failure​(java.lang.Exception reason)
      This is used to report failures back to the client.
      void process()
      This is used to process frames consumed from the underlying TCP connection.
      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.
      • Methods inherited from class java.lang.Object

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

      • listeners

        private final java.util.Set<FrameListener> listeners
        This is the set of listeners to dispatch frames to.
      • extractor

        private final ReasonExtractor extractor
        This is used to extract the reason description from a frame.
      • consumer

        private final FrameConsumer consumer
        This is used to consume the frames from the underling channel.
      • encoder

        private final FrameEncoder encoder
        This is the encoder that is used to send control messages.
      • closed

        private final java.util.concurrent.atomic.AtomicBoolean closed
        This is used to determine if a close notification was sent.
      • cursor

        private final ByteCursor cursor
        This is the cursor used to maintain a read seek position.
      • session

        private final Session session
        This is the session associated with the WebSocket connection.
      • channel

        private final Channel channel
        This is the underlying TCP channel this reads frames from.
      • normal

        private final Reason normal
        This is the reason message used for a normal closure.
      • trace

        private final Trace trace
        This is used to trace the events that occur on the channel.
    • Constructor Detail

      • FrameProcessor

        public FrameProcessor​(FrameEncoder encoder,
                              Session session,
                              Request request)
        Constructor for the FrameProcessor object. This is used to create a processor that can consume and dispatch frames as defined by RFC 6455 to a set of registered listeners.
        Parameters:
        encoder - this is the encoder used to send control frames
        session - this is the session associated with the channel
        channel - this is the channel to read frames from
    • Method Detail

      • 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
      • process

        public void process()
                     throws java.io.IOException
        This is used to process frames consumed from the underlying TCP connection. It will respond to control frames such as pings and will also handle close frames. Each frame, regardless of its type will be dispatched to any FrameListener objects that are registered with the processor. If an a close frame is received it will echo that close frame, with the same close code and back to the sender as suggested by RFC 6455 section 5.5.1.
        Throws:
        java.io.IOException
      • failure

        public void failure​(java.lang.Exception reason)
                     throws java.io.IOException
        This is used to report failures back to the client. Any I/O or frame processing exception is reported back to all of the registered listeners so that they can take action. The underlying TCP connection is closed after any failure.
        Parameters:
        reason - this is the cause of the failure
        Throws:
        java.io.IOException
      • close

        public void close​(Reason reason)
                   throws java.io.IOException
        This is used to close the connection without a specific reason. The close reason will be sent as a control frame before the TCP connection is terminated. All registered listeners will be notified of the close event.
        Parameters:
        reason - this is the reason for the connection closure
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        This is used to close the connection when it has not responded to any activity for a configured period of time. It may be possible to send up a control frame, however if the TCP channel is closed this will just notify the listeners.
        Throws:
        java.io.IOException