类 DefaultStompSession
- java.lang.Object
- org.springframework.messaging.simp.stomp.DefaultStompSession
- 所有已实现的接口:
ConnectionHandlingStompSession,StompSession,TcpConnectionHandler<byte[]>
public class DefaultStompSession extends Object implements ConnectionHandlingStompSession
Default implementation ofConnectionHandlingStompSession.- 从以下版本开始:
- 4.2
- 作者:
- Rossen Stoyanchev
嵌套类概要
从接口继承的嵌套类/接口 org.springframework.messaging.simp.stomp.StompSession
StompSession.Receiptable, StompSession.Subscription
字段概要
字段 修饰符和类型 字段 说明 static byte[]EMPTY_PAYLOADAn empty payload.
构造器概要
构造器 构造器 说明 DefaultStompSession(StompSessionHandler sessionHandler, StompHeaders connectHeaders)Create a new session.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 StompSession.Receiptableacknowledge(String messageId, boolean consumed)Send an acknowledgement whether a message was consumed or not resulting in an ACK or NACK frame respectively.StompSession.Receiptableacknowledge(StompHeaders headers, boolean consumed)An overloaded version ofStompSession.acknowledge(String, boolean)with fullStompHeadersinstead of just amessageId.voidafterConnected(TcpConnection<byte[]> connection)Invoked after a connection is successfully established.voidafterConnectFailure(Throwable ex)Invoked on failure to connect.voidafterConnectionClosed()Invoked after the connection is closed.voiddisconnect()Disconnect the session by sending a DISCONNECT frame.voiddisconnect(StompHeaders headers)Variant ofStompSession.disconnect()with headers.MessageConvertergetMessageConverter()Return the configuredMessageConverter.longgetReceiptTimeLimit()Return the configured time limit before a receipt expires.ListenableFuture<StompSession>getSessionFuture()Return a future that will complete when the session is ready for use.StompSessionHandlergetSessionHandler()Return the configured session handler.StringgetSessionId()Return the id for the session.TaskSchedulergetTaskScheduler()Return the configured TaskScheduler to use for receipt tracking.voidhandleFailure(Throwable ex)Handle a failure on the connection.voidhandleMessage(Message<byte[]> message)Handle a message received from the remote host.booleanisAutoReceiptEnabled()Whether receipt headers should be automatically added.booleanisConnected()Whether the session is connected.StompSession.Receiptablesend(String destination, Object payload)Send a message to the specified destination, converting the payload to abyte[]with the help of aMessageConverter.StompSession.Receiptablesend(StompHeaders headers, Object payload)An overloaded version ofStompSession.send(String, Object)with fullStompHeadersinstead of just a destination.voidsetAutoReceipt(boolean autoReceiptEnabled)When enabled, a receipt header is automatically added to futuresendandsubscribeoperations on this session, which causes the server to return a RECEIPT.voidsetMessageConverter(MessageConverter messageConverter)Set theMessageConverterto use to convert the payload of incoming and outgoing messages to and frombyte[]based on object type, or expected object type, and the "content-type" header.voidsetReceiptTimeLimit(long receiptTimeLimit)Configure the time in milliseconds before a receipt expires.voidsetTaskScheduler(TaskScheduler taskScheduler)Configure the TaskScheduler to use for receipt tracking.StompSession.Subscriptionsubscribe(String destination, StompFrameHandler handler)Subscribe to the given destination by sending a SUBSCRIBE frame and handle received messages with the specifiedStompFrameHandler.StompSession.Subscriptionsubscribe(StompHeaders headers, StompFrameHandler handler)An overloaded version ofStompSession.subscribe(String, StompFrameHandler)with fullStompHeadersinstead of just a destination.
字段详细资料
EMPTY_PAYLOAD
public static final byte[] EMPTY_PAYLOAD
An empty payload.
构造器详细资料
DefaultStompSession
public DefaultStompSession(StompSessionHandler sessionHandler, StompHeaders connectHeaders)
Create a new session.- 参数:
sessionHandler- the application handler for the sessionconnectHeaders- headers for the STOMP CONNECT frame
方法详细资料
getSessionId
public String getSessionId()
从接口复制的说明:StompSessionReturn the id for the session.- 指定者:
getSessionId在接口中StompSession
getSessionHandler
public StompSessionHandler getSessionHandler()
Return the configured session handler.
getSessionFuture
public ListenableFuture<StompSession> getSessionFuture()
从接口复制的说明:ConnectionHandlingStompSessionReturn a future that will complete when the session is ready for use.
setMessageConverter
public void setMessageConverter(MessageConverter messageConverter)
Set theMessageConverterto use to convert the payload of incoming and outgoing messages to and frombyte[]based on object type, or expected object type, and the "content-type" header.By default,
SimpleMessageConverteris configured.- 参数:
messageConverter- the message converter to use
getMessageConverter
public MessageConverter getMessageConverter()
Return the configuredMessageConverter.
setTaskScheduler
public void setTaskScheduler(@Nullable TaskScheduler taskScheduler)
Configure the TaskScheduler to use for receipt tracking.
getTaskScheduler
@Nullable public TaskScheduler getTaskScheduler()
Return the configured TaskScheduler to use for receipt tracking.
setReceiptTimeLimit
public void setReceiptTimeLimit(long receiptTimeLimit)
Configure the time in milliseconds before a receipt expires.By default set to 15,000 (15 seconds).
getReceiptTimeLimit
public long getReceiptTimeLimit()
Return the configured time limit before a receipt expires.
setAutoReceipt
public void setAutoReceipt(boolean autoReceiptEnabled)
从接口复制的说明:StompSessionWhen enabled, a receipt header is automatically added to futuresendandsubscribeoperations on this session, which causes the server to return a RECEIPT. An application can then use theReceiptablereturned from the operation to track the receipt.A receipt header can also be added manually through the overloaded methods that accept
StompHeaders.- 指定者:
setAutoReceipt在接口中StompSession
isAutoReceiptEnabled
public boolean isAutoReceiptEnabled()
Whether receipt headers should be automatically added.
isConnected
public boolean isConnected()
从接口复制的说明:StompSessionWhether the session is connected.- 指定者:
isConnected在接口中StompSession
send
public StompSession.Receiptable send(String destination, Object payload)
从接口复制的说明:StompSessionSend a message to the specified destination, converting the payload to abyte[]with the help of aMessageConverter.- 指定者:
send在接口中StompSession- 参数:
destination- the destination to send a message topayload- the message payload- 返回:
- a Receiptable for tracking receipts
send
public StompSession.Receiptable send(StompHeaders headers, Object payload)
从接口复制的说明:StompSessionAn overloaded version ofStompSession.send(String, Object)with fullStompHeadersinstead of just a destination. The headers must contain a destination and may also have other headers such as "content-type" or custom headers for the broker to propagate to subscribers, or broker-specific, non-standard headers.- 指定者:
send在接口中StompSession- 参数:
headers- the message headerspayload- the message payload- 返回:
- a Receiptable for tracking receipts
subscribe
public StompSession.Subscription subscribe(String destination, StompFrameHandler handler)
从接口复制的说明:StompSessionSubscribe to the given destination by sending a SUBSCRIBE frame and handle received messages with the specifiedStompFrameHandler.- 指定者:
subscribe在接口中StompSession- 参数:
destination- the destination to subscribe tohandler- the handler for received messages- 返回:
- a handle to use to unsubscribe and/or track receipts
subscribe
public StompSession.Subscription subscribe(StompHeaders headers, StompFrameHandler handler)
从接口复制的说明:StompSessionAn overloaded version ofStompSession.subscribe(String, StompFrameHandler)with fullStompHeadersinstead of just a destination.- 指定者:
subscribe在接口中StompSession- 参数:
headers- the headers for the subscribe message framehandler- the handler for received messages- 返回:
- a handle to use to unsubscribe and/or track receipts
acknowledge
public StompSession.Receiptable acknowledge(String messageId, boolean consumed)
从接口复制的说明:StompSessionSend an acknowledgement whether a message was consumed or not resulting in an ACK or NACK frame respectively.Note: to use this when subscribing you must set the
ackheader to "client" or "client-individual" in order ot use this.- 指定者:
acknowledge在接口中StompSession- 参数:
messageId- the id of the messageconsumed- whether the message was consumed or not- 返回:
- a Receiptable for tracking receipts
acknowledge
public StompSession.Receiptable acknowledge(StompHeaders headers, boolean consumed)
从接口复制的说明:StompSessionAn overloaded version ofStompSession.acknowledge(String, boolean)with fullStompHeadersinstead of just amessageId.- 指定者:
acknowledge在接口中StompSession- 参数:
headers- the headers for the ACK or NACK message frameconsumed- whether the message was consumed or not- 返回:
- a Receiptable for tracking receipts
disconnect
public void disconnect()
从接口复制的说明:StompSessionDisconnect the session by sending a DISCONNECT frame.- 指定者:
disconnect在接口中StompSession
disconnect
public void disconnect(@Nullable StompHeaders headers)
从接口复制的说明:StompSessionVariant ofStompSession.disconnect()with headers.- 指定者:
disconnect在接口中StompSession- 参数:
headers- the headers for the disconnect message frame
afterConnected
public void afterConnected(TcpConnection<byte[]> connection)
从接口复制的说明:TcpConnectionHandlerInvoked after a connection is successfully established.- 指定者:
afterConnected在接口中TcpConnectionHandler<byte[]>- 参数:
connection- the connection
afterConnectFailure
public void afterConnectFailure(Throwable ex)
从接口复制的说明:TcpConnectionHandlerInvoked on failure to connect.- 指定者:
afterConnectFailure在接口中TcpConnectionHandler<byte[]>- 参数:
ex- the exception
handleMessage
public void handleMessage(Message<byte[]> message)
从接口复制的说明:TcpConnectionHandlerHandle a message received from the remote host.- 指定者:
handleMessage在接口中TcpConnectionHandler<byte[]>- 参数:
message- the message
handleFailure
public void handleFailure(Throwable ex)
从接口复制的说明:TcpConnectionHandlerHandle a failure on the connection.- 指定者:
handleFailure在接口中TcpConnectionHandler<byte[]>- 参数:
ex- the exception
afterConnectionClosed
public void afterConnectionClosed()
从接口复制的说明:TcpConnectionHandlerInvoked after the connection is closed.- 指定者:
afterConnectionClosed在接口中TcpConnectionHandler<byte[]>