private class StompBrokerRelayMessageHandler.StompConnectionHandler extends java.lang.Object implements TcpConnectionHandler<byte[]>
Modifier and Type | Field and Description |
---|---|
private StompHeaderAccessor |
connectHeaders |
private boolean |
isRemoteClientSession |
private boolean |
isStompConnected |
private java.lang.String |
sessionId |
private TcpConnection<byte[]> |
tcpConnection |
Modifier | Constructor and Description |
---|---|
private |
StompConnectionHandler(java.lang.String sessionId,
StompHeaderAccessor connectHeaders) |
private |
StompConnectionHandler(java.lang.String sessionId,
StompHeaderAccessor connectHeaders,
boolean isRemoteClientSession) |
Modifier and Type | Method and Description |
---|---|
void |
afterConnected(TcpConnection<byte[]> connection)
Invoked after a connection is successfully established.
|
void |
afterConnectFailure(java.lang.Throwable ex)
Invoked after a connection failure.
|
void |
afterConnectionClosed()
Invoked after the connection is closed.
|
protected void |
afterStompConnected(StompHeaderAccessor connectedHeaders)
Invoked after the STOMP CONNECTED frame is received.
|
void |
clearConnection()
Close the TCP connection to the broker and release the connection reference,
Any exception arising from closing the connection is propagated.
|
ListenableFuture<java.lang.Void> |
forward(Message<?> message)
Forward the given message to the STOMP broker.
|
java.lang.String |
getSessionId() |
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.
|
protected void |
handleTcpConnectionFailure(java.lang.String errorMessage,
java.lang.Throwable ex)
Invoked when any TCP connectivity issue is detected, i.e.
|
private void |
initHeartbeats(StompHeaderAccessor connectedHeaders) |
protected void |
sendMessageToClient(Message<?> message) |
private void |
sendStompErrorToClient(java.lang.String errorText) |
java.lang.String |
toString() |
private final java.lang.String sessionId
private final boolean isRemoteClientSession
private final StompHeaderAccessor connectHeaders
private volatile TcpConnection<byte[]> tcpConnection
private volatile boolean isStompConnected
private StompConnectionHandler(java.lang.String sessionId, StompHeaderAccessor connectHeaders)
private StompConnectionHandler(java.lang.String sessionId, StompHeaderAccessor connectHeaders, boolean isRemoteClientSession)
public java.lang.String getSessionId()
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 exceptionprotected void handleTcpConnectionFailure(java.lang.String errorMessage, java.lang.Throwable ex)
private void sendStompErrorToClient(java.lang.String errorText)
protected void sendMessageToClient(Message<?> message)
public void handleMessage(Message<byte[]> message)
TcpConnectionHandler
handleMessage
in interface TcpConnectionHandler<byte[]>
message
- the messageprotected void afterStompConnected(StompHeaderAccessor connectedHeaders)
private void initHeartbeats(StompHeaderAccessor connectedHeaders)
public void handleFailure(java.lang.Throwable ex)
TcpConnectionHandler
handleFailure
in interface TcpConnectionHandler<byte[]>
ex
- the exceptionpublic void afterConnectionClosed()
TcpConnectionHandler
afterConnectionClosed
in interface TcpConnectionHandler<byte[]>
public ListenableFuture<java.lang.Void> forward(Message<?> message)
The method checks whether we have an active TCP connection and have received the STOMP CONNECTED frame. For client messages this should be false only if we lose the TCP connection around the same time when a client message is being forwarded, so we simply log the ignored message at trace level. For messages from within the application being sent on the "system" connection an exception is raised so that components sending the message have a chance to handle it -- by default the broker message channel is synchronous.
Note that if messages arrive concurrently around the same time a TCP connection is lost, there is a brief period of time before the connection is reset when one or more messages may sneak through and an attempt made to forward them. Rather than synchronizing to guard against that, this method simply lets them try and fail. For client sessions that may result in an additional STOMP ERROR frame(s) being sent downstream but code handling that downstream should be idempotent in such cases.
message
- the message to send, never null
public void clearConnection()
If the connection belongs to a client session, the connection handler
for the session (basically the current instance) is also released from the
StompBrokerRelayMessageHandler
.
public java.lang.String toString()
toString
in class java.lang.Object