Class FrameCollector

java.lang.Object
org.simpleframework.http.socket.service.FrameCollector
All Implemented Interfaces:
Runnable, Operation

class FrameCollector extends 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 final Channel
    This is the underlying channel for this frame collector.
    private final ByteCursor
    This is the cursor used to maintain a stream seek position.
    private final FrameProcessor
    This decodes the frame bytes from the channel and processes it.
    private final Reactor
    This is the reactor used to schedule this operation for reads.
    private final Trace
    This is the tracer that is used to trace the frame collection.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    void
    This is called when a read operation has timed out.
    This is the channel associated with this collector.
    This is used to acquire the trace object that is associated with the operation.
    void
    This is used to register a FrameListener to this instance.
    void
    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 Details

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

    • 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
      reactor - this is the reactor used for read notifications
      channel - this is the underlying TCP communication channel
  • Method Details

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