Class WebSocketRemoteEndpoint
- java.lang.Object
-
- org.eclipse.jetty.websocket.common.WebSocketRemoteEndpoint
-
- All Implemented Interfaces:
RemoteEndpoint
public class WebSocketRemoteEndpoint extends java.lang.Object implements RemoteEndpoint
Endpoint for Writing messages to the Remote websocket.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classWebSocketRemoteEndpoint.MsgType
-
Field Summary
Fields Modifier and Type Field Description private static intASYNC_MASKprivate BatchModebatchModeprivate static intBLOCK_MASKprivate BlockingWriteCallbackblockerprivate LogicalConnectionconnectionprivate static org.eclipse.jetty.util.log.LoggerLOGprivate intmaxNumOutgoingFramesprivate java.util.concurrent.atomic.AtomicIntegermsgStateprivate static WriteCallbackNOOP_CALLBACKprivate java.util.concurrent.atomic.AtomicIntegernumOutgoingFramesprivate OutgoingFramesoutgoingprivate static intPARTIAL_BINARY_MASKprivate static intPARTIAL_TEXT_MASKprivate static intSTREAM_MASK
-
Constructor Summary
Constructors Constructor Description WebSocketRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoing)WebSocketRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoing, BatchMode batchMode)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidblockingWrite(WebSocketFrame frame)voidflush()Flushes messages that may have been batched by the implementation.private static WriteCallbackfrom(WriteCallback callback, java.lang.Runnable completed)BatchModegetBatchMode()java.net.InetSocketAddressgetInetSocketAddress()Get the InetSocketAddress for the established connection.intgetMaxOutgoingFrames()Get the maximum number of data frames allowed to be waiting to be sent at any one time.private booleanlockMsg(WebSocketRemoteEndpoint.MsgType type)private java.util.concurrent.Future<java.lang.Void>sendAsyncFrame(WebSocketFrame frame)InternalvoidsendBytes(java.nio.ByteBuffer data)Blocking write of bytes.voidsendBytes(java.nio.ByteBuffer data, WriteCallback callback)Initiates the asynchronous transmission of a binary message.java.util.concurrent.Future<java.lang.Void>sendBytesByFuture(java.nio.ByteBuffer data)Initiates the asynchronous transmission of a binary message.voidsendPartialBytes(java.nio.ByteBuffer fragment, boolean isLast)Send a binary message in pieces, blocking until all of the message has been transmitted.voidsendPartialString(java.lang.String fragment, boolean isLast)Send a text message in pieces, blocking until all of the message has been transmitted.voidsendPing(java.nio.ByteBuffer applicationData)Send a Ping message containing the given application data to the remote endpoint.voidsendPong(java.nio.ByteBuffer applicationData)Allows the developer to send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session.voidsendString(java.lang.String text)Send a text message, blocking until all bytes of the message has been transmitted.voidsendString(java.lang.String text, WriteCallback callback)Initiates the asynchronous transmission of a text message.java.util.concurrent.Future<java.lang.Void>sendStringByFuture(java.lang.String text)Initiates the asynchronous transmission of a text message.voidsetBatchMode(BatchMode batchMode)Set the batch mode with which messages are sent.voidsetMaxOutgoingFrames(int maxOutgoingFrames)Set the maximum number of data frames allowed to be waiting to be sent at any one time.java.lang.StringtoString()voiduncheckedSendFrame(WebSocketFrame frame, WriteCallback callback)private voidunlockMsg(WebSocketRemoteEndpoint.MsgType type)
-
-
-
Field Detail
-
NOOP_CALLBACK
private static final WriteCallback NOOP_CALLBACK
-
LOG
private static final org.eclipse.jetty.util.log.Logger LOG
-
ASYNC_MASK
private static final int ASYNC_MASK
- See Also:
- Constant Field Values
-
BLOCK_MASK
private static final int BLOCK_MASK
- See Also:
- Constant Field Values
-
STREAM_MASK
private static final int STREAM_MASK
- See Also:
- Constant Field Values
-
PARTIAL_TEXT_MASK
private static final int PARTIAL_TEXT_MASK
- See Also:
- Constant Field Values
-
PARTIAL_BINARY_MASK
private static final int PARTIAL_BINARY_MASK
- See Also:
- Constant Field Values
-
connection
private final LogicalConnection connection
-
outgoing
private final OutgoingFrames outgoing
-
msgState
private final java.util.concurrent.atomic.AtomicInteger msgState
-
blocker
private final BlockingWriteCallback blocker
-
numOutgoingFrames
private final java.util.concurrent.atomic.AtomicInteger numOutgoingFrames
-
batchMode
private volatile BatchMode batchMode
-
maxNumOutgoingFrames
private int maxNumOutgoingFrames
-
-
Constructor Detail
-
WebSocketRemoteEndpoint
public WebSocketRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoing)
-
WebSocketRemoteEndpoint
public WebSocketRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoing, BatchMode batchMode)
-
-
Method Detail
-
blockingWrite
private void blockingWrite(WebSocketFrame frame) throws java.io.IOException
- Throws:
java.io.IOException
-
lockMsg
private boolean lockMsg(WebSocketRemoteEndpoint.MsgType type)
-
unlockMsg
private void unlockMsg(WebSocketRemoteEndpoint.MsgType type)
-
getInetSocketAddress
public java.net.InetSocketAddress getInetSocketAddress()
Get the InetSocketAddress for the established connection.- Specified by:
getInetSocketAddressin interfaceRemoteEndpoint- Returns:
- the InetSocketAddress for the established connection. (or null, if the connection is no longer established)
-
sendAsyncFrame
private java.util.concurrent.Future<java.lang.Void> sendAsyncFrame(WebSocketFrame frame)
Internal- Parameters:
frame- the frame to write- Returns:
- the future for the network write of the frame
-
sendBytes
public void sendBytes(java.nio.ByteBuffer data) throws java.io.IOExceptionBlocking write of bytes.- Specified by:
sendBytesin interfaceRemoteEndpoint- Parameters:
data- the message to be sent- Throws:
java.io.IOException- if unable to send the bytes
-
sendBytesByFuture
public java.util.concurrent.Future<java.lang.Void> sendBytesByFuture(java.nio.ByteBuffer data)
Description copied from interface:RemoteEndpointInitiates the asynchronous transmission of a binary message. This method returns before the message is transmitted. Developers may use the returned Future object to track progress of the transmission.- Specified by:
sendBytesByFuturein interfaceRemoteEndpoint- Parameters:
data- the data being sent- Returns:
- the Future object representing the send operation.
-
sendBytes
public void sendBytes(java.nio.ByteBuffer data, WriteCallback callback)Description copied from interface:RemoteEndpointInitiates the asynchronous transmission of a binary message. This method returns before the message is transmitted. Developers may provide a callback to be notified when the message has been transmitted or resulted in an error.- Specified by:
sendBytesin interfaceRemoteEndpoint- Parameters:
data- the data being sentcallback- callback to notify of success or failure of the write operation
-
uncheckedSendFrame
public void uncheckedSendFrame(WebSocketFrame frame, WriteCallback callback)
-
sendPartialBytes
public void sendPartialBytes(java.nio.ByteBuffer fragment, boolean isLast) throws java.io.IOExceptionDescription copied from interface:RemoteEndpointSend a binary message in pieces, blocking until all of the message has been transmitted. The runtime reads the message in order. Non-final pieces are sent with isLast set to false. The final piece must be sent with isLast set to true.- Specified by:
sendPartialBytesin interfaceRemoteEndpoint- Parameters:
fragment- the piece of the message being sentisLast- true if this is the last piece of the partial bytes- Throws:
java.io.IOException- if unable to send the partial bytes
-
sendPartialString
public void sendPartialString(java.lang.String fragment, boolean isLast) throws java.io.IOExceptionDescription copied from interface:RemoteEndpointSend a text message in pieces, blocking until all of the message has been transmitted. The runtime reads the message in order. Non-final pieces are sent with isLast set to false. The final piece must be sent with isLast set to true.- Specified by:
sendPartialStringin interfaceRemoteEndpoint- Parameters:
fragment- the piece of the message being sentisLast- true if this is the last piece of the partial bytes- Throws:
java.io.IOException- if unable to send the partial bytes
-
sendPing
public void sendPing(java.nio.ByteBuffer applicationData) throws java.io.IOExceptionDescription copied from interface:RemoteEndpointSend a Ping message containing the given application data to the remote endpoint. The corresponding Pong message may be picked up using the MessageHandler.Pong handler.- Specified by:
sendPingin interfaceRemoteEndpoint- Parameters:
applicationData- the data to be carried in the ping request- Throws:
java.io.IOException- if unable to send the ping
-
sendPong
public void sendPong(java.nio.ByteBuffer applicationData) throws java.io.IOExceptionDescription copied from interface:RemoteEndpointAllows the developer to send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session.- Specified by:
sendPongin interfaceRemoteEndpoint- Parameters:
applicationData- the application data to be carried in the pong response.- Throws:
java.io.IOException- if unable to send the pong
-
sendString
public void sendString(java.lang.String text) throws java.io.IOExceptionDescription copied from interface:RemoteEndpointSend a text message, blocking until all bytes of the message has been transmitted.Note: this is a blocking call
- Specified by:
sendStringin interfaceRemoteEndpoint- Parameters:
text- the message to be sent- Throws:
java.io.IOException- if unable to send the text message
-
sendStringByFuture
public java.util.concurrent.Future<java.lang.Void> sendStringByFuture(java.lang.String text)
Description copied from interface:RemoteEndpointInitiates the asynchronous transmission of a text message. This method may return before the message is transmitted. Developers may use the returned Future object to track progress of the transmission.- Specified by:
sendStringByFuturein interfaceRemoteEndpoint- Parameters:
text- the text being sent- Returns:
- the Future object representing the send operation.
-
sendString
public void sendString(java.lang.String text, WriteCallback callback)Description copied from interface:RemoteEndpointInitiates the asynchronous transmission of a text message. This method may return before the message is transmitted. Developers may provide a callback to be notified when the message has been transmitted or resulted in an error.- Specified by:
sendStringin interfaceRemoteEndpoint- Parameters:
text- the text being sentcallback- callback to notify of success or failure of the write operation
-
getBatchMode
public BatchMode getBatchMode()
- Specified by:
getBatchModein interfaceRemoteEndpoint- Returns:
- the batch mode with which messages are sent.
- See Also:
RemoteEndpoint.flush()
-
setBatchMode
public void setBatchMode(BatchMode batchMode)
Description copied from interface:RemoteEndpointSet the batch mode with which messages are sent.- Specified by:
setBatchModein interfaceRemoteEndpoint- Parameters:
batchMode- the batch mode to use- See Also:
RemoteEndpoint.flush()
-
getMaxOutgoingFrames
public int getMaxOutgoingFrames()
Description copied from interface:RemoteEndpointGet the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with aWritePendingExceptionbut the connection is not failed and will remain open.- Specified by:
getMaxOutgoingFramesin interfaceRemoteEndpoint- Returns:
- the max number of frames.
-
setMaxOutgoingFrames
public void setMaxOutgoingFrames(int maxOutgoingFrames)
Description copied from interface:RemoteEndpointSet the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with aWritePendingExceptionbut the connection is not failed and will remain open.- Specified by:
setMaxOutgoingFramesin interfaceRemoteEndpoint- Parameters:
maxOutgoingFrames- the max number of frames.
-
flush
public void flush() throws java.io.IOExceptionDescription copied from interface:RemoteEndpointFlushes messages that may have been batched by the implementation.- Specified by:
flushin interfaceRemoteEndpoint- Throws:
java.io.IOException- if the flush fails- See Also:
RemoteEndpoint.getBatchMode()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
from
private static WriteCallback from(WriteCallback callback, java.lang.Runnable completed)
-
-