diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java index 0196f11b60a..32ca8337d57 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java @@ -308,6 +308,8 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont protected void doStop() throws Exception { ShutdownThread.deregister(this); + this.encoderFactory.destroy(); + this.decoderFactory.destroy(); endpointClientMetadataCache.clear(); super.doStop(); } diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/Configurable.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/Configurable.java index 352e6478fd4..8e3dd9b20ad 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/Configurable.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/Configurable.java @@ -26,4 +26,6 @@ import javax.websocket.EndpointConfig; public interface Configurable { void init(EndpointConfig config); + + void destroy(); } diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/DecoderFactory.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/DecoderFactory.java index 58ad6c629dc..8b61176fdbd 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/DecoderFactory.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/DecoderFactory.java @@ -69,6 +69,12 @@ public class DecoderFactory implements Configurable { this.decoder.init(config); } + + @Override + public void destroy() + { + this.decoder.destroy(); + } } private static final Logger LOG = Log.getLogger(DecoderFactory.class); @@ -185,6 +191,17 @@ public class DecoderFactory implements Configurable } } + @Override + public void destroy() + { + for (Wrapper wrapper : activeWrappers.values()) + { + wrapper.decoder.destroy(); + } + + activeWrappers.clear(); + } + public Wrapper newWrapper(DecoderMetadata metadata) { Class decoderClass = metadata.getCoderClass(); diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/EncoderFactory.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/EncoderFactory.java index 27bf324f2ae..1bbf3a7d483 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/EncoderFactory.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/EncoderFactory.java @@ -62,14 +62,21 @@ public class EncoderFactory implements Configurable { this.encoder.init(config); } + + @Override + public void destroy() + { + this.encoder.destroy(); + } } private static final Logger LOG = Log.getLogger(EncoderFactory.class); private final EncoderMetadataSet metadatas; private final WebSocketContainerScope containerScope; - private EncoderFactory parentFactory; - private Map, Wrapper> activeWrappers; + private final Map, Wrapper> activeWrappers; + private final EncoderFactory parentFactory; + private EndpointConfig endpointConfig; public EncoderFactory(WebSocketContainerScope containerScope, EncoderMetadataSet metadatas) { @@ -153,10 +160,9 @@ public class EncoderFactory implements Configurable @Override public void init(EndpointConfig config) { + this.endpointConfig = config; if (LOG.isDebugEnabled()) - { - LOG.debug("init({})", config); - } + LOG.debug("init({})", endpointConfig); // Instantiate all declared encoders for (EncoderMetadata metadata : metadatas) @@ -164,20 +170,29 @@ public class EncoderFactory implements Configurable Wrapper wrapper = newWrapper(metadata); activeWrappers.put(metadata.getObjectType(), wrapper); } + } - // Initialize all encoders + @Override + public void destroy() + { for (Wrapper wrapper : activeWrappers.values()) { - wrapper.encoder.init(config); + wrapper.encoder.destroy(); } + + activeWrappers.clear(); } private Wrapper newWrapper(EncoderMetadata metadata) { + if (endpointConfig == null) + throw new IllegalStateException("EndpointConfig not set"); + Class encoderClass = metadata.getCoderClass(); try { Encoder encoder = containerScope.getObjectFactory().createInstance(encoderClass); + encoder.init(endpointConfig); return new Wrapper(encoder, metadata); } catch (Exception e) diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JsrSession.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JsrSession.java index 5dc3e71b96c..50c48eb39e8 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JsrSession.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JsrSession.java @@ -306,6 +306,13 @@ public class JsrSession extends WebSocketSession implements javax.websocket.Sess decoderFactory.init(config); } + @Override + public void destroy() + { + encoderFactory.destroy(); + decoderFactory.destroy(); + } + @Override public void removeMessageHandler(MessageHandler handler) { diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/AbstractJsrEventDriver.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/AbstractJsrEventDriver.java index 4f76e8fa8ad..e3304a4a2c4 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/AbstractJsrEventDriver.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/AbstractJsrEventDriver.java @@ -77,6 +77,10 @@ public abstract class AbstractJsrEventDriver extends AbstractEventDriver CloseCode closecode = CloseCodes.getCloseCode(close.getStatusCode()); CloseReason closereason = new CloseReason(closecode, close.getReason()); onClose(closereason); + + // Destroy the JsrSession. + if (jsrsession != null) + jsrsession.destroy(); } protected abstract void onClose(CloseReason closereason);