-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5840 from eclipse/jetty-10.0.x-5832-WebSocketShut…
…downThread Issue #5832 - shutdown Javax WSClientContainer with webapp if possible.
- Loading branch information
Showing
12 changed files
with
587 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...c/main/java/org/eclipse/jetty/websocket/javax/client/JavaxWebSocketShutdownContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.websocket.javax.client; | ||
|
||
import java.util.Set; | ||
import javax.servlet.ServletContainerInitializer; | ||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
import javax.servlet.ServletException; | ||
|
||
import org.eclipse.jetty.util.component.ContainerLifeCycle; | ||
import org.eclipse.jetty.util.component.LifeCycle; | ||
import org.eclipse.jetty.websocket.javax.client.internal.JavaxWebSocketClientContainer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* <p>This manages the LifeCycle of {@link javax.websocket.WebSocketContainer} instances that are created with | ||
* {@link javax.websocket.ContainerProvider}, if this code is being run from another ServletContainer, or if run inside a | ||
* Jetty Server with the WebSocket client classes provided by the webapp.</p> | ||
* | ||
* <p>This mechanism will not work if run with embedded Jetty or if the WebSocket client classes are provided by the server. | ||
* In this case then the client {@link javax.websocket.WebSocketContainer} will register itself to be automatically shutdown | ||
* with the Jetty {@code ContextHandler}.</p> | ||
*/ | ||
public class JavaxWebSocketShutdownContainer extends ContainerLifeCycle implements ServletContainerInitializer, ServletContextListener | ||
{ | ||
private static final Logger LOG = LoggerFactory.getLogger(JavaxWebSocketShutdownContainer.class); | ||
|
||
@Override | ||
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException | ||
{ | ||
JavaxWebSocketClientContainer.setShutdownContainer(this); | ||
ctx.addListener(this); | ||
} | ||
|
||
@Override | ||
public void contextInitialized(ServletContextEvent sce) | ||
{ | ||
if (LOG.isDebugEnabled()) | ||
LOG.debug("contextInitialized({}) {}", sce, this); | ||
LifeCycle.start(this); | ||
} | ||
|
||
@Override | ||
public void contextDestroyed(ServletContextEvent sce) | ||
{ | ||
if (LOG.isDebugEnabled()) | ||
LOG.debug("contextDestroyed({}) {}", sce, this); | ||
|
||
LifeCycle.stop(this); | ||
removeBeans(); | ||
JavaxWebSocketClientContainer.setShutdownContainer(null); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return String.format("%s@%x{%s, size=%s}", getClass().getSimpleName(), hashCode(), getState(), getBeans().size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...vax-client/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.eclipse.jetty.websocket.javax.client.JavaxWebSocketShutdownContainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.