Top Description Inners Fields Constructors Methods
io.undertow.server.handlers

public Class GracefulShutdownHandler

extends Object
implements HttpHandler
Class Inheritance
All Implemented Interfaces
io.undertow.server.HttpHandler
Imports
io.undertow.UndertowMessages, io.undertow.server.ExchangeCompletionListener, .HttpHandler, .HttpServerExchange, io.undertow.util.StatusCodes, java.util.ArrayList, .List, java.util.concurrent.atomic.AtomicLongFieldUpdater, java.util.function.LongUnaryOperator

Handler that allows for graceful server shutdown. Basically it provides a way to prevent the server from accepting new requests, and wait for existing requests to complete.

The handler itself does not shut anything down.

Import: The thread safety semantics of the handler are very important. Don't touch anything unless you know what you are doing.

Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
public static interface
GracefulShutdownHandler.ShutdownListener

A listener which can be registered with the handler to be notified when all pending requests have finished.

Field Summary

Modifier and TypeField and Description
private static final long
private static final LongUnaryOperator
private static final LongUnaryOperator
private static final LongUnaryOperator
private final GracefulShutdownHandler.GracefulShutdownListener
private final Object
private final HttpHandler
private static final long
private final List<GracefulShutdownHandler.ShutdownListener>
private volatile long
private static final AtomicLongFieldUpdater<GracefulShutdownHandler>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static long
activeCount(long state)

public void
addShutdownListener(final GracefulShutdownHandler.ShutdownListener
The shutdown listener
shutdownListener
)

Adds a shutdown listener that will be invoked when all requests have finished.

public void
awaitShutdown()

Waits for the handler to shutdown.

public boolean

Returns:

true If the handler successfully shut down
awaitShutdown
(long
The length of time
millis
)

Waits a set length of time for the handler to shut down

private void
public void
handleRequest(HttpServerExchange
the HTTP request/response exchange
exchange
)

Implements io.undertow.server.HttpHandler.handleRequest.

Handle the request.

private static boolean
isShutdown(long state)

public void
private void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ACTIVE_COUNT_MASKback to summary
private static final long ACTIVE_COUNT_MASK
decrementActiveback to summary
private static final LongUnaryOperator decrementActive
incrementActiveback to summary
private static final LongUnaryOperator incrementActive
incrementActiveAndShutdownback to summary
private static final LongUnaryOperator incrementActiveAndShutdown
listenerback to summary
private final GracefulShutdownHandler.GracefulShutdownListener listener
lockback to summary
private final Object lock
nextback to summary
private final HttpHandler next
SHUTDOWN_MASKback to summary
private static final long SHUTDOWN_MASK
shutdownListenersback to summary
private final List<GracefulShutdownHandler.ShutdownListener> shutdownListeners
stateback to summary
private volatile long state
stateUpdaterback to summary
private static final AtomicLongFieldUpdater<GracefulShutdownHandler> stateUpdater

Constructor Detail

GracefulShutdownHandlerback to summary
public GracefulShutdownHandler(HttpHandler next)

Method Detail

activeCountback to summary
private static long activeCount(long state)
addShutdownListenerback to summary
public void addShutdownListener(final GracefulShutdownHandler.ShutdownListener shutdownListener)

Adds a shutdown listener that will be invoked when all requests have finished. If all requests have already been finished the listener will be invoked immediately.

Parameters
shutdownListener:GracefulShutdownHandler.ShutdownListener

The shutdown listener

awaitShutdownback to summary
public void awaitShutdown() throws InterruptedException

Waits for the handler to shutdown.

awaitShutdownback to summary
public boolean awaitShutdown(long millis) throws InterruptedException

Waits a set length of time for the handler to shut down

Parameters
millis:long

The length of time

Returns:boolean

true If the handler successfully shut down

decrementRequestsback to summary
private void decrementRequests()
handleRequestback to summary
public void handleRequest(HttpServerExchange exchange) throws Exception

Implements io.undertow.server.HttpHandler.handleRequest.

Doc from io.undertow.server.HttpHandler.handleRequest.

Handle the request.

Parameters
exchange:HttpServerExchange

the HTTP request/response exchange

Annotations
@Override
isShutdownback to summary
private static boolean isShutdown(long state)
shutdownback to summary
public void shutdown()
shutdownCompleteback to summary
private void shutdownComplete()
startback to summary
public void start()
io.undertow.server.handlers back to summary

private final Class GracefulShutdownHandler.GracefulShutdownListener

extends Object
implements ExchangeCompletionListener
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.GracefulShutdownHandler.GracefulShutdownListener
All Implemented Interfaces
io.undertow.server.ExchangeCompletionListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

GracefulShutdownListenerback to summary
private GracefulShutdownListener()

Method Detail

exchangeEventback to summary
public void exchangeEvent(HttpServerExchange exchange, ExchangeCompletionListener.NextListener nextListener)

Implements io.undertow.server.ExchangeCompletionListener.exchangeEvent.

Annotations
@Override
io.undertow.server.handlers back to summary

public Interface GracefulShutdownHandler.ShutdownListener


A listener which can be registered with the handler to be notified when all pending requests have finished.

Method Summary

Modifier and TypeMethod and Description
public void
shutdown(boolean
If the shutdown succeeded or not
shutdownSuccessful
)

Notification that the container has shutdown.

Method Detail

shutdownback to summary
public void shutdown(boolean shutdownSuccessful)

Notification that the container has shutdown.

Parameters
shutdownSuccessful:boolean

If the shutdown succeeded or not