-
- All Implemented Interfaces:
-
com.mobwith.httpmodule.WebSocket,com.mobwith.httpmodule.internal.ws.WebSocketReader.FrameCallback
public final class RealWebSocket implements WebSocket, WebSocketReader.FrameCallback
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public abstract classRealWebSocket.Streams
-
Constructor Summary
Constructors Constructor Description RealWebSocket(MobonRequest mobonRequest, WebSocketListener listener, Random random, long pingIntervalMillis)
-
Method Summary
Modifier and Type Method Description MobonRequestrequest()Returns the original mobonRequest that initiated this web socket. synchronized longqueueSize()Returns the size in bytes of all messages enqueued to be transmitted to the server. voidcancel()Immediately and violently release resources held by this web socket, discarding any enqueuedmessages. voidconnect(MobonOkHttpClient client)voidinitReaderAndWriter(String name, RealWebSocket.Streams streams)voidloopReader()Receive frames until there are no more. voidonReadMessage(String text)voidonReadMessage(ByteString bytes)synchronized voidonReadPing(ByteString payload)synchronized voidonReadPong(ByteString buffer)voidonReadClose(int code, String reason)booleansend(String text)Attempts to enqueue {@code text}to be UTF-8 encoded and sent as a the data of a text (type{@code 0x1}) message.booleansend(ByteString bytes)Attempts to enqueue {@code bytes}to be sent as a the data of a binary (type{@code 0x2})message.booleanclose(int code, String reason)Attempts to initiate a graceful shutdown of this web socket. voidfailWebSocket(Exception e, @Nullable() MobonResponse mobonResponse)-
Methods inherited from class com.mobwith.httpmodule.WebSocket
close -
Methods inherited from class com.mobwith.httpmodule.internal.ws.WebSocketReader.FrameCallback
onReadPing -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
RealWebSocket
RealWebSocket(MobonRequest mobonRequest, WebSocketListener listener, Random random, long pingIntervalMillis)
-
-
Method Detail
-
request
MobonRequest request()
Returns the original mobonRequest that initiated this web socket.
-
queueSize
synchronized long queueSize()
Returns the size in bytes of all messages enqueued to be transmitted to the server. Thisdoesn't include framing overhead. It also doesn't include any bytes buffered by the operatingsystem or network intermediaries. This method returns 0 if no messages are waitingin the queue. If may return a nonzero value after the web socket has been canceled; thisindicates that enqueued messages were not transmitted.
-
cancel
void cancel()
Immediately and violently release resources held by this web socket, discarding any enqueuedmessages. This does nothing if the web socket has already been closed or canceled.
-
connect
void connect(MobonOkHttpClient client)
-
initReaderAndWriter
void initReaderAndWriter(String name, RealWebSocket.Streams streams)
-
loopReader
void loopReader()
Receive frames until there are no more. Invoked only by the reader thread.
-
onReadMessage
void onReadMessage(String text)
-
onReadMessage
void onReadMessage(ByteString bytes)
-
onReadPing
synchronized void onReadPing(ByteString payload)
-
onReadPong
synchronized void onReadPong(ByteString buffer)
-
onReadClose
void onReadClose(int code, String reason)
-
send
boolean send(String text)
Attempts to enqueue
{@code text}to be UTF-8 encoded and sent as a the data of a text (type{@code 0x1}) message.This method returns true if the message was enqueued. Messages that would overflow theoutgoing message buffer will be rejected and trigger a graceful shutdown ofthis web socket. This method returns false in that case, and in any other case where thisweb socket is closing, closed, or canceled.
This method returns immediately.
-
send
boolean send(ByteString bytes)
Attempts to enqueue
{@code bytes}to be sent as a the data of a binary (type{@code 0x2})message.This method returns true if the message was enqueued. Messages that would overflow theoutgoing message buffer (16 MiB) will be rejected and trigger a graceful shutdown of this web socket. This method returns false in thatcase, and in any other case where this web socket is closing, closed, or canceled.
This method returns immediately.
-
close
boolean close(int code, String reason)
Attempts to initiate a graceful shutdown of this web socket. Any already-enqueued messages willbe transmitted before the close message is sent but subsequent calls to send willreturn false and their messages will not be enqueued.
This returns true if a graceful shutdown was initiated by this call. It returns false and ifa graceful shutdown was already underway or if the web socket is already closed or canceled.
- Parameters:
code- Status code as defined by Section 7.4 of RFC 6455.reason- Reason for shutting down or{@code null}.
-
failWebSocket
void failWebSocket(Exception e, @Nullable() MobonResponse mobonResponse)
-
-
-
-