Class FrameProcessor
- java.lang.Object
-
- org.simpleframework.http.socket.service.FrameProcessor
-
class FrameProcessor extends java.lang.ObjectTheFrameProcessorobject is used to process incoming data and dispatch that data as WebSocket frames. Dispatching of the frames is done by making a callback toFrameListenerobjects 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 ChannelchannelThis is the underlying TCP channel this reads frames from.private java.util.concurrent.atomic.AtomicBooleanclosedThis is used to determine if a close notification was sent.private FrameConsumerconsumerThis is used to consume the frames from the underling channel.private ByteCursorcursorThis is the cursor used to maintain a read seek position.private FrameEncoderencoderThis is the encoder that is used to send control messages.private ReasonExtractorextractorThis is used to extract the reason description from a frame.private java.util.Set<FrameListener>listenersThis is the set of listeners to dispatch frames to.private ReasonnormalThis is the reason message used for a normal closure.private SessionsessionThis is the session associated with the WebSocket connection.private TracetraceThis 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 theFrameProcessorobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This is used to close the connection when it has not responded to any activity for a configured period of time.voidclose(Reason reason)This is used to close the connection without a specific reason.voidfailure(java.lang.Exception reason)This 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 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 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 Detail
-
register
public void register(FrameListener listener)
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
public void remove(FrameListener listener)
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
public void process() throws java.io.IOExceptionThis 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:
java.io.IOException
-
failure
public void failure(java.lang.Exception reason) throws java.io.IOExceptionThis 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.IOExceptionThis 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
-
-