Issue #4919 - changes from review

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-07-28 16:48:49 +10:00
parent e13d26ab45
commit 9e383f0891
6 changed files with 16 additions and 6 deletions

View File

@ -211,7 +211,7 @@ public abstract class JavaxWebSocketContainer extends ContainerLifeCycle impleme
@Override
public CompletableFuture<Void> shutdown()
{
return ShutdownUtil.shutdown(sessionTracker);
return ShutdownUtil.stop(sessionTracker);
}
@Override

View File

@ -57,6 +57,9 @@ public class SessionTracker extends AbstractLifeCycle implements JavaxWebSocketS
{
for (Session session : sessions)
{
if (Thread.interrupted())
break;
try
{
// GOING_AWAY is abnormal close status so it will hard close connection after sent.

View File

@ -71,7 +71,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli
private final Configuration.ConfigurationCustomizer configurationCustomizer = new Configuration.ConfigurationCustomizer();
private final WebSocketComponents components = new WebSocketComponents();
private boolean stopAtShutdown = false;
private long _stopTimeout = 200;
private long _stopTimeout = Long.MAX_VALUE;
/**
* Instantiate a WebSocketClient with defaults
@ -391,6 +391,10 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli
stopAtShutdown = stop;
}
/**
* The timeout to allow all remaining open Sessions to be closed gracefully using the close code {@link org.eclipse.jetty.websocket.api.StatusCode#SHUTDOWN}.
* @param stopTimeout the time in ms to wait for the graceful close, use a value less than or equal to 0 to not gracefully close.
*/
public void setStopTimeout(long stopTimeout)
{
_stopTimeout = stopTimeout;
@ -424,7 +428,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli
@Override
public CompletableFuture<Void> shutdown()
{
return ShutdownUtil.shutdown(sessionTracker);
return ShutdownUtil.stop(sessionTracker);
}
@Override

View File

@ -53,6 +53,9 @@ public class SessionTracker extends AbstractLifeCycle implements WebSocketSessio
{
for (Session session : sessions)
{
if (Thread.interrupted())
break;
// SHUTDOWN is abnormal close status so it will hard close connection after sent.
session.close(StatusCode.SHUTDOWN, "Container being shut down");
}

View File

@ -293,7 +293,7 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
@Override
public CompletableFuture<Void> shutdown()
{
return ShutdownUtil.shutdown(sessionTracker);
return ShutdownUtil.stop(sessionTracker);
}
@Override

View File

@ -30,11 +30,11 @@ public class ShutdownUtil
private static final Logger LOG = LoggerFactory.getLogger(ShutdownUtil.class);
/**
* Shutdown a {@link LifeCycle} in a new daemon thread and be notified on the result in a {@link CompletableFuture}.
* Stop a {@link LifeCycle} in a new daemon thread and be notified of the result in a {@link CompletableFuture}.
* @param lifeCycle the LifeCycle to stop.
* @return the CompletableFuture to be notified when the stop either completes or fails.
*/
public static CompletableFuture<Void> shutdown(LifeCycle lifeCycle)
public static CompletableFuture<Void> stop(LifeCycle lifeCycle)
{
AtomicReference<Thread> stopThreadReference = new AtomicReference<>();
CompletableFuture<Void> shutdown = new CompletableFuture<>()