Class WsFrameBase
java.lang.Object
org.apache.tomcat.websocket.WsFrameBase
- Direct Known Subclasses:
WsFrameClient, WsFrameServer
Takes the ServletInputStream, processes the WebSocket frames it contains and extracts the messages. WebSocket Pings
received will be responded to automatically without any action required by the application.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumWAITING - not suspended Server case: waiting for a notification that data is ready to be read from the socket, the socket is registered to the poller Client case: data has been read from the socket and is waiting for data to be processed PROCESSING - not suspended Server case: reading from the socket and processing the data Client case: processing the data if such has already been read and more data will be read from the socket SUSPENDING_WAIT - suspended, a call to suspend() was made while in WAITING state. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ByteBufferThe input buffer for reading data.protected final WsSessionThe WebSocket session for this frame. -
Constructor Summary
ConstructorsConstructorDescriptionWsFrameBase(WsSession wsSession, Transformation transformation) Constructs a new WsFrameBase. -
Method Summary
Modifier and TypeMethodDescriptionprotected static longbyteArrayToLong(byte[] b, int start, int len) Converts a byte array segment to a long value.protected voidchangeReadState(WsFrameBase.ReadState newState) Changes the read state to the new state.protected booleanchangeReadState(WsFrameBase.ReadState oldState, WsFrameBase.ReadState newState) Atomically changes the read state if it matches the expected old state.protected abstract LoggetLog()Returns the log instance for this frame.protected WsFrameBase.ReadStateReturns the current read state.protected TransformationReturns the transformation applied to this frame.protected abstract booleanisMasked()Returns whether frames from this peer must be masked.protected booleanisOpen()Returns whether the connection is open.protected booleanReturns whether this frame is currently suspended.protected voidProcesses the input buffer, reading and handling WebSocket frames.voidresume()Resumes processing of this frame after suspension.protected abstract voidThis method will be invoked when the read operation is resumed.protected voidsendMessageBinary(ByteBuffer msg, boolean last) Sends a binary message to the remote endpoint.protected voidsendMessageText(boolean last) Sends a text message to the remote endpoint.voidsuspend()Suspends processing of this frame.protected voidupdateStats(long payloadLength) Hook for updating server side statistics.
-
Field Details
-
wsSession
The WebSocket session for this frame. -
inputBuffer
The input buffer for reading data.
-
-
Constructor Details
-
WsFrameBase
Constructs a new WsFrameBase.- Parameters:
wsSession- The WebSocket sessiontransformation- The transformation to apply
-
-
Method Details
-
processInputBuffer
Processes the input buffer, reading and handling WebSocket frames.- Throws:
IOException- If an I/O error occurs
-
isMasked
protected abstract boolean isMasked()Returns whether frames from this peer must be masked.- Returns:
trueif frames must be masked
-
getLog
-
updateStats
protected void updateStats(long payloadLength) Hook for updating server side statistics. Called on every frame received.- Parameters:
payloadLength- Size of message payload
-
sendMessageText
Sends a text message to the remote endpoint.- Parameters:
last- Whether this is the last fragment of the message- Throws:
WsIOException- If a WebSocket I/O error occurs
-
sendMessageBinary
Sends a binary message to the remote endpoint.- Parameters:
msg- The message datalast- Whether this is the last fragment of the message- Throws:
WsIOException- If a WebSocket I/O error occurs
-
byteArrayToLong
Converts a byte array segment to a long value.- Parameters:
b- The byte arraystart- The start indexlen- The length- Returns:
- the long value
- Throws:
IOException- If the length exceeds 8 bytes
-
isOpen
protected boolean isOpen()Returns whether the connection is open.- Returns:
trueif open
-
getTransformation
Returns the transformation applied to this frame.- Returns:
- the transformation
-
suspend
public void suspend()Suspends processing of this frame. -
resume
public void resume()Resumes processing of this frame after suspension. -
isSuspended
protected boolean isSuspended()Returns whether this frame is currently suspended.- Returns:
trueif suspended
-
getReadState
Returns the current read state.- Returns:
- the read state
-
changeReadState
Changes the read state to the new state.- Parameters:
newState- The new read state
-
changeReadState
Atomically changes the read state if it matches the expected old state.- Parameters:
oldState- The expected old statenewState- The new state- Returns:
trueif the state was changed
-
resumeProcessing
protected abstract void resumeProcessing()This method will be invoked when the read operation is resumed. Since suspend of the read operation can be invoked at any time, when implementing this method one should consider that there might still be data remaining into the internal buffers that needs to be processed before reading again from the socket.
-