类 JettyWebSocketClient
- java.lang.Object
- org.springframework.web.socket.client.AbstractWebSocketClient
- org.springframework.web.socket.client.jetty.JettyWebSocketClient
- 所有已实现的接口:
Lifecycle,WebSocketClient
public class JettyWebSocketClient extends AbstractWebSocketClient implements Lifecycle
Initiates WebSocket requests to a WebSocket server programmatically through the Jetty WebSocket API.As of 4.1 this class implements
Lifecyclerather thanSmartLifecycle. UseWebSocketConnectionManagerinstead to auto-start a WebSocket connection.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
字段概要
从类继承的字段 org.springframework.web.socket.client.AbstractWebSocketClient
logger
构造器概要
构造器 构造器 说明 JettyWebSocketClient()Default constructor that creates an instance ofWebSocketClient.JettyWebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient client)Constructor that accepts an existingWebSocketClientinstance.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ListenableFuture<WebSocketSession>doHandshake(WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVars)ListenableFuture<WebSocketSession>doHandshakeInternal(WebSocketHandler wsHandler, HttpHeaders headers, URI uri, List<String> protocols, List<WebSocketExtension> extensions, Map<String,Object> attributes)Perform the actual handshake to establish a connection to the server.AsyncListenableTaskExecutorgetTaskExecutor()Return the configuredTaskExecutor.protected PrincipalgetUser()booleanisRunning()Check whether this component is currently running.voidsetTaskExecutor(AsyncListenableTaskExecutor taskExecutor)Set anAsyncListenableTaskExecutorto use when opening connections.voidstart()Start this component.voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.从类继承的方法 org.springframework.web.socket.client.AbstractWebSocketClient
assertUri, doHandshake
构造器详细资料
JettyWebSocketClient
public JettyWebSocketClient()
Default constructor that creates an instance ofWebSocketClient.
JettyWebSocketClient
public JettyWebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient client)
Constructor that accepts an existingWebSocketClientinstance.
方法详细资料
setTaskExecutor
public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor)
Set anAsyncListenableTaskExecutorto use when opening connections. If this property is set tonull, calls to any of thedoHandshakemethods will block until the connection is established.By default an instance of
SimpleAsyncTaskExecutoris used.
getTaskExecutor
public AsyncListenableTaskExecutor getTaskExecutor()
Return the configuredTaskExecutor.
start
public void start()
从接口复制的说明:LifecycleStart this component.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在接口中Lifecycle- 另请参阅:
SmartLifecycle.isAutoStartup()
stop
public void stop()
从接口复制的说明:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecyclebeans 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, a given bean's destroy method will be called without any consideration of stop signals upfront.Should not throw an exception if the component is not running (not started yet).
In the case of a container, this will propagate the stop signal to all components that apply.
- 指定者:
stop在接口中Lifecycle- 另请参阅:
SmartLifecycle.stop(Runnable),DisposableBean.destroy()
isRunning
public boolean isRunning()
从接口复制的说明:LifecycleCheck whether this component is currently running.In the case of a container, this will return
trueonly if all components that apply are currently running.
doHandshake
public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVars)
- 指定者:
doHandshake在接口中WebSocketClient- 覆盖:
doHandshake在类中AbstractWebSocketClient
doHandshakeInternal
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler, HttpHeaders headers, URI uri, List<String> protocols, List<WebSocketExtension> extensions, Map<String,Object> attributes)
从类复制的说明:AbstractWebSocketClientPerform the actual handshake to establish a connection to the server.- 指定者:
doHandshakeInternal在类中AbstractWebSocketClient- 参数:
wsHandler- the client-side handler for WebSocket messagesheaders- HTTP headers to use for the handshake, with unwanted (forbidden) headers filtered out, nevernulluri- the target URI for the handshake, nevernullprotocols- requested sub-protocols, or an empty listextensions- requested WebSocket extensions, or an empty listattributes- attributes to associate with the WebSocketSession, i.e. viaWebSocketSession.getAttributes(); currently always an empty map.- 返回:
- the established WebSocket session wrapped in a ListenableFuture.
getUser
protected Principal getUser()
- 返回:
- the user to make available through
WebSocketSession.getPrincipal(); by default this method returnsnull