Class FrameProcessor
java.lang.Object
org.simpleframework.http.socket.service.FrameProcessor
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
FieldsModifier and TypeFieldDescriptionprivate final ChannelThis is the underlying TCP channel this reads frames from.private final AtomicBooleanThis is used to determine if a close notification was sent.private final FrameConsumerThis is used to consume the frames from the underling channel.private final ByteCursorThis is the cursor used to maintain a read seek position.private final FrameEncoderThis is the encoder that is used to send control messages.private final ReasonExtractorThis 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 ReasonThis is the reason message used for a normal closure.private final SessionThis is the session associated with the WebSocket connection.private final TraceThis is used to trace the events that occur on the channel. -
Constructor Summary
ConstructorsConstructorDescriptionFrameProcessor(FrameEncoder encoder, Session session, Request request) Constructor for theFrameProcessorobject. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This is used to close the connection when it has not responded to any activity for a configured period of time.voidThis is used to close the connection without a specific reason.voidThis is used to report failures back to the client.voidprocess()This is used to process frames consumed from the underlying TCP connection.voidregister(FrameListener listener) This is used to register aFrameListenerto this instance.voidremove(FrameListener listener) This is used to remove aFrameListenerfrom this instance.
-
Field Details
-
listeners
This is the set of listeners to dispatch frames to. -
extractor
This is used to extract the reason description from a frame. -
consumer
This is used to consume the frames from the underling channel. -
encoder
This is the encoder that is used to send control messages. -
closed
This is used to determine if a close notification was sent. -
cursor
This is the cursor used to maintain a read seek position. -
session
This is the session associated with the WebSocket connection. -
channel
This is the underlying TCP channel this reads frames from. -
normal
This is the reason message used for a normal closure. -
trace
This is used to trace the events that occur on the channel.
-
-
Constructor Details
-
FrameProcessor
Constructor for theFrameProcessorobject. 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 framessession- this is the session associated with the channelchannel- this is the channel to read frames from
-
-
Method Details
-
register
This is used to register aFrameListenerto 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
This is used to remove aFrameListenerfrom 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
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 anyFrameListenerobjects 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
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
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
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
-