public class WebSocketRemoteEndpoint extends java.lang.Object implements RemoteEndpoint
Modifier and Type | Class and Description |
---|---|
private static class |
WebSocketRemoteEndpoint.MsgType |
Modifier and Type | Field and Description |
---|---|
private static int |
ASYNC_MASK |
private BatchMode |
batchMode |
private static int |
BLOCK_MASK |
private BlockingWriteCallback |
blocker |
private LogicalConnection |
connection |
private static Logger |
LOG |
private java.util.concurrent.atomic.AtomicInteger |
msgState |
private static WriteCallback |
NOOP_CALLBACK |
private OutgoingFrames |
outgoing |
private static int |
PARTIAL_BINARY_MASK |
private static int |
PARTIAL_TEXT_MASK |
private static int |
STREAM_MASK |
Constructor and Description |
---|
WebSocketRemoteEndpoint(LogicalConnection connection,
OutgoingFrames outgoing) |
WebSocketRemoteEndpoint(LogicalConnection connection,
OutgoingFrames outgoing,
BatchMode batchMode) |
Modifier and Type | Method and Description |
---|---|
private void |
blockingWrite(WebSocketFrame frame) |
void |
flush()
Flushes messages that may have been batched by the implementation.
|
BatchMode |
getBatchMode() |
java.net.InetSocketAddress |
getInetSocketAddress()
Get the InetSocketAddress for the established connection.
|
private boolean |
lockMsg(WebSocketRemoteEndpoint.MsgType type) |
private java.util.concurrent.Future<java.lang.Void> |
sendAsyncFrame(WebSocketFrame frame)
Internal
|
void |
sendBytes(java.nio.ByteBuffer data)
Blocking write of bytes.
|
void |
sendBytes(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.
|
void |
sendPartialBytes(java.nio.ByteBuffer fragment,
boolean isLast)
Send a binary message in pieces, blocking until all of the message has been transmitted.
|
void |
sendPartialString(java.lang.String fragment,
boolean isLast)
Send a text message in pieces, blocking until all of the message has been transmitted.
|
void |
sendPing(java.nio.ByteBuffer applicationData)
Send a Ping message containing the given application data to the remote endpoint.
|
void |
sendPong(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.
|
void |
sendString(java.lang.String text)
Send a text message, blocking until all bytes of the message has been transmitted.
|
void |
sendString(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.
|
void |
setBatchMode(BatchMode batchMode)
Set the batch mode with which messages are sent.
|
java.lang.String |
toString() |
void |
uncheckedSendFrame(WebSocketFrame frame,
WriteCallback callback) |
private void |
unlockMsg(WebSocketRemoteEndpoint.MsgType type) |
private static final WriteCallback NOOP_CALLBACK
private static final Logger LOG
private static final int ASYNC_MASK
private static final int BLOCK_MASK
private static final int STREAM_MASK
private static final int PARTIAL_TEXT_MASK
private static final int PARTIAL_BINARY_MASK
private final LogicalConnection connection
private final OutgoingFrames outgoing
private final java.util.concurrent.atomic.AtomicInteger msgState
private final BlockingWriteCallback blocker
private volatile BatchMode batchMode
public WebSocketRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoing)
public WebSocketRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoing, BatchMode batchMode)
private void blockingWrite(WebSocketFrame frame) throws java.io.IOException
java.io.IOException
private boolean lockMsg(WebSocketRemoteEndpoint.MsgType type)
private void unlockMsg(WebSocketRemoteEndpoint.MsgType type)
public java.net.InetSocketAddress getInetSocketAddress()
getInetSocketAddress
in interface RemoteEndpoint
private java.util.concurrent.Future<java.lang.Void> sendAsyncFrame(WebSocketFrame frame)
frame
- the frame to writepublic void sendBytes(java.nio.ByteBuffer data) throws java.io.IOException
sendBytes
in interface RemoteEndpoint
data
- the message to be sentjava.io.IOException
- if unable to send the bytespublic java.util.concurrent.Future<java.lang.Void> sendBytesByFuture(java.nio.ByteBuffer data)
RemoteEndpoint
sendBytesByFuture
in interface RemoteEndpoint
data
- the data being sentpublic void sendBytes(java.nio.ByteBuffer data, WriteCallback callback)
RemoteEndpoint
sendBytes
in interface RemoteEndpoint
data
- the data being sentcallback
- callback to notify of success or failure of the write operationpublic void uncheckedSendFrame(WebSocketFrame frame, WriteCallback callback)
public void sendPartialBytes(java.nio.ByteBuffer fragment, boolean isLast) throws java.io.IOException
RemoteEndpoint
sendPartialBytes
in interface RemoteEndpoint
fragment
- the piece of the message being sentisLast
- true if this is the last piece of the partial bytesjava.io.IOException
- if unable to send the partial bytespublic void sendPartialString(java.lang.String fragment, boolean isLast) throws java.io.IOException
RemoteEndpoint
sendPartialString
in interface RemoteEndpoint
fragment
- the piece of the message being sentisLast
- true if this is the last piece of the partial bytesjava.io.IOException
- if unable to send the partial bytespublic void sendPing(java.nio.ByteBuffer applicationData) throws java.io.IOException
RemoteEndpoint
sendPing
in interface RemoteEndpoint
applicationData
- the data to be carried in the ping requestjava.io.IOException
- if unable to send the pingpublic void sendPong(java.nio.ByteBuffer applicationData) throws java.io.IOException
RemoteEndpoint
sendPong
in interface RemoteEndpoint
applicationData
- the application data to be carried in the pong response.java.io.IOException
- if unable to send the pongpublic void sendString(java.lang.String text) throws java.io.IOException
RemoteEndpoint
Note: this is a blocking call
sendString
in interface RemoteEndpoint
text
- the message to be sentjava.io.IOException
- if unable to send the text messagepublic java.util.concurrent.Future<java.lang.Void> sendStringByFuture(java.lang.String text)
RemoteEndpoint
sendStringByFuture
in interface RemoteEndpoint
text
- the text being sentpublic void sendString(java.lang.String text, WriteCallback callback)
RemoteEndpoint
sendString
in interface RemoteEndpoint
text
- the text being sentcallback
- callback to notify of success or failure of the write operationpublic BatchMode getBatchMode()
getBatchMode
in interface RemoteEndpoint
RemoteEndpoint.flush()
public void setBatchMode(BatchMode batchMode)
RemoteEndpoint
setBatchMode
in interface RemoteEndpoint
batchMode
- the batch mode to useRemoteEndpoint.flush()
public void flush() throws java.io.IOException
RemoteEndpoint
flush
in interface RemoteEndpoint
java.io.IOException
- if the flush failsRemoteEndpoint.getBatchMode()
public java.lang.String toString()
toString
in class java.lang.Object