public class DefaultStompSession extends java.lang.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(StompHeaders headers,
boolean consumed)
An overloaded version of
StompSession.acknowledge(String, boolean) with
full StompHeaders instead of just a messageId . |
StompSession.Receiptable |
acknowledge(java.lang.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(java.lang.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.
|
java.lang.String |
getSessionId()
Return the id for the session.
|
TaskScheduler |
getTaskScheduler()
Return the configured TaskScheduler to use for receipt tracking.
|
void |
handleFailure(java.lang.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 headers,
java.lang.Object payload)
An overloaded version of
StompSession.send(String, Object) with full
StompHeaders instead of just a destination. |
StompSession.Receiptable |
send(java.lang.String destination,
java.lang.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 headers,
StompFrameHandler handler)
An overloaded version of
StompSession.subscribe(String, StompFrameHandler)
with full StompHeaders instead of just a destination. |
StompSession.Subscription |
subscribe(java.lang.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 java.lang.String getSessionId()
StompSession
getSessionId
in interface StompSession
public StompSessionHandler getSessionHandler()
public ListenableFuture<StompSession> getSessionFuture()
ConnectionHandlingStompSession
getSessionFuture
in interface ConnectionHandlingStompSession
public 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(@Nullable TaskScheduler taskScheduler)
@Nullable public TaskScheduler getTaskScheduler()
public void setReceiptTimeLimit(long receiptTimeLimit)
By default set to 15,000 (15 seconds).
public long getReceiptTimeLimit()
public void setAutoReceipt(boolean autoReceiptEnabled)
StompSession
send
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 StompSession
public boolean isAutoReceiptEnabled()
public boolean isConnected()
StompSession
isConnected
in interface StompSession
public StompSession.Receiptable send(java.lang.String destination, java.lang.Object payload)
StompSession
byte[]
with the help of a
MessageConverter
.send
in interface StompSession
destination
- the destination to send a message topayload
- the message payloadpublic StompSession.Receiptable send(StompHeaders headers, java.lang.Object payload)
StompSession
StompSession.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 StompSession
headers
- the message headerspayload
- the message payloadpublic StompSession.Subscription subscribe(java.lang.String destination, StompFrameHandler handler)
StompSession
StompFrameHandler
.subscribe
in interface StompSession
destination
- the destination to subscribe tohandler
- the handler for received messagespublic StompSession.Subscription subscribe(StompHeaders headers, StompFrameHandler handler)
StompSession
StompSession.subscribe(String, StompFrameHandler)
with full StompHeaders
instead of just a destination.subscribe
in interface StompSession
headers
- the headers for the subscribe message framehandler
- the handler for received messagespublic StompSession.Receiptable acknowledge(java.lang.String messageId, boolean consumed)
StompSession
Note: to use this when subscribing you must set the
ack
header to "client" or
"client-individual" in order ot use this.
acknowledge
in interface StompSession
messageId
- the id of the messageconsumed
- whether the message was consumed or notpublic StompSession.Receiptable acknowledge(StompHeaders headers, boolean consumed)
StompSession
StompSession.acknowledge(String, boolean)
with
full StompHeaders
instead of just a messageId
.acknowledge
in interface StompSession
headers
- the headers for the ACK or NACK message frameconsumed
- whether the message was consumed or notpublic void disconnect()
StompSession
disconnect
in interface StompSession
public void afterConnected(TcpConnection<byte[]> connection)
TcpConnectionHandler
afterConnected
in interface TcpConnectionHandler<byte[]>
connection
- the connectionpublic void afterConnectFailure(java.lang.Throwable ex)
TcpConnectionHandler
afterConnectFailure
in interface TcpConnectionHandler<byte[]>
ex
- the exceptionpublic void handleMessage(Message<byte[]> message)
TcpConnectionHandler
handleMessage
in interface TcpConnectionHandler<byte[]>
message
- the messagepublic void handleFailure(java.lang.Throwable ex)
TcpConnectionHandler
handleFailure
in interface TcpConnectionHandler<byte[]>
ex
- the exceptionpublic void afterConnectionClosed()
TcpConnectionHandler
afterConnectionClosed
in interface TcpConnectionHandler<byte[]>