public class WebSocketStompClient extends StompClientSupport implements SmartLifecycle
WebSocketClient
including SockJsClient
.Modifier and Type | Class and Description |
---|---|
private static class |
WebSocketStompClient.StompWebSocketMessageCodec
Encode and decode STOMP WebSocket messages.
|
private class |
WebSocketStompClient.WebSocketTcpConnectionHandlerAdapter
Adapt WebSocket to the TcpConnectionHandler and TcpConnection contracts.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
autoStartup |
private int |
inboundMessageSizeLimit |
private static Log |
logger |
private int |
phase |
private boolean |
running |
private WebSocketClient |
webSocketClient |
Constructor and Description |
---|
WebSocketStompClient(WebSocketClient webSocketClient)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
ListenableFuture<StompSession> |
connect(java.lang.String url,
StompSessionHandler handler,
java.lang.Object... uriVars)
Connect to the given WebSocket URL and notify the given
StompSessionHandler
when connected on the STOMP level after the CONNECTED frame is received. |
ListenableFuture<StompSession> |
connect(java.lang.String url,
WebSocketHttpHeaders handshakeHeaders,
StompHeaders connectHeaders,
StompSessionHandler handler,
java.lang.Object... uriVariables)
An overloaded version of
connect(String, StompSessionHandler, Object...) that also accepts
WebSocketHttpHeaders to use for the WebSocket handshake and
StompHeaders for the STOMP CONNECT frame. |
ListenableFuture<StompSession> |
connect(java.lang.String url,
WebSocketHttpHeaders handshakeHeaders,
StompSessionHandler handler,
java.lang.Object... uriVariables)
An overloaded version of
connect(String, StompSessionHandler, Object...) that also
accepts WebSocketHttpHeaders to use for the WebSocket handshake. |
ListenableFuture<StompSession> |
connect(java.net.URI url,
WebSocketHttpHeaders handshakeHeaders,
StompHeaders connectHeaders,
StompSessionHandler sessionHandler)
An overloaded version of
connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)
that accepts a fully prepared URI . |
int |
getInboundMessageSizeLimit()
Get the configured inbound message buffer size in bytes.
|
int |
getPhase()
Return the configured phase.
|
WebSocketClient |
getWebSocketClient()
Return the configured WebSocketClient.
|
boolean |
isAutoStartup()
Return the value for the 'autoStartup' property.
|
boolean |
isRunning()
Check whether this component is currently running.
|
protected StompHeaders |
processConnectHeaders(StompHeaders connectHeaders)
Further initialize the StompHeaders, for example setting the heart-beat
header if necessary.
|
void |
setAutoStartup(boolean autoStartup)
Set whether to auto-start the contained WebSocketClient when the Spring
context has been refreshed.
|
void |
setInboundMessageSizeLimit(int inboundMessageSizeLimit)
Configure the maximum size allowed for inbound STOMP message.
|
void |
setPhase(int phase)
Specify the phase in which the WebSocket client should be started and
subsequently closed.
|
void |
setTaskScheduler(TaskScheduler taskScheduler)
Configure a scheduler to use for heartbeats and for receipt tracking.
|
void |
start()
Start this component.
|
void |
stop()
Stop this component, typically in a synchronous fashion, such that
the component is fully stopped upon return of this method.
|
void |
stop(java.lang.Runnable callback)
Indicates that a Lifecycle component must stop if it is currently running.
|
createSession, getDefaultHeartbeat, getMessageConverter, getReceiptTimeLimit, getTaskScheduler, isDefaultHeartbeatEnabled, setDefaultHeartbeat, setMessageConverter, setReceiptTimeLimit
private static Log logger
private final WebSocketClient webSocketClient
private int inboundMessageSizeLimit
private boolean autoStartup
private boolean running
private int phase
public WebSocketStompClient(WebSocketClient webSocketClient)
StompClientSupport.setDefaultHeartbeat(long[])
to "0,0" but will
reset it back to the preferred "10000,10000" when a
setTaskScheduler(org.springframework.scheduling.TaskScheduler)
is configured.webSocketClient
- the WebSocket client to connect withpublic WebSocketClient getWebSocketClient()
public void setTaskScheduler(TaskScheduler taskScheduler)
Note: some transports have built-in support to work with heartbeats and therefore do not require a TaskScheduler. Receipts however, if needed, do require a TaskScheduler to be configured.
By default this is not set.
Also automatically sets the defaultHeartbeat
property to "10000,10000" if it is currently set to "0,0".
setTaskScheduler
in class StompClientSupport
public void setInboundMessageSizeLimit(int inboundMessageSizeLimit)
By default this is set to 64 * 1024 (64K).
public int getInboundMessageSizeLimit()
public void setAutoStartup(boolean autoStartup)
Default is "true".
public boolean isAutoStartup()
isAutoStartup
in interface SmartLifecycle
Lifecycle.start()
,
Phased.getPhase()
,
LifecycleProcessor.onRefresh()
,
ConfigurableApplicationContext.refresh()
public boolean isRunning()
Lifecycle
In the case of a container, this will return true
only if all components that apply are currently running.
public void setPhase(int phase)
By default this is Integer.MAX_VALUE meaning that the WebSocket client is started as late as possible and stopped as soon as possible.
public int getPhase()
public void start()
Lifecycle
In the case of a container, this will propagate the start signal to all components that apply.
start
in interface Lifecycle
SmartLifecycle.isAutoStartup()
public void stop()
Lifecycle
SmartLifecycle
and its stop(Runnable)
variant in cases where asynchronous stop behavior is necessary.
Should not throw an exception if the component isn't started yet.
In the case of a container, this will propagate the stop signal to all components that apply.
stop
in interface Lifecycle
SmartLifecycle.stop(Runnable)
public void stop(java.lang.Runnable callback)
SmartLifecycle
The provided callback is used by the LifecycleProcessor
to support
an ordered, and potentially concurrent, shutdown of all components having a
common shutdown order value. The callback must be executed after
the SmartLifecycle
component does indeed stop.
The LifecycleProcessor
will call only this variant of the
stop
method; i.e. Lifecycle.stop()
will not be called for
SmartLifecycle
implementations unless explicitly delegated to within
the implementation of this method.
stop
in interface SmartLifecycle
Lifecycle.stop()
,
Phased.getPhase()
public ListenableFuture<StompSession> connect(java.lang.String url, StompSessionHandler handler, java.lang.Object... uriVars)
StompSessionHandler
when connected on the STOMP level after the CONNECTED frame is received.url
- the url to connect tohandler
- the session handleruriVars
- URI variables to expand into the URLpublic ListenableFuture<StompSession> connect(java.lang.String url, WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, java.lang.Object... uriVariables)
connect(String, StompSessionHandler, Object...)
that also
accepts WebSocketHttpHeaders
to use for the WebSocket handshake.url
- the url to connect tohandshakeHeaders
- the headers for the WebSocket handshakehandler
- the session handleruriVariables
- URI variables to expand into the URLpublic ListenableFuture<StompSession> connect(java.lang.String url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler handler, java.lang.Object... uriVariables)
connect(String, StompSessionHandler, Object...)
that also accepts
WebSocketHttpHeaders
to use for the WebSocket handshake and
StompHeaders
for the STOMP CONNECT frame.url
- the url to connect tohandshakeHeaders
- headers for the WebSocket handshakeconnectHeaders
- headers for the STOMP CONNECT framehandler
- the session handleruriVariables
- URI variables to expand into the URLpublic ListenableFuture<StompSession> connect(java.net.URI url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler sessionHandler)
connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)
that accepts a fully prepared URI
.url
- the url to connect tohandshakeHeaders
- the headers for the WebSocket handshakeconnectHeaders
- headers for the STOMP CONNECT framesessionHandler
- the STOMP session handlerprotected StompHeaders processConnectHeaders(StompHeaders connectHeaders)
StompClientSupport
processConnectHeaders
in class StompClientSupport
connectHeaders
- the headers to modify