Class FrameConnection
- java.lang.Object
-
- org.simpleframework.http.socket.service.FrameConnection
-
- All Implemented Interfaces:
FrameChannel
class FrameConnection extends java.lang.Object implements FrameChannel
TheFrameConnectionrepresents a connection that can send and receivd WebSocket frames. Any instance of this will provide a means to perform asynchronous writes and reads to a remote client using a lightweight framing protocol. A frame is a finite length sequence of bytes that can hold either text or binary data. Also, control frames are used to perform heartbeat monitoring and closure.For convenience frames can be consumed from the socket via a callback to a registered listener. This avoids having to poll each socket for data and provides a asynchronous event driven model of communication, which greatly reduces overhead and complication.
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelchannelThis is the underlying TCP channel that frames are sent over.private FrameEncoderencoderThis encoder is used to encode data as RFC 6455 frames.private FrameCollectoroperationThe collector is used to collect frames from the TCP channel.private ReasonreasonThe reason that is sent if at any time the channel is closed.private SessionsessionThis is the session object that has a synchronized channel.private TracetraceThis is used to trace all events that occur on the channel.private ByteWriterwriterThis is the sender used to send frames over the channel.
-
Constructor Summary
Constructors Constructor Description FrameConnection(Request request, Response response, Reactor reactor)Constructor for theFrameConnectionobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This is used to close the connection without a specific reason.voidclose(Reason reason)This is used to close the connection with a specific reason.Sessionopen()This is used to open the channel and begin consuming frames.voidregister(FrameListener listener)This is used to register aFrameListenerto this instance.voidremove(FrameListener listener)This is used to remove aFrameListenerfrom this instance.voidsend(byte[] data)This is used to send data to the connected client.voidsend(java.lang.String text)This is used to send text to the connected client.voidsend(Frame frame)This is used to send data to the connected client.
-
-
-
Field Detail
-
operation
private final FrameCollector operation
The collector is used to collect frames from the TCP channel.
-
encoder
private final FrameEncoder encoder
This encoder is used to encode data as RFC 6455 frames.
-
writer
private final ByteWriter writer
This is the sender used to send frames over the channel.
-
session
private final Session session
This is the session object that has a synchronized channel.
-
channel
private final Channel channel
This is the underlying TCP channel that frames are sent over.
-
reason
private final Reason reason
The reason that is sent if at any time the channel is closed.
-
trace
private final Trace trace
This is used to trace all events that occur on the channel.
-
-
Constructor Detail
-
FrameConnection
public FrameConnection(Request request, Response response, Reactor reactor)
Constructor for theFrameConnectionobject. This is used to create a channel that can read and write frames over a TCP channel. For asynchronous read and dispatch operations this will produce an operation to collect and process RFC 6455 frames.- Parameters:
request- this is the initiating request for the WebSocketresponse- this is the initiating response for the WebSocketreactor- this is the reactor used to process frames
-
-
Method Detail
-
open
public Session open() throws java.io.IOException
This is used to open the channel and begin consuming frames. This will also return the session that contains the details for the created WebSocket such as the initiating request and response as well as theFrameChannelobject.- Returns:
- the session associated with the WebSocket
- Throws:
java.io.IOException
-
register
public void register(FrameListener listener) throws java.io.IOException
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.- Specified by:
registerin interfaceFrameChannel- Parameters:
listener- this is the listener that is to be registered- Throws:
java.io.IOException
-
remove
public void remove(FrameListener listener) throws java.io.IOException
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.- Specified by:
removein interfaceFrameChannel- Parameters:
listener- this is the listener to be removed- Throws:
java.io.IOException
-
send
public void send(byte[] data) throws java.io.IOExceptionThis is used to send data to the connected client. To prevent an application code from causing resource issues this will block as soon as a configured linked list of mapped memory buffers has been exhausted. Caution should be taken when writing a broadcast implementation that can write to multiple sockets as a badly behaving socket that has filled its output buffering capacity can cause congestion.- Specified by:
sendin interfaceFrameChannel- Parameters:
data- this is the data that is to be sent- Throws:
java.io.IOException
-
send
public void send(java.lang.String text) throws java.io.IOExceptionThis is used to send text to the connected client. To prevent an application code from causing resource issues this will block as soon as a configured linked list of mapped memory buffers has been exhausted. Caution should be taken when writing a broadcast implementation that can write to multiple sockets as a badly behaving socket that has filled its output buffering capacity can cause congestion.- Specified by:
sendin interfaceFrameChannel- Parameters:
text- this is the text that is to be sent- Throws:
java.io.IOException
-
send
public void send(Frame frame) throws java.io.IOException
This is used to send data to the connected client. To prevent an application code from causing resource issues this will block as soon as a configured linked list of mapped memory buffers has been exhausted. Caution should be taken when writing a broadcast implementation that can write to multiple sockets as a badly behaving socket that has filled its output buffering capacity can cause congestion.- Specified by:
sendin interfaceFrameChannel- Parameters:
frame- this is the frame that is to be sent- Throws:
java.io.IOException
-
close
public void close(Reason reason) throws java.io.IOException
This is used to close the connection with a specific reason. The close reason will be sent as a control frame before the TCP connection is terminated.- Specified by:
closein interfaceFrameChannel- Parameters:
reason- the reason for closing the connection- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionThis 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.- Specified by:
closein interfaceFrameChannel- Throws:
java.io.IOException
-
-