org.springframework.messaging.simp.stomp

## Class DefaultStompSession

- java.lang.Object
- - org.springframework.messaging.simp.stomp.DefaultStompSession

All Implemented Interfaces:
  ConnectionHandlingStompSession, StompSession, TcpConnectionHandler<byte[]>

    public class DefaultStompSession
    extends Object
    implements ConnectionHandlingStompSession

Default implementation of `ConnectionHandlingStompSession`.

Since:
  4.2
Author:
  Rossen Stoyanchev

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.springframework.messaging.simp.stomp.StompSession

`StompSession.Receiptable, StompSession.Subscription`

### Field Summary

Fields
`static byte[]` `EMPTY_PAYLOAD` An empty payload.

### Constructor Summary

Constructors
Constructor and Description
`DefaultStompSession(StompSessionHandler sessionHandler, StompHeaders connectHeaders)` Create a new session.

### Method Summary

All Methods Instance Methods Concrete Methods
`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(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.
`void` `disconnect(StompHeaders headers)` Variant of `StompSession.disconnect()` with headers.
`MessageConverter` `getMessageConverter()` Return the configured `MessageConverter`.
`long` `getReceiptTimeLimit()` Return the configured time limit before a receipt expires.
`org.springframework.util.concurrent.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.
`org.springframework.scheduling.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 headers, 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(org.springframework.scheduling.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(String destination, StompFrameHandler handler)` Subscribe to the given destination by sending a SUBSCRIBE frame and handle received messages with the specified `StompFrameHandler`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### EMPTY_PAYLOAD

    public static final byte[] EMPTY_PAYLOAD

An empty payload.

### Constructor Detail

#### DefaultStompSession

    public DefaultStompSession(StompSessionHandler sessionHandler,
                               StompHeaders connectHeaders)

Create a new session.

Parameters:
  `sessionHandler` - the application handler for the session
  `connectHeaders` - headers for the STOMP CONNECT frame

### Method Detail

#### getSessionId

    public String getSessionId()

Description copied from interface: `StompSession`
Return the id for the session.

Specified by:
  `getSessionId` in interface `StompSession`

#### getSessionHandler

    public StompSessionHandler getSessionHandler()

Return the configured session handler.

#### getSessionFuture

    public org.springframework.util.concurrent.ListenableFuture<StompSession> getSessionFuture()

Description copied from interface: `ConnectionHandlingStompSession`
Return a future that will complete when the session is ready for use.

Specified by:
  `getSessionFuture` in interface `ConnectionHandlingStompSession`

#### setMessageConverter

    public 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.

By default, `SimpleMessageConverter` is configured.

Parameters:
  `messageConverter` - the message converter to use

#### getMessageConverter

    public MessageConverter getMessageConverter()

Return the configured `MessageConverter`.

#### setTaskScheduler

    public void setTaskScheduler(@Nullable
                                 org.springframework.scheduling.TaskScheduler taskScheduler)

Configure the TaskScheduler to use for receipt tracking.

#### getTaskScheduler

    @Nullable
    public org.springframework.scheduling.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)

Description copied from interface: `StompSession`
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. 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`.

Specified by:
  `setAutoReceipt` in interface `StompSession`

#### isAutoReceiptEnabled

    public boolean isAutoReceiptEnabled()

Whether receipt headers should be automatically added.

#### isConnected

    public boolean isConnected()

Description copied from interface: `StompSession`
Whether the session is connected.

Specified by:
  `isConnected` in interface `StompSession`

#### send

    public StompSession.Receiptable send(String destination,
                                         Object payload)

Description copied from interface: `StompSession`
Send a message to the specified destination, converting the payload to a `byte[]` with the help of a `MessageConverter`.

Specified by:
  `send` in interface `StompSession`
Parameters:
  `destination` - the destination to send a message to
  `payload` - the message payload
Returns:
  a Receiptable for tracking receipts

#### send

    public StompSession.Receiptable send(StompHeaders headers,
                                         Object payload)

Description copied from interface: `StompSession`
An overloaded version of `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.

Specified by:
  `send` in interface `StompSession`
Parameters:
  `headers` - the message headers
  `payload` - the message payload
Returns:
  a Receiptable for tracking receipts

#### subscribe

    public StompSession.Subscription subscribe(String destination,
                                               StompFrameHandler handler)

Description copied from interface: `StompSession`
Subscribe to the given destination by sending a SUBSCRIBE frame and handle received messages with the specified `StompFrameHandler`.

Specified by:
  `subscribe` in interface `StompSession`
Parameters:
  `destination` - the destination to subscribe to
  `handler` - the handler for received messages
Returns:
  a handle to use to unsubscribe and/or track receipts

#### subscribe

    public StompSession.Subscription subscribe(StompHeaders headers,
                                               StompFrameHandler handler)

Description copied from interface: `StompSession`
An overloaded version of `StompSession.subscribe(String, StompFrameHandler)` with full `StompHeaders` instead of just a destination.

Specified by:
  `subscribe` in interface `StompSession`
Parameters:
  `headers` - the headers for the subscribe message frame
  `handler` - the handler for received messages
Returns:
  a handle to use to unsubscribe and/or track receipts

#### acknowledge

    public StompSession.Receiptable acknowledge(String messageId,
                                                boolean consumed)

Description copied from interface: `StompSession`
Send 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 `ack` header to "client" or "client-individual" in order ot use this.

Specified by:
  `acknowledge` in interface `StompSession`
Parameters:
  `messageId` - the id of the message
  `consumed` - whether the message was consumed or not
Returns:
  a Receiptable for tracking receipts

#### acknowledge

    public StompSession.Receiptable acknowledge(StompHeaders headers,
                                                boolean consumed)

Description copied from interface: `StompSession`
An overloaded version of `StompSession.acknowledge(String, boolean)` with full `StompHeaders` instead of just a `messageId`.

Specified by:
  `acknowledge` in interface `StompSession`
Parameters:
  `headers` - the headers for the ACK or NACK message frame
  `consumed` - whether the message was consumed or not
Returns:
  a Receiptable for tracking receipts

#### disconnect

    public void disconnect()

Description copied from interface: `StompSession`
Disconnect the session by sending a DISCONNECT frame.

Specified by:
  `disconnect` in interface `StompSession`

#### disconnect

    public void disconnect(@Nullable
                           StompHeaders headers)

Description copied from interface: `StompSession`
Variant of `StompSession.disconnect()` with headers.

Specified by:
  `disconnect` in interface `StompSession`
Parameters:
  `headers` - the headers for the disconnect message frame

#### afterConnected

    public void afterConnected(TcpConnection<byte[]> connection)

Description copied from interface: `TcpConnectionHandler`
Invoked after a connection is successfully established.

Specified by:
  `afterConnected` in interface `TcpConnectionHandler<byte[]>`
Parameters:
  `connection` - the connection

#### afterConnectFailure

    public void afterConnectFailure(Throwable ex)

Description copied from interface: `TcpConnectionHandler`
Invoked on failure to connect.

Specified by:
  `afterConnectFailure` in interface `TcpConnectionHandler<byte[]>`
Parameters:
  `ex` - the exception

#### handleMessage

    public void handleMessage(Message<byte[]> message)

Description copied from interface: `TcpConnectionHandler`
Handle a message received from the remote host.

Specified by:
  `handleMessage` in interface `TcpConnectionHandler<byte[]>`
Parameters:
  `message` - the message

#### handleFailure

    public void handleFailure(Throwable ex)

Description copied from interface: `TcpConnectionHandler`
Handle a failure on the connection.

Specified by:
  `handleFailure` in interface `TcpConnectionHandler<byte[]>`
Parameters:
  `ex` - the exception

#### afterConnectionClosed

    public void afterConnectionClosed()

Description copied from interface: `TcpConnectionHandler`
Invoked after the connection is closed.

Specified by:
  `afterConnectionClosed` in interface `TcpConnectionHandler<byte[]>`