public class DefaultStompSession extends Object implements ConnectionHandlingStompSession
ConnectionHandlingStompSession.StompSession.Receiptable, StompSession.Subscription| Modifier and Type | Field and Description |
|---|---|
static byte[] |
EMPTY_PAYLOAD |
| Constructor and Description |
|---|
DefaultStompSession(StompSessionHandler sessionHandler,
StompHeaders connectHeaders)
Create a new session.
|
| Modifier and Type | Method and Description |
|---|---|
StompSession.Receiptable |
acknowledge(String messageId,
boolean consumed)
Send an acknowledgement whether a message was consumed or not resulting
in an ACK or NACK frame respectively.
|
void |
afterConnected(TcpConnection<byte[]> connection)
Invoked after a connection is successfully established.
|
void |
afterConnectFailure(Throwable ex)
Invoked on failure to connect.
|
void |
afterConnectionClosed()
Invoked after the connection is closed.
|
void |
disconnect()
Disconnect the session by sending a DISCONNECT frame.
|
MessageConverter |
getMessageConverter()
Return the configured
MessageConverter. |
long |
getReceiptTimeLimit()
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.
|
StompSessionHandler |
getSessionHandler()
Return the configured session handler.
|
String |
getSessionId()
Return the id for the session.
|
TaskScheduler |
getTaskScheduler()
Return the configured TaskScheduler to use for receipt tracking.
|
void |
handleFailure(Throwable ex)
Handle a failure on the connection.
|
void |
handleMessage(Message<byte[]> message)
Handle a message received from the remote host.
|
boolean |
isAutoReceiptEnabled()
Whether receipt headers should be automatically added.
|
boolean |
isConnected()
Whether the session is connected.
|
StompSession.Receiptable |
send(StompHeaders stompHeaders,
Object payload)
An overloaded version of
StompSession.send(String, Object) with full
StompHeaders instead of just a destination. |
StompSession.Receiptable |
send(String destination,
Object payload)
Send a message to the specified destination, converting the payload to a
byte[] with the help of a
MessageConverter. |
void |
setAutoReceipt(boolean autoReceiptEnabled)
When enabled, a receipt header is automatically added to future
send and subscribe operations on this session, which
causes the server to return a RECEIPT. |
void |
setMessageConverter(MessageConverter messageConverter)
Set the
MessageConverter to use to convert the payload of incoming
and outgoing messages to and from byte[] based on object type, or
expected object type, and the "content-type" header. |
void |
setReceiptTimeLimit(long receiptTimeLimit)
Configure the time in milliseconds before a receipt expires.
|
void |
setTaskScheduler(TaskScheduler taskScheduler)
Configure the TaskScheduler to use for receipt tracking.
|
StompSession.Subscription |
subscribe(StompHeaders stompHeaders,
StompFrameHandler handler)
An overloaded version of
StompSession.subscribe(String, StompFrameHandler)
with full StompHeaders instead of just a destination. |
StompSession.Subscription |
subscribe(String destination,
StompFrameHandler handler)
Subscribe to the given destination by sending a SUBSCRIBE frame and handle
received messages with the specified
StompFrameHandler. |
public DefaultStompSession(StompSessionHandler sessionHandler, StompHeaders connectHeaders)
sessionHandler - the application handler for the sessionconnectHeaders - headers for the STOMP CONNECT framepublic String getSessionId()
StompSessiongetSessionId in interface StompSessionpublic StompSessionHandler getSessionHandler()
public ListenableFuture<StompSession> getSessionFuture()
ConnectionHandlingStompSessiongetSessionFuture in interface ConnectionHandlingStompSessionpublic void setMessageConverter(MessageConverter messageConverter)
MessageConverter to use to convert the payload of incoming
and outgoing messages to and from byte[] based on object type, or
expected object type, and the "content-type" header.
By default, SimpleMessageConverter is configured.
messageConverter - the message converter to usepublic MessageConverter getMessageConverter()
MessageConverter.public void setTaskScheduler(TaskScheduler taskScheduler)
public TaskScheduler getTaskScheduler()
public void setReceiptTimeLimit(long receiptTimeLimit)
By default set to 15,000 (15 seconds).
public long getReceiptTimeLimit()
public void setAutoReceipt(boolean autoReceiptEnabled)
StompSessionsend and subscribe operations on this session, which
causes the server to return a RECEIPT. An application can then use
the Receiptable returned from the
operation to track the receipt.
A receipt header can also be added manually through the overloaded
methods that accept StompHeaders.
setAutoReceipt in interface StompSessionpublic boolean isAutoReceiptEnabled()
public boolean isConnected()
StompSessionisConnected in interface StompSessionpublic StompSession.Receiptable send(String destination, Object payload)
StompSessionbyte[] with the help of a
MessageConverter.send in interface StompSessiondestination - the destination to send a message topayload - the message payloadpublic StompSession.Receiptable send(StompHeaders stompHeaders, Object payload)
StompSessionStompSession.send(String, Object) with full
StompHeaders instead 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 in interface StompSessionstompHeaders - the message headerspayload - the message payloadpublic StompSession.Subscription subscribe(String destination, StompFrameHandler handler)
StompSessionStompFrameHandler.subscribe in interface StompSessiondestination - the destination to subscribe tohandler - the handler for received messagespublic StompSession.Subscription subscribe(StompHeaders stompHeaders, StompFrameHandler handler)
StompSessionStompSession.subscribe(String, StompFrameHandler)
with full StompHeaders instead of just a destination.subscribe in interface StompSessionstompHeaders - the headers for the subscribe message framehandler - the handler for received messagespublic StompSession.Receiptable acknowledge(String messageId, boolean consumed)
StompSessionNote: to use this when subscribing you must set the
ack header to "client" or
"client-individual" in order ot use this.
acknowledge in interface StompSessionmessageId - the id of the messageconsumed - whether the message was consumed or notpublic void disconnect()
StompSessiondisconnect in interface StompSessionpublic void afterConnected(TcpConnection<byte[]> connection)
TcpConnectionHandlerafterConnected in interface TcpConnectionHandler<byte[]>connection - the connectionpublic void afterConnectFailure(Throwable ex)
TcpConnectionHandlerafterConnectFailure in interface TcpConnectionHandler<byte[]>ex - the exceptionpublic void handleMessage(Message<byte[]> message)
TcpConnectionHandlerhandleMessage in interface TcpConnectionHandler<byte[]>message - the messagepublic void handleFailure(Throwable ex)
TcpConnectionHandlerhandleFailure in interface TcpConnectionHandler<byte[]>ex - the exceptionpublic void afterConnectionClosed()
TcpConnectionHandlerafterConnectionClosed in interface TcpConnectionHandler<byte[]>