diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java index 5ebedbb517b..3f65e0bece8 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java @@ -42,7 +42,7 @@ public abstract class ConnectionManagerSupport implements SmartLifecycle { private boolean autoStartup = false; - private boolean isRunning = false; + private boolean running = false; private int phase = Integer.MAX_VALUE; @@ -104,7 +104,7 @@ public abstract class ConnectionManagerSupport implements SmartLifecycle { @Override public boolean isRunning() { synchronized (this.lifecycleMonitor) { - return this.isRunning; + return this.running; } } @@ -125,7 +125,7 @@ public abstract class ConnectionManagerSupport implements SmartLifecycle { if (logger.isInfoEnabled()) { logger.info("Starting " + this.getClass().getSimpleName()); } - this.isRunning = true; + this.running = true; openConnection(); } } @@ -146,7 +146,7 @@ public abstract class ConnectionManagerSupport implements SmartLifecycle { logger.error("Failed to stop WebSocket connection", e); } finally { - this.isRunning = false; + this.running = false; } } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java index 85a90cb2ab9..0da13bd898e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.web.socket.client; import java.util.List; +import org.springframework.context.Lifecycle; import org.springframework.context.SmartLifecycle; import org.springframework.http.HttpHeaders; import org.springframework.util.concurrent.ListenableFuture; @@ -46,8 +47,6 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport { private WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); - private final boolean syncClientLifecycle; - public WebSocketConnectionManager(WebSocketClient client, WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) { @@ -55,7 +54,6 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport { super(uriTemplate, uriVariables); this.client = client; this.webSocketHandler = decorateWebSocketHandler(webSocketHandler); - this.syncClientLifecycle = ((client instanceof SmartLifecycle) && !((SmartLifecycle) client).isRunning()); } @@ -116,16 +114,16 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport { @Override public void startInternal() { - if (this.syncClientLifecycle) { - ((SmartLifecycle) this.client).start(); + if (this.client instanceof Lifecycle && !((Lifecycle) client).isRunning()) { + ((Lifecycle) client).start(); } super.startInternal(); } @Override public void stopInternal() throws Exception { - if (this.syncClientLifecycle) { - ((SmartLifecycle) this.client).stop(); + if (this.client instanceof Lifecycle && ((Lifecycle) client).isRunning()) { + ((Lifecycle) client).stop(); } super.stopInternal(); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java index f9e6f8a9d1c..67aec6a3152 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java @@ -26,7 +26,7 @@ import java.util.concurrent.Future; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; -import org.springframework.context.SmartLifecycle; +import org.springframework.context.Lifecycle; import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; @@ -47,17 +47,18 @@ import org.springframework.web.util.UriComponentsBuilder; * Initiates WebSocket requests to a WebSocket server programmatically * through the Jetty WebSocket API. * + *
As of 4.1 this class implements {@link Lifecycle} rather than
+ * {@link org.springframework.context.SmartLifecycle}. Use
+ * {@link org.springframework.web.socket.client.WebSocketConnectionManager
+ * WebSocketConnectionManager} instead to auto-start a WebSocket connection.
+ *
* @author Rossen Stoyanchev
* @since 4.0
*/
-public class JettyWebSocketClient extends AbstractWebSocketClient implements SmartLifecycle {
+public class JettyWebSocketClient extends AbstractWebSocketClient implements Lifecycle {
private final org.eclipse.jetty.websocket.client.WebSocketClient client;
- private boolean autoStartup = true;
-
- private int phase = Integer.MAX_VALUE;
-
private final Object lifecycleMonitor = new Object();
private AsyncListenableTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
@@ -98,24 +99,6 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Sma
return this.taskExecutor;
}
- public void setAutoStartup(boolean autoStartup) {
- this.autoStartup = autoStartup;
- }
-
- @Override
- public boolean isAutoStartup() {
- return this.autoStartup;
- }
-
- public void setPhase(int phase) {
- this.phase = phase;
- }
-
- @Override
- public int getPhase() {
- return this.phase;
- }
-
@Override
public boolean isRunning() {
synchronized (this.lifecycleMonitor) {
@@ -157,12 +140,6 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Sma
}
}
- @Override
- public void stop(Runnable callback) {
- this.stop();
- callback.run();
- }
-
@Override
public ListenableFuture