org.apache.logging.log4j.core.util
Class DefaultShutdownCallbackRegistry

java.lang.Object
  extended by org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
All Implemented Interfaces:
Serializable, Runnable, LifeCycle, ShutdownCallbackRegistry

public class DefaultShutdownCallbackRegistry
extends Object
implements ShutdownCallbackRegistry, LifeCycle, Runnable, Serializable

ShutdownRegistrationStrategy that simply uses Runtime.addShutdownHook(Thread). If no strategy is specified, this one is used for shutdown hook registration.

Since:
2.1
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
 
Field Summary
protected static org.apache.logging.log4j.Logger LOGGER
           
 
Fields inherited from interface org.apache.logging.log4j.core.util.ShutdownCallbackRegistry
SHUTDOWN_CALLBACK_REGISTRY, SHUTDOWN_HOOK_ENABLED, SHUTDOWN_HOOK_MARKER
 
Constructor Summary
  DefaultShutdownCallbackRegistry()
          Constructs a DefaultShutdownRegistrationStrategy.
protected DefaultShutdownCallbackRegistry(ThreadFactory threadFactory)
          Constructs a DefaultShutdownRegistrationStrategy using the given ThreadFactory.
 
Method Summary
 Cancellable addShutdownCallback(Runnable callback)
          Adds a Runnable shutdown callback to this class.
 LifeCycle.State getState()
          Gets the life-cycle state
 boolean isStarted()
          Indicates if this can accept shutdown hooks.
 boolean isStopped()
           
 void run()
          Executes the registered shutdown callbacks.
 void start()
          Registers the shutdown thread only if this is initialized.
 void stop()
          Cancels the shutdown thread only if this is started.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

protected static final org.apache.logging.log4j.Logger LOGGER
Constructor Detail

DefaultShutdownCallbackRegistry

public DefaultShutdownCallbackRegistry()
Constructs a DefaultShutdownRegistrationStrategy.


DefaultShutdownCallbackRegistry

protected DefaultShutdownCallbackRegistry(ThreadFactory threadFactory)
Constructs a DefaultShutdownRegistrationStrategy using the given ThreadFactory.

Parameters:
threadFactory - the ThreadFactory to use to create a Runtime shutdown hook thread
Method Detail

run

public void run()
Executes the registered shutdown callbacks.

Specified by:
run in interface Runnable

addShutdownCallback

public Cancellable addShutdownCallback(Runnable callback)
Description copied from interface: ShutdownCallbackRegistry
Adds a Runnable shutdown callback to this class.

Specified by:
addShutdownCallback in interface ShutdownCallbackRegistry
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.

start

public void start()
Registers the shutdown thread only if this is initialized.

Specified by:
start in interface LifeCycle

stop

public void stop()
Cancels the shutdown thread only if this is started.

Specified by:
stop in interface LifeCycle

getState

public LifeCycle.State getState()
Description copied from interface: LifeCycle
Gets the life-cycle state

Specified by:
getState in interface LifeCycle
Returns:
the life-cycle state

isStarted

public boolean isStarted()
Indicates if this can accept shutdown hooks.

Specified by:
isStarted in interface LifeCycle
Returns:
true if this can accept shutdown hooks

isStopped

public boolean isStopped()
Specified by:
isStopped in interface LifeCycle


Copyright © 1999-2015 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.