diff --git a/core/websocket/client/src/main/java/org/phoebus/core/websocket/client/WebSocketClientService.java b/core/websocket/client/src/main/java/org/phoebus/core/websocket/client/WebSocketClientService.java index e1d60f70e8..34903d66b0 100644 --- a/core/websocket/client/src/main/java/org/phoebus/core/websocket/client/WebSocketClientService.java +++ b/core/websocket/client/src/main/java/org/phoebus/core/websocket/client/WebSocketClientService.java @@ -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; @@ -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}); StompSessionHandler sessionHandler = new StompSessionHandler(); logger.log(Level.INFO, "Attempting web socket connection to " + connectUrl); new Thread(() -> { @@ -228,11 +229,14 @@ 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: + *
    + *
  1. {@link DeploymentException}: unable to connect, i.e. do not start a new connection thread.
  2. + *
  3. {@link ConnectionLostException}: service not reachable, e.g. due to network issues or service down. + * Connection thread started.
  4. + *
  5. {@link IllegalStateException}: service very busy or being debugged, i.e. heartbeat messages + * not received. Connection thread started.
  6. + *
* * @param session the client STOMP session * @param exception the exception that occurred. This is evaluated to determine if a reconnection @@ -240,14 +244,15 @@ public void handleException(StompSession session, @Nullable StompCommand command */ @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); } } }