Skip to content

Commit

Permalink
Issue #4919 - changes from review
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Jul 28, 2020
1 parent e13d26a commit 9e383f0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected void doStart() throws Exception
@Override
public CompletableFuture<Void> shutdown()
{
return ShutdownUtil.shutdown(sessionTracker);
return ShutdownUtil.stop(sessionTracker);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ protected void doStop() throws Exception
{
for (Session session : sessions)
{
if (Thread.interrupted())
break;

try
{
// GOING_AWAY is abnormal close status so it will hard close connection after sent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -391,6 +391,10 @@ public synchronized void setStopAtShutdown(boolean stop)
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;
Expand Down Expand Up @@ -424,7 +428,7 @@ protected void doStop() throws Exception
@Override
public CompletableFuture<Void> shutdown()
{
return ShutdownUtil.shutdown(sessionTracker);
return ShutdownUtil.stop(sessionTracker);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ protected void doStop() throws Exception
{
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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ protected void doStart() throws Exception
@Override
public CompletableFuture<Void> shutdown()
{
return ShutdownUtil.shutdown(sessionTracker);
return ShutdownUtil.stop(sessionTracker);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<>()
Expand Down

0 comments on commit 9e383f0

Please sign in to comment.