Class FrameProcessor

java.lang.Object
org.simpleframework.http.socket.service.FrameProcessor

class FrameProcessor extends 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:
  • Field Summary

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

    Constructors
    Constructor
    Description
    FrameProcessor(FrameEncoder encoder, Session session, Request request)
    Constructor for the FrameProcessor object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    This is used to report failures back to the client.
    void
    This is used to process frames consumed from the underlying TCP connection.
    void
    This is used to register a FrameListener to this instance.
    void
    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 Details

    • listeners

      private final 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 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 Details

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

    • 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 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:
      IOException
    • failure

      public void failure(Exception reason) throws 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:
      IOException
    • close

      public void close(Reason reason) throws 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:
      IOException
    • close

      public void close() throws 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:
      IOException