类 HandshakeWebSocketService
- java.lang.Object
- org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService
- 所有已实现的接口:
Lifecycle
,WebSocketService
public class HandshakeWebSocketService extends Object implements WebSocketService, Lifecycle
WebSocketService
implementation that handles a WebSocket HTTP handshake request by delegating to aRequestUpgradeStrategy
which is either auto-detected (no-arg constructor) from the classpath but can also be explicitly configured.- 从以下版本开始:
- 5.0
- 作者:
- Rossen Stoyanchev
构造器概要
构造器 构造器 说明 HandshakeWebSocketService()
Default constructor automatic, classpath detection based discovery of theRequestUpgradeStrategy
to use.HandshakeWebSocketService(RequestUpgradeStrategy upgradeStrategy)
Alternative constructor with theRequestUpgradeStrategy
to use.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
doStart()
protected void
doStop()
Predicate<String>
getSessionAttributePredicate()
Return the configured predicate for initialization WebSocket session attributes fromWebSession
attributes.RequestUpgradeStrategy
getUpgradeStrategy()
Return theRequestUpgradeStrategy
for WebSocket requests.reactor.core.publisher.Mono<Void>
handleRequest(ServerWebExchange exchange, WebSocketHandler handler)
Handle the request with the givenWebSocketHandler
.boolean
isRunning()
Check whether this component is currently running.void
setSessionAttributePredicate(Predicate<String> predicate)
Configure a predicate to use to extractWebSession
attributes and use them to initialize the WebSocket session with.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.
构造器详细资料
HandshakeWebSocketService
public HandshakeWebSocketService()
Default constructor automatic, classpath detection based discovery of theRequestUpgradeStrategy
to use.
HandshakeWebSocketService
public HandshakeWebSocketService(RequestUpgradeStrategy upgradeStrategy)
Alternative constructor with theRequestUpgradeStrategy
to use.- 参数:
upgradeStrategy
- the strategy to use
方法详细资料
getUpgradeStrategy
public RequestUpgradeStrategy getUpgradeStrategy()
Return theRequestUpgradeStrategy
for WebSocket requests.
setSessionAttributePredicate
public void setSessionAttributePredicate(@Nullable Predicate<String> predicate)
Configure a predicate to use to extractWebSession
attributes and use them to initialize the WebSocket session with.By default this is not set in which case no attributes are passed.
- 参数:
predicate
- the predicate- 从以下版本开始:
- 5.1
getSessionAttributePredicate
@Nullable public Predicate<String> getSessionAttributePredicate()
Return the configured predicate for initialization WebSocket session attributes fromWebSession
attributes.- 从以下版本开始:
- 5.1
start
public void start()
从接口复制的说明:Lifecycle
Start 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()
doStart
protected void doStart()
stop
public void stop()
从接口复制的说明:Lifecycle
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycle
and itsstop(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, 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()
doStop
protected void doStop()
isRunning
public boolean isRunning()
从接口复制的说明:Lifecycle
Check whether this component is currently running.In the case of a container, this will return
true
only if all components that apply are currently running.
handleRequest
public reactor.core.publisher.Mono<Void> handleRequest(ServerWebExchange exchange, WebSocketHandler handler)
从接口复制的说明:WebSocketService
Handle the request with the givenWebSocketHandler
.- 指定者:
handleRequest
在接口中WebSocketService
- 参数:
exchange
- the current exchangehandler
- handler for WebSocket session- 返回:
- a
Mono<Void>
that completes when application handling of the WebSocket session completes.