public class FluxCapacitor extends Object
| Constructor and Description |
|---|
FluxCapacitor(WebSocketServer webSocketServer,
WebSocketClient webSocketClient,
org.mule.runtime.http.api.HttpService httpService,
org.mule.runtime.api.scheduler.Scheduler reconnectionScheduler) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
broadcast(org.mule.runtime.api.metadata.TypedValue<InputStream> content,
String path,
Predicate<org.mule.runtime.http.api.ws.WebSocket> socketFilter,
org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate retryPolicyTemplate,
BiConsumer<org.mule.runtime.http.api.ws.WebSocket,Throwable> errorCallback) |
CompletableFuture<Void> |
bulkCloseSockets(Predicate<org.mule.runtime.http.api.ws.WebSocket> socketFilter,
org.mule.runtime.http.api.ws.WebSocketCloseCode closeCode,
String reason) |
void |
close()
Closes this capacitor, closing all the registered sockets using an
WebSocketCloseCode.ENDPOINT_GOING_DOWN code
and stopping the underlying HttpClient. |
CompletableFuture<Void> |
close(String socketId,
org.mule.runtime.http.api.ws.WebSocketCloseCode closeCode,
String reason)
Closes the socket of the given
socketId. |
Optional<ForwardingWebSocketHandler> |
getInboundHandler(String path)
Returns the
ForwardingWebSocketHandler associated to the given path if present. |
OutboundSocketListener |
getOutboundSocketListener() |
Optional<WebSocketClient> |
getWebSocketClient() |
Optional<WebSocketServer> |
getWebSocketServer() |
org.mule.runtime.http.api.ws.WebSocket |
lookupWebSocket(String socketId)
Returns the
WebSocket for the given socketId |
void |
notifyClosed(org.mule.runtime.http.api.ws.WebSocket socket,
org.mule.runtime.http.api.ws.WebSocketCloseCode code,
String reason,
boolean unregister)
Notifies that the given
socket has just been closed. |
void |
notifyOpen(WebSocketState state)
Notifies that a socket has been opened.
|
CompletableFuture<WebSocketAttributes> |
openOutboundSocket(WebSocketsConnector config,
org.mule.runtime.http.api.client.HttpClient client,
org.mule.runtime.http.api.domain.message.request.HttpRequest request,
List<String> defaultGroups,
Optional<String> socketId,
int responseTimeout)
Opens an outbound socket
|
CompletableFuture<org.mule.runtime.http.api.ws.WebSocket> |
reconnectOnFailure(String socketId,
org.mule.runtime.http.api.ws.exception.WebSocketConnectionException e,
org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate retryPolicyTemplate)
Reconnects the referenced socket, provided it supports reconnection to begin with.
|
CompletableFuture<org.mule.runtime.http.api.ws.WebSocket> |
reconnectOnFailure(String socketId,
org.mule.runtime.http.api.ws.exception.WebSocketConnectionException e,
org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate retryPolicyTemplate,
org.mule.runtime.api.scheduler.Scheduler scheduler)
Reconnects the referenced socket, provided it supports reconnection to begin with.
|
void |
registerInboundHandler(String path,
ForwardingWebSocketHandler handler)
Registers the given
handler to the given path. |
void |
registerOnCloseCallback(String path,
OnCloseCallback callback)
Registers a callback that will be invoked whenever a
WebSocket with a matching path is closed. |
CompletableFuture<Void> |
send(String socketId,
InputStream content,
org.mule.runtime.api.metadata.MediaType mediaType)
Sends the given
content through the socket of the given socketId. |
CompletableFuture<Void> |
send(org.mule.runtime.http.api.ws.WebSocket socket,
InputStream content,
org.mule.runtime.api.metadata.MediaType mediaType)
Sends the given
content through the socket of the given socket. |
void |
subscribeGroups(org.mule.runtime.http.api.ws.WebSocket socket,
List<String> groups)
Subscribes the given
socket to the specified groups |
void |
unregisterInboundHandler(String path)
Unregisters the
ForwardingWebSocketHandler of the given path |
void |
unregisterOnCloseCallback(String path,
OnCloseCallback callback)
Unregisters the given
callback, provided that it has previously been registered through
registerOnCloseCallback(String, OnCloseCallback) with an equivalent path. |
WebSocketClient |
unsafeGetWebSocketClient(WebSocketsConnector config) |
WebSocketServer |
unsafeGetWebSocketServer(WebSocketsConnector config) |
void |
unsubscribeGroups(org.mule.runtime.http.api.ws.WebSocket socket,
List<String> groups)
Unsubscribe the given
socket from the specified groups |
public FluxCapacitor(WebSocketServer webSocketServer, WebSocketClient webSocketClient, org.mule.runtime.http.api.HttpService httpService, org.mule.runtime.api.scheduler.Scheduler reconnectionScheduler)
public CompletableFuture<WebSocketAttributes> openOutboundSocket(WebSocketsConnector config, org.mule.runtime.http.api.client.HttpClient client, org.mule.runtime.http.api.domain.message.request.HttpRequest request, List<String> defaultGroups, Optional<String> socketId, int responseTimeout)
config - the connector's configclient - the HttpClient used to open the connectionrequest - the initiating HttpRequestdefaultGroups - the groups to which the socket should be initially subscribed to.responseTimeout - connection timeoutWebSocketAttributespublic CompletableFuture<Void> send(String socketId, InputStream content, org.mule.runtime.api.metadata.MediaType mediaType)
content through the socket of the given socketId. This method works for both inbound
and outbound socketssocketId - the socket idcontent - the content to be sentmediaType - the content's MediaTypeCompletableFutureNoSuchSocketException - if no socket matches the socketIdpublic CompletableFuture<Void> send(org.mule.runtime.http.api.ws.WebSocket socket, InputStream content, org.mule.runtime.api.metadata.MediaType mediaType)
content through the socket of the given socket. This method works for both inbound
and outbound socketssocket - the socketcontent - the content to be sentmediaType - the content's MediaTypeCompletableFutureNoSuchSocketException - if no socket matches the socketIdpublic CompletableFuture<Void> broadcast(org.mule.runtime.api.metadata.TypedValue<InputStream> content, String path, Predicate<org.mule.runtime.http.api.ws.WebSocket> socketFilter, org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate retryPolicyTemplate, BiConsumer<org.mule.runtime.http.api.ws.WebSocket,Throwable> errorCallback)
public CompletableFuture<Void> bulkCloseSockets(Predicate<org.mule.runtime.http.api.ws.WebSocket> socketFilter, org.mule.runtime.http.api.ws.WebSocketCloseCode closeCode, String reason)
public void registerOnCloseCallback(String path, OnCloseCallback callback)
WebSocket with a matching path is closed.
Multiple invocations to equivalent paths are allowed, in which case the callbacks will be executed in order. Both inbound and outbound sockets will be matched
path - the socket path to matchcallback - the callbackpublic void unregisterOnCloseCallback(String path, OnCloseCallback callback)
callback, provided that it has previously been registered through
registerOnCloseCallback(String, OnCloseCallback) with an equivalent path.path - the socket path to matchcallback - the callbackpublic CompletableFuture<Void> close(String socketId, org.mule.runtime.http.api.ws.WebSocketCloseCode closeCode, String reason)
socketId. This method works for both inbound and outbound socketssocketId - the id of the socket to closecloseCode - the WebSocketCloseCodereason - the reason phraseCompletableFutureNoSuchSocketException - if no socket matches the socketIdpublic void registerInboundHandler(String path, ForwardingWebSocketHandler handler)
handler to the given path.path - the endpoint's pathhandler - a ForwardingWebSocketHandlerpublic void unregisterInboundHandler(String path)
ForwardingWebSocketHandler of the given pathpath - the endpoint's pathpublic Optional<ForwardingWebSocketHandler> getInboundHandler(String path)
ForwardingWebSocketHandler associated to the given path if present.path - the endpoint's pathOptional ForwardingWebSocketHandlerpublic void subscribeGroups(org.mule.runtime.http.api.ws.WebSocket socket,
List<String> groups)
socket to the specified groupssocket - a WebSocketgroups - a list of groupspublic CompletableFuture<org.mule.runtime.http.api.ws.WebSocket> reconnectOnFailure(String socketId, org.mule.runtime.http.api.ws.exception.WebSocketConnectionException e, org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate retryPolicyTemplate)
socketId - the id of the socket to be reconnectede - the exception that triggered the need to reconnectretryPolicyTemplate - the reconnection policyCompletableFuture with the newly obtained socketpublic CompletableFuture<org.mule.runtime.http.api.ws.WebSocket> reconnectOnFailure(String socketId, org.mule.runtime.http.api.ws.exception.WebSocketConnectionException e, org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate retryPolicyTemplate, org.mule.runtime.api.scheduler.Scheduler scheduler)
socketId - the id of the socket to be reconnectede - the exception that triggered the need to reconnectretryPolicyTemplate - the reconnection policyscheduler - the scheduler on which reconnection work is to be submittedCompletableFuture with the newly obtained socketpublic void unsubscribeGroups(org.mule.runtime.http.api.ws.WebSocket socket,
List<String> groups)
socket from the specified groupssocket - a WebSocketgroups - a list of groupspublic OutboundSocketListener getOutboundSocketListener()
OutboundSocketListenerpublic void notifyOpen(WebSocketState state)
state - a just opened WebSocketStatepublic void notifyClosed(org.mule.runtime.http.api.ws.WebSocket socket,
org.mule.runtime.http.api.ws.WebSocketCloseCode code,
String reason,
boolean unregister)
socket has just been closed. This method MUST be invoked for all closed sockets,
regardless of their types.socket - a just closed WebSocketcode - the close codereason - the reason phraseunregister - whether the socket should be unregister or a reference to it should still be keptpublic void close()
WebSocketCloseCode.ENDPOINT_GOING_DOWN code
and stopping the underlying HttpClient.
This operation is irreversible, a new FluxCapacitor must be created after this.
public org.mule.runtime.http.api.ws.WebSocket lookupWebSocket(String socketId)
WebSocket for the given socketIdsocketId - the socket's idWebSocketNoSuchSocketException - if the socket doesn't existspublic Optional<WebSocketServer> getWebSocketServer()
public Optional<WebSocketClient> getWebSocketClient()
public WebSocketServer unsafeGetWebSocketServer(WebSocketsConnector config)
public WebSocketClient unsafeGetWebSocketClient(WebSocketsConnector config)
Copyright © 2024 MuleSoft, Inc.. All rights reserved.