Class DefaultShutdownCallbackRegistry
java.lang.Object
org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
- All Implemented Interfaces:
Runnable
,LifeCycle
,LifeCycle2
,ShutdownCallbackRegistry
public class DefaultShutdownCallbackRegistry
extends Object
implements ShutdownCallbackRegistry, LifeCycle2, Runnable
ShutdownRegistrationStrategy that simply uses
Runtime.addShutdownHook(Thread)
. If no strategy is specified,
this one is used for shutdown hook registration.- Since:
- 2.1
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
Field Summary
Fields inherited from interface org.apache.logging.log4j.core.util.ShutdownCallbackRegistry
SHUTDOWN_CALLBACK_REGISTRY, SHUTDOWN_HOOK_ENABLED, SHUTDOWN_HOOK_MARKER
-
Constructor Summary
ModifierConstructorDescriptionConstructs a DefaultShutdownRegistrationStrategy.protected
DefaultShutdownCallbackRegistry
(ThreadFactory threadFactory) Constructs a DefaultShutdownRegistrationStrategy using the givenThreadFactory
. -
Method Summary
Modifier and TypeMethodDescriptionaddShutdownCallback
(Runnable callback) Adds a Runnable shutdown callback to this class.getState()
Gets the life-cycle state.void
boolean
Indicates if this can accept shutdown hooks.boolean
void
run()
Executes the registered shutdown callbacks.void
start()
Registers the shutdown thread only if this is initialized.void
stop()
boolean
Cancels the shutdown thread only if this is started.
-
Field Details
-
LOGGER
Status logger.
-
-
Constructor Details
-
DefaultShutdownCallbackRegistry
public DefaultShutdownCallbackRegistry()Constructs a DefaultShutdownRegistrationStrategy. -
DefaultShutdownCallbackRegistry
Constructs a DefaultShutdownRegistrationStrategy using the givenThreadFactory
.- Parameters:
threadFactory
- the ThreadFactory to use to create aRuntime
shutdown hook thread
-
-
Method Details
-
run
public void run()Executes the registered shutdown callbacks. -
addShutdownCallback
Description copied from interface:ShutdownCallbackRegistry
Adds a Runnable shutdown callback to this class. Note: The returnedCancellable
must be retained on heap by caller to avoid premature garbage-collection of the registered callback (and to ensure the callback runs on shutdown).- Specified by:
addShutdownCallback
in interfaceShutdownCallbackRegistry
- Parameters:
callback
- the shutdown callback to be executed upon shutdown.- Returns:
- a Cancellable wrapper of the provided callback or
null
if the shutdown hook is disabled and cannot be added.
-
initialize
public void initialize()- Specified by:
initialize
in interfaceLifeCycle
-
start
public void start()Registers the shutdown thread only if this is initialized. -
stop
public void stop() -
stop
Cancels the shutdown thread only if this is started.- Specified by:
stop
in interfaceLifeCycle2
- Parameters:
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
getState
Description copied from interface:LifeCycle
Gets the life-cycle state. -
isStarted
public boolean isStarted()Indicates if this can accept shutdown hooks. -
isStopped
public boolean isStopped()
-