From 0e9841a3ccef2885acdd700cd62c47b80a5b3ea5 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 12 Oct 2016 11:13:35 -0700 Subject: [PATCH] Issue #207 - correcting lifecycle of WebSocketSession and EndpointFunctions --- .../eclipse/jetty/websocket/client/io/ConnectPromise.java | 1 + .../eclipse/jetty/websocket/client/io/UpgradeConnection.java | 5 +++-- .../org/eclipse/jetty/websocket/common/WebSocketSession.java | 4 ++-- .../websocket/common/function/CommonEndpointFunctions.java | 2 +- .../jetty/websocket/common/function/EndpointFunctions.java | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectPromise.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectPromise.java index 5b9832fa378..b19bf97c97d 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectPromise.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectPromise.java @@ -116,5 +116,6 @@ public abstract class ConnectPromise extends FuturePromise implements R public void setSession(WebSocketSession session) { this.session = session; + this.client.addManaged(session); } } diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java index d8caa246e16..e4262dee235 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java @@ -320,7 +320,6 @@ public class UpgradeConnection extends AbstractConnection implements Connection. // Wire up Session <-> Connection connection.addListener(session); - connectPromise.setSession(session); // Initialize / Negotiate Extensions ExtensionStack extensionStack = new ExtensionStack(connectPromise.getClient().getExtensionFactory()); @@ -338,7 +337,9 @@ public class UpgradeConnection extends AbstractConnection implements Connection. extensionStack.setNextOutgoing(connection); session.addManaged(extensionStack); - connectPromise.getClient().addManaged(session); + + // let waiting client know about session + connectPromise.setSession(session); // Now swap out the connection endp.upgrade(connection); diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java index a1ca67f7482..d1a7cdbe201 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java @@ -174,8 +174,8 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem LOG.debug("Using RemoteEndpointFactory: {}", remoteEndpointFactory); this.endpointFunctions = newEndpointFunctions(this.endpoint); - addBean(this.endpointFunctions); - + addManaged(this.endpointFunctions); + super.doStart(); } diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/function/CommonEndpointFunctions.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/function/CommonEndpointFunctions.java index e022db53b12..b2f48e19289 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/function/CommonEndpointFunctions.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/function/CommonEndpointFunctions.java @@ -110,8 +110,8 @@ public class CommonEndpointFunctions extends AbstractLifeCycl @Override protected void doStart() throws Exception { - super.doStart(); discoverEndpointFunctions(this.endpoint); + super.doStart(); } protected void discoverEndpointFunctions(Object endpoint) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/function/EndpointFunctions.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/function/EndpointFunctions.java index 937137258c4..41607b94de4 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/function/EndpointFunctions.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/function/EndpointFunctions.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.common.function; import java.nio.ByteBuffer; +import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.websocket.api.extensions.Frame; import org.eclipse.jetty.websocket.common.CloseInfo; @@ -28,7 +29,7 @@ import org.eclipse.jetty.websocket.common.CloseInfo; * * @param the Session object */ -public interface EndpointFunctions +public interface EndpointFunctions extends LifeCycle { void onOpen(T session);