private class WebSocketStompClient.WebSocketTcpConnectionHandlerAdapter extends java.lang.Object implements ListenableFutureCallback<WebSocketSession>, WebSocketHandler, TcpConnection<byte[]>
Modifier and Type | Field and Description |
---|---|
private WebSocketStompClient.StompWebSocketMessageCodec |
codec |
private TcpConnectionHandler<byte[]> |
connectionHandler |
private java.util.List<java.util.concurrent.ScheduledFuture<?>> |
inactivityTasks |
private long |
lastReadTime |
private long |
lastWriteTime |
private WebSocketSession |
session |
Constructor and Description |
---|
WebSocketTcpConnectionHandlerAdapter(TcpConnectionHandler<byte[]> connectionHandler) |
Modifier and Type | Method and Description |
---|---|
void |
afterConnectionClosed(WebSocketSession session,
CloseStatus closeStatus)
Invoked after the WebSocket connection has been closed by either side, or after a
transport error has occurred.
|
void |
afterConnectionEstablished(WebSocketSession session)
Invoked after WebSocket negotiation has succeeded and the WebSocket connection is
opened and ready for use.
|
private void |
cancelInactivityTasks() |
void |
close()
Close the connection.
|
void |
handleMessage(WebSocketSession session,
WebSocketMessage<?> webSocketMessage)
Invoked when a new WebSocket message arrives.
|
void |
handleTransportError(WebSocketSession session,
java.lang.Throwable ex)
Handle an error from the underlying WebSocket message transport.
|
void |
onFailure(java.lang.Throwable ex)
Called when the
ListenableFuture completes with failure. |
void |
onReadInactivity(java.lang.Runnable runnable,
long duration)
Register a task to invoke after a period of read inactivity.
|
void |
onSuccess(WebSocketSession webSocketSession)
Called when the
ListenableFuture completes with success. |
void |
onWriteInactivity(java.lang.Runnable runnable,
long duration)
Register a task to invoke after a period of write inactivity.
|
ListenableFuture<java.lang.Void> |
send(Message<byte[]> message)
Send the given message.
|
boolean |
supportsPartialMessages()
Whether the WebSocketHandler handles partial messages.
|
private void |
updateLastWriteTime() |
private final TcpConnectionHandler<byte[]> connectionHandler
private final WebSocketStompClient.StompWebSocketMessageCodec codec
private volatile WebSocketSession session
private volatile long lastReadTime
private volatile long lastWriteTime
private final java.util.List<java.util.concurrent.ScheduledFuture<?>> inactivityTasks
public WebSocketTcpConnectionHandlerAdapter(TcpConnectionHandler<byte[]> connectionHandler)
public void onSuccess(WebSocketSession webSocketSession)
SuccessCallback
ListenableFuture
completes with success.
Note that Exceptions raised by this method are ignored.
onSuccess
in interface SuccessCallback<WebSocketSession>
webSocketSession
- the resultpublic void onFailure(java.lang.Throwable ex)
FailureCallback
ListenableFuture
completes with failure.
Note that Exceptions raised by this method are ignored.
onFailure
in interface FailureCallback
ex
- the failurepublic void afterConnectionEstablished(WebSocketSession session)
WebSocketHandler
afterConnectionEstablished
in interface WebSocketHandler
public void handleMessage(WebSocketSession session, WebSocketMessage<?> webSocketMessage)
WebSocketHandler
handleMessage
in interface WebSocketHandler
public void handleTransportError(WebSocketSession session, java.lang.Throwable ex) throws java.lang.Exception
WebSocketHandler
handleTransportError
in interface WebSocketHandler
java.lang.Exception
- this method can handle or propagate exceptions; see class-level
Javadoc for details.public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws java.lang.Exception
WebSocketHandler
afterConnectionClosed
in interface WebSocketHandler
java.lang.Exception
- this method can handle or propagate exceptions; see class-level
Javadoc for details.private void cancelInactivityTasks()
public boolean supportsPartialMessages()
WebSocketHandler
true
and the underlying WebSocket server supports partial messages,
then a large WebSocket message, or one of an unknown size may be split and
maybe received over multiple calls to
WebSocketHandler.handleMessage(WebSocketSession, WebSocketMessage)
. The flag
WebSocketMessage.isLast()
indicates if
the message is partial and whether it is the last part.supportsPartialMessages
in interface WebSocketHandler
public ListenableFuture<java.lang.Void> send(Message<byte[]> message)
TcpConnection
send
in interface TcpConnection<byte[]>
message
- the messageprivate void updateLastWriteTime()
public void onReadInactivity(java.lang.Runnable runnable, long duration)
TcpConnection
onReadInactivity
in interface TcpConnection<byte[]>
runnable
- the task to invokeduration
- the amount of inactive time in millisecondspublic void onWriteInactivity(java.lang.Runnable runnable, long duration)
TcpConnection
onWriteInactivity
in interface TcpConnection<byte[]>
runnable
- the task to invokeduration
- the amount of inactive time in millisecondspublic void close()
TcpConnection
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface TcpConnection<byte[]>