public class JettyWebSocketClient extends AbstractWebSocketClient implements Lifecycle
As of 4.1 this class implements Lifecycle
rather than
SmartLifecycle
. Use
WebSocketConnectionManager
instead to auto-start a WebSocket connection.
logger
Constructor and Description |
---|
JettyWebSocketClient()
Default constructor that creates an instance of
WebSocketClient . |
JettyWebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient client)
Constructor that accepts an existing
WebSocketClient instance. |
Modifier and Type | Method and Description |
---|---|
ListenableFuture<WebSocketSession> |
doHandshake(WebSocketHandler webSocketHandler,
java.lang.String uriTemplate,
java.lang.Object... uriVars) |
ListenableFuture<WebSocketSession> |
doHandshakeInternal(WebSocketHandler wsHandler,
HttpHeaders headers,
java.net.URI uri,
java.util.List<java.lang.String> protocols,
java.util.List<WebSocketExtension> extensions,
java.util.Map<java.lang.String,java.lang.Object> attributes)
Perform the actual handshake to establish a connection to the server.
|
AsyncListenableTaskExecutor |
getTaskExecutor()
Return the configured
TaskExecutor . |
protected java.security.Principal |
getUser() |
boolean |
isRunning()
Check whether this component is currently running.
|
void |
setTaskExecutor(AsyncListenableTaskExecutor taskExecutor)
Set an
AsyncListenableTaskExecutor to use when opening connections. |
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.
|
assertUri, doHandshake
public JettyWebSocketClient()
WebSocketClient
.public JettyWebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient client)
WebSocketClient
instance.public void setTaskExecutor(@Nullable AsyncListenableTaskExecutor taskExecutor)
AsyncListenableTaskExecutor
to use when opening connections.
If this property is set to null
, calls to any of the
doHandshake
methods will block until the connection is established.
By default an instance of SimpleAsyncTaskExecutor
is used.
@Nullable public AsyncListenableTaskExecutor getTaskExecutor()
TaskExecutor
.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 start()
Lifecycle
Should not throw an exception if the component is already running.
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 when asynchronous stop behavior is necessary.
Note that this stop notification is not guaranteed to come before destruction: On
regular shutdown, Lifecycle
beans will first receive a stop notification before
the general destruction callbacks are being propagated; however, on hot refresh during a
context's lifetime or on aborted refresh attempts, only destroy methods will be called.
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)
,
DisposableBean.destroy()
public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler, java.lang.String uriTemplate, java.lang.Object... uriVars)
doHandshake
in interface WebSocketClient
doHandshake
in class AbstractWebSocketClient
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler, HttpHeaders headers, java.net.URI uri, java.util.List<java.lang.String> protocols, java.util.List<WebSocketExtension> extensions, java.util.Map<java.lang.String,java.lang.Object> attributes)
AbstractWebSocketClient
doHandshakeInternal
in class AbstractWebSocketClient
wsHandler
- the client-side handler for WebSocket messagesheaders
- HTTP headers to use for the handshake, with unwanted (forbidden)
headers filtered out (never null
)uri
- the target URI for the handshake (never null
)protocols
- requested sub-protocols, or an empty listextensions
- requested WebSocket extensions, or an empty listattributes
- attributes to associate with the WebSocketSession, i.e. via
WebSocketSession.getAttributes()
; currently always an empty map.@Nullable protected java.security.Principal getUser()
WebSocketSession.getPrincipal()
;
by default this method returns null