| Modifier and Type | Interface and Description |
|---|---|
static class |
WebSocket.WebSocketType
Types of WebSocket
|
| Modifier and Type | Method and Description |
|---|---|
void |
addGroup(String group)
Subscribes
this socket to the given group |
CompletableFuture<Void> |
close(WebSocketCloseCode code,
String reason)
Closes
this socket |
List<String> |
getGroups() |
String |
getId() |
WebSocketProtocol |
getProtocol() |
WebSocket.WebSocketType |
getType() |
URI |
getUri() |
boolean |
isClosed()
Tests whether the
close(WebSocketCloseCode, String) method has been called on this instance or not. |
boolean |
isConnected()
Tests whether this socket's connection to the remote system is still active.
|
CompletableFuture<WebSocket> |
reconnect(RetryPolicyTemplate retryPolicyTemplate,
org.mule.runtime.api.scheduler.Scheduler scheduler)
Reconnects by opening a new
WebSocket generated from an HTTP request identical to the one that originally spawned
this one. |
void |
removeGroup(String group)
Unsubscribe
this socket to the given group |
CompletableFuture<Void> |
send(InputStream content,
org.mule.runtime.api.metadata.MediaType mediaType)
Sends the given
content to the remote peer. |
CompletableFuture<Void> |
sendFrame(byte[] frameBytes)
Sends the given frame in its binary representation.
|
boolean |
supportsReconnection()
Tests if
this socket supports reconnection by the means of the reconnect(RetryPolicyTemplate, Scheduler)
method. |
byte[] |
toBinaryFrame(byte[] data,
boolean last)
Transforms the given
data into a binary data frame per the WebSockets specification. |
byte[] |
toTextFrame(String data,
boolean last)
Transforms the given
data into a text data frame per the WebSockets specification. |
String getId()
this socketWebSocket.WebSocketType getType()
this socket's typeWebSocketProtocol getProtocol()
this socket's protocolboolean supportsReconnection()
this socket supports reconnection by the means of the reconnect(RetryPolicyTemplate, Scheduler)
method.this instance.CompletableFuture<WebSocket> reconnect(RetryPolicyTemplate retryPolicyTemplate, org.mule.runtime.api.scheduler.Scheduler scheduler)
WebSocket generated from an HTTP request identical to the one that originally spawned
this one. The new WebSocket will have THE SAME getId() as the original instance.
The term reconnection is not to be interpreted here as in the "socket MUST have had a connectivity issue first". Although recovering from connectivity issues is one of the prime uses of this method, that is not a prerequisite. Invoking this method on a perfectly functioning instance will just spawn a new WebSocket connected to the same remote system. However, be mindful that the new WebSocket will share the same id as this one. Having two active sockets with the same ID might be problematic depending on the use case.
This method does not alter the current state of this instance. It merely generates a new WebSocket similar to
this one.
Not all implementations are required to support this method as it's not possible to do in some cases. The general contract
is that this method should only be called when supportsReconnection() returns true. Invoking this method
on an implementation that doesn't support it will result in a CompletableFuture immediately and exceptionally
completed with an OperationNotSupportedException.
retryPolicyTemplate - the retry policy to use while reconnectingscheduler - the scheduler on which reconnection work should happenCompletableFuture with the newly generated WebSocketList<String> getGroups()
this socket belongs to. Maybe empty but never null.void addGroup(String group)
this socket to the given groupgroup - a group. Not null nor empty.void removeGroup(String group)
this socket to the given groupgroup - a group. Not null nor empty.CompletableFuture<Void> send(InputStream content, org.mule.runtime.api.metadata.MediaType mediaType)
content to the remote peer.content - the content to be sentmediaType - the content's MediaTypeCompletableFutureCompletableFuture<Void> sendFrame(byte[] frameBytes)
The frameBytes passed here are not a binary payload but the complete DataFrame that gets sent through the
wire per the WebSockets specification. This method is useful when the exact same content has to be sent many times
and the actual frame is cached as a performance improvement.
The frameBytes can be (but are not forced to) be generated through the toTextFrame(String, boolean) and
toBinaryFrame(byte[], boolean) methods
frameBytes - a data frame per the WebSocket specificationCompletableFuturebyte[] toTextFrame(String data, boolean last)
data into a text data frame per the WebSockets specification.
The returned frame is the actual set of bytes to be sent through the wire as specified by the protocol. This is not just
a mere binary representation of the data.
The returned frame is to be sent through the sendFrame(byte[]) method. Using this frame as input of the
send(InputStream, MediaType) method will result in a frame wrapping another frame.
data - text to be sentlast - whether the returned frame is the last in a chain of correlated framesbyte[] toBinaryFrame(byte[] data,
boolean last)
data into a binary data frame per the WebSockets specification.
The returned frame is the actual set of bytes to be sent through the wire as specified by the protocol. This is not just
a mere binary representation of the data.
The returned frame is to be sent through the sendFrame(byte[]) method. Using this frame as input of the
send(InputStream, MediaType) method will result in a frame wrapping another frame.
data - binary data to be sentlast - whether the returned frame is the last in a chain of correlated framesCompletableFuture<Void> close(WebSocketCloseCode code, String reason)
this socketcode - WebSocketCloseCode the close codereason - the reason why it's being closedCompletableFutureboolean isClosed()
close(WebSocketCloseCode, String) method has been called on this instance or not.
Notice that this method differs from isConnected() in that even though the socket might not have been closed,
it might still have lost its connection to the remote system. There's no forced correlation between the output values of
both methods.
boolean isConnected()
Notice that this method differs from isClosed() ()} in that even though the socket might not have been closed,
it might still have lost its connection to the remote system. There's no forced correlation between the output values of
both methods.
Copyright © 2003–2020 MuleSoft, Inc.. All rights reserved.