类 PerConnectionWebSocketHandler
- java.lang.Object
- org.springframework.web.socket.handler.PerConnectionWebSocketHandler
- 所有已实现的接口:
Aware,BeanFactoryAware,WebSocketHandler
public class PerConnectionWebSocketHandler extends Object implements WebSocketHandler, BeanFactoryAware
AWebSocketHandlerthat initializes and destroys aWebSocketHandlerinstance for each WebSocket connection and delegates all other methods to it.Essentially create an instance of this class once, providing the type of
WebSocketHandlerclass to create for each connection, and then pass it to any API method that expects aWebSocketHandler.If initializing the target
WebSocketHandlertype requires a Spring BeanFctory, then thesetBeanFactory(BeanFactory)property accordingly. Simply declaring this class as a Spring bean will do that. Otherwise,WebSocketHandlerinstances of the target type will be created using the default constructor.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
构造器概要
构造器 构造器 说明 PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType)PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType, boolean supportsPartialMessages)
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterConnectionClosed(WebSocketSession session, CloseStatus closeStatus)Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred.voidafterConnectionEstablished(WebSocketSession session)Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.voidhandleMessage(WebSocketSession session, WebSocketMessage<?> message)Invoked when a new WebSocket message arrives.voidhandleTransportError(WebSocketSession session, Throwable exception)Handle an error from the underlying WebSocket message transport.voidsetBeanFactory(BeanFactory beanFactory)Callback that supplies the owning factory to a bean instance.booleansupportsPartialMessages()Whether the WebSocketHandler handles partial messages.StringtoString()
构造器详细资料
PerConnectionWebSocketHandler
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType)
PerConnectionWebSocketHandler
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType, boolean supportsPartialMessages)
方法详细资料
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
从接口复制的说明:BeanFactoryAwareCallback that supplies the owning factory to a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean.afterPropertiesSet()or a custom init-method.- 指定者:
setBeanFactory在接口中BeanFactoryAware- 参数:
beanFactory- owning BeanFactory (nevernull). The bean can immediately call methods on the factory.- 另请参阅:
BeanInitializationException
afterConnectionEstablished
public void afterConnectionEstablished(WebSocketSession session) throws Exception
从接口复制的说明:WebSocketHandlerInvoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.- 指定者:
afterConnectionEstablished在接口中WebSocketHandler- 抛出:
Exception- this method can handle or propagate exceptions; see class-level Javadoc for details.
handleMessage
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception
从接口复制的说明:WebSocketHandlerInvoked when a new WebSocket message arrives.- 指定者:
handleMessage在接口中WebSocketHandler- 抛出:
Exception- this method can handle or propagate exceptions; see class-level Javadoc for details.
handleTransportError
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception
从接口复制的说明:WebSocketHandlerHandle an error from the underlying WebSocket message transport.- 指定者:
handleTransportError在接口中WebSocketHandler- 抛出:
Exception- this method can handle or propagate exceptions; see class-level Javadoc for details.
afterConnectionClosed
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception
从接口复制的说明:WebSocketHandlerInvoked after the WebSocket connection has been closed by either side, or after a transport error has occurred. Although the session may technically still be open, depending on the underlying implementation, sending messages at this point is discouraged and most likely will not succeed.- 指定者:
afterConnectionClosed在接口中WebSocketHandler- 抛出:
Exception- this method can handle or propagate exceptions; see class-level Javadoc for details.
supportsPartialMessages
public boolean supportsPartialMessages()
从接口复制的说明:WebSocketHandlerWhether the WebSocketHandler handles partial messages. If this flag is set totrueand the underlying WebSocket server supports partial messages, then a large WebSocket message, or one of an unknown size may be split and maybe received over multiple calls toWebSocketHandler.handleMessage(WebSocketSession, WebSocketMessage). The flagWebSocketMessage.isLast()indicates if the message is partial and whether it is the last part.- 指定者:
supportsPartialMessages在接口中WebSocketHandler