Skip to content

Commit

Permalink
Get WebSocketContainer only once (static initilization).
Browse files Browse the repository at this point in the history
  • Loading branch information
matejonnet committed May 7, 2020
1 parent ef2f902 commit df03917
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.websocket.CloseReason;
import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.io.IOException;
import java.net.URI;
import java.nio.BufferOverflowException;
Expand All @@ -51,6 +52,8 @@ public class BuildAgentSocketClient extends BuildAgentClientBase implements Buil

private static final Logger log = LoggerFactory.getLogger(BuildAgentSocketClient.class);

private static final WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();

private String commandContext;

private final ResponseMode responseMode;
Expand Down Expand Up @@ -191,7 +194,7 @@ private RemoteEndpoint connectStatusListenerClient(String webSocketBaseUrl, Cons
try {
String websocketUrl = stripEndingSlash(webSocketBaseUrl) + RemoteEndpoint.WEB_SOCKET_LISTENER_PATH + commandContext;
ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
ContainerProvider.getWebSocketContainer().connectToServer(client, clientEndpointConfig, new URI(websocketUrl));
webSocketContainer.connectToServer(client, clientEndpointConfig, new URI(websocketUrl));
} catch (Exception e) {
throw new AssertionError("Failed to connect to remote client.", e);
}
Expand Down Expand Up @@ -225,7 +228,7 @@ private RemoteEndpoint connectCommandExecutingClient(String webSocketBaseUrl, Op
try {
String websocketUrl = webSocketPath + commandContext + appendReadOnly;
ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
ContainerProvider.getWebSocketContainer().connectToServer(client, clientEndpointConfig, new URI(websocketUrl));
webSocketContainer.connectToServer(client, clientEndpointConfig, new URI(websocketUrl));
} catch (Exception e) {
throw new AssertionError("Failed to connect to remote client.", e);
}
Expand Down

0 comments on commit df03917

Please sign in to comment.