Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import org.springframework.web.socket.messaging.WebSocketStompClient;

import javax.websocket.DeploymentException;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -142,7 +143,7 @@ public void connect() {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.initialize();
stompClient.setTaskScheduler(threadPoolTaskScheduler);
stompClient.setDefaultHeartbeat(new long[]{30000, 30000});
stompClient.setDefaultHeartbeat(new long[]{60000, 60000});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not make this a configuration variable?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it would make sense as it is not obvious on how to set it.

StompSessionHandler sessionHandler = new StompSessionHandler();
logger.log(Level.INFO, "Attempting web socket connection to " + connectUrl);
new Thread(() -> {
Expand Down Expand Up @@ -228,26 +229,30 @@ public void handleException(StompSession session, @Nullable StompCommand command
}

/**
* If remote peer goes away because the service is shut down, or because
* of a network connection issue, we get a {@link ConnectionLostException}. In this case
* a reconnection thread is started. If on the other hand a connection attempt fails, we get
* a different type of exception (javax.websocket.DeploymentException), in which case a
* reconnection thread is not started.
* Handles error for different type of {@link Exception}s:
* <ol>
* <li>{@link DeploymentException}: unable to connect, i.e. do not start a new connection thread.</li>
* <li>{@link ConnectionLostException}: service not reachable, e.g. due to network issues or service down.
* Connection thread started.</li>
* <li>{@link IllegalStateException}: service very busy or being debugged, i.e. heartbeat messages
* not received. Connection thread started.</li>
* </ol>
*
* @param session the client STOMP session
* @param exception the exception that occurred. This is evaluated to determine if a reconnection
* thread should be launched.
*/
@Override
public void handleTransportError(StompSession session, Throwable exception) {
if (exception instanceof ConnectionLostException) {
if(exception instanceof DeploymentException){
logger.log(Level.WARNING, "Unable to connect", exception);
}
else {
logger.log(Level.WARNING, "Connection lost, will attempt to reconnect", exception);
if (disconnectCallback != null) {
if (exception instanceof ConnectionLostException && disconnectCallback != null) {
disconnectCallback.run();
}
connect();
} else {
logger.log(Level.WARNING, "Got transport exception", exception);
}
}
}
Expand Down
Loading