Class WsRemoteEndpointImplServer
- java.lang.Object
-
- org.apache.tomcat.websocket.WsRemoteEndpointImplBase
-
- org.apache.tomcat.websocket.server.WsRemoteEndpointImplServer
-
- All Implemented Interfaces:
RemoteEndpoint
public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase
This is the server sideRemoteEndpoint
implementation - i.e. what the server uses to send data to the client.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.websocket.RemoteEndpoint
RemoteEndpoint.Async, RemoteEndpoint.Basic
-
-
Field Summary
-
Fields inherited from class org.apache.tomcat.websocket.WsRemoteEndpointImplBase
messagePartInProgress, SENDRESULT_OK
-
-
Constructor Summary
Constructors Constructor Description WsRemoteEndpointImplServer(SocketWrapperBase<?> socketWrapper, UpgradeInfo upgradeInfo, WsServerContainer serverContainer, WebConnection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
acquireMessagePartInProgressSemaphore(byte opCode, long timeoutExpiry)
Acquire the semaphore that allows a message part to be written.protected void
doClose()
protected void
doWrite(SendHandler handler, long blockingWriteTimeoutExpiry, java.nio.ByteBuffer... buffers)
protected java.util.concurrent.locks.Lock
getLock()
protected long
getTimeoutExpiry()
protected boolean
isMasked()
protected void
onTimeout(boolean useDispatch)
void
onWritePossible(boolean useDispatch)
protected void
setTransformation(Transformation transformation)
protected void
updateStats(long payloadLength)
Hook for updating server side statistics.-
Methods inherited from class org.apache.tomcat.websocket.WsRemoteEndpointImplBase
close, flushBatch, getBatchingAllowed, getSendStream, getSendTimeout, getSendWriter, sendBytes, sendBytesByCompletion, sendBytesByFuture, sendObject, sendObjectByCompletion, sendObjectByFuture, sendPartialBytes, sendPartialString, sendPing, sendPong, sendString, sendStringByCompletion, sendStringByFuture, setBatchingAllowed, setEncoders, setSendTimeout, setSession
-
-
-
-
Constructor Detail
-
WsRemoteEndpointImplServer
public WsRemoteEndpointImplServer(SocketWrapperBase<?> socketWrapper, UpgradeInfo upgradeInfo, WsServerContainer serverContainer, WebConnection connection)
-
-
Method Detail
-
isMasked
protected final boolean isMasked()
- Specified by:
isMasked
in classWsRemoteEndpointImplBase
-
acquireMessagePartInProgressSemaphore
protected boolean acquireMessagePartInProgressSemaphore(byte opCode, long timeoutExpiry) throws java.lang.InterruptedException
Acquire the semaphore that allows a message part to be written.The close message is a special case. It needs to be blocking else implementing the clean-up that follows the sending of the close message gets a lot more complicated. On the server, this creates additional complications as a dead-lock may occur in the following scenario:
- Application thread writes message using non-blocking
- Write does not complete (write logic holds message pending lock)
- Socket is added to poller (or equivalent) for write
- Client sends close message
- Container processes received close message and tries to send close message in response
- Container holds socket lock and is blocked waiting for message pending lock
- Poller fires write possible event for socket
- Container tries to process write possible event but is blocked waiting for socket lock
- Processing of the WebSocket connection is dead-locked until the original message write times out
true
) and upgrade processors are never pooled.TODO: Despite the complications it creates, it would be worth exploring the possibility of processing a received close frame in a non-blocking manner.
- Overrides:
acquireMessagePartInProgressSemaphore
in classWsRemoteEndpointImplBase
- Parameters:
opCode
- The OPCODE for the message to be writtentimeoutExpiry
- The time when the attempt to acquire the semaphore should expire- Returns:
true
if the semaphore is obtained, otherwisefalse
.- Throws:
java.lang.InterruptedException
- If the wait for the semaphore is interrupted
-
doWrite
protected void doWrite(SendHandler handler, long blockingWriteTimeoutExpiry, java.nio.ByteBuffer... buffers)
- Specified by:
doWrite
in classWsRemoteEndpointImplBase
-
updateStats
protected void updateStats(long payloadLength)
Description copied from class:WsRemoteEndpointImplBase
Hook for updating server side statistics. Called on every frame written (including when batching is enabled and the frames are buffered locally until the buffer is full or is flushed).- Overrides:
updateStats
in classWsRemoteEndpointImplBase
- Parameters:
payloadLength
- Size of message payload
-
onWritePossible
public void onWritePossible(boolean useDispatch)
-
doClose
protected void doClose()
- Specified by:
doClose
in classWsRemoteEndpointImplBase
-
getTimeoutExpiry
protected long getTimeoutExpiry()
-
onTimeout
protected void onTimeout(boolean useDispatch)
-
setTransformation
protected void setTransformation(Transformation transformation)
- Overrides:
setTransformation
in classWsRemoteEndpointImplBase
-
getLock
protected java.util.concurrent.locks.Lock getLock()
- Specified by:
getLock
in classWsRemoteEndpointImplBase
-
-