ariba.util.shutdown
Class ShutdownManager

java.lang.Object
  extended by ariba.util.shutdown.ShutdownManager

public class ShutdownManager
extends java.lang.Object

The ShutdownManager is responsible for executing shutdown requests as graceful as possible. There are several elements in the shutdown sequence:

  1. ShutdownDelayer are objects which can delay the shutdown request
  2. ShutdownHook are objects which are invoked during the actual shutdown process
  3. ExitHook is the object which is invoked last to stop the VM


Nested Class Summary
static interface ShutdownManager.ShutdownNotifier
          This is an interface defined to allow the shutdown manager to callback a notifier just before the actual shutdown.
 
Field Summary
static java.lang.String AutoRecycleKey
           
static java.lang.String DirectActionKey
           
static int FatalExitNoRestart
          Exit code to use on fatal failure without restart.
static int FatalExitRestart
          Exit code to use on fatal failure with restart.
static java.lang.String FinalShutdownNoticeTopic
           
static java.lang.String NodeKey
           
static java.lang.String[] NodeStatusStrings
           
static java.lang.String NodeStatusUnknown
           
static int NormalExitNoRestart
          Exit code to use on normal exit with no restart
static java.lang.String SignalKey
           
static int StatusNodeAutoRecycle
          Node is in Auto Recycle shutdown.
static int StatusNodeDirectAction
          Node is in shutdown initiated by a Direct Action.
static int StatusNodeImmediate
          Node is in immediate (synchronous, forced) shutdown.
static int StatusNodeRunning
          Nodes is in normal running state.
static int StatusNodeSignal
          Node is in shutdown initiated by a signal.
static int StatusSystemRollingRestart
          System is in Rolling Restart.
static int StatusSystemRollingUpgrade
          System is in Rolling Upgrade.
static int StatusSystemRunning
          System is in normal running state.
static java.lang.String[] SystemStatusStrings
           
static java.lang.String SystemStatusUnknown
           
 
Method Summary
static void addLastShutdownHook(java.lang.Thread hook)
          Adds a ShutdownHook to be invoked before the exit
static void addShutdownDelayer(ShutdownDelayer delayer)
          Adds a ShutdownDelayer to be invoked during the asynhchronous shutdown
static void addShutdownHook(java.lang.Thread hook)
          Adds a ShutdownHook to be invoked before the exit
static void forceShutdown(int exitCode)
          Triggers the synchronous and immediate shutdown sequence
static ShutdownManager get()
          Returns the instance of the ShutdownManager
 long getGracePeriod()
          Returns the milliseconds for which we wait for all the ShutdownDelayers to complete.
static int getMetastableSystemStatus(int minuteWindow, int samples)
          Get a meta-stable value of the Shutdown Manager's state.
static int getNodeStatus()
           
 int getNodeStatus(java.lang.String type)
          Returns the status code given a shutdown type.
static java.lang.String getNodeStatusAsString(int status)
           
 RecycleManager getRecycleMgr()
           
static long getShutdownStartTime()
           
static int getSystemStatus()
          Determine the current system shutdown (cluster) status.
static java.lang.String getSystemStatusAsString(int status)
           
 ThreadFactory getThreadFactory()
           
 long getTimeBeforeShutdown()
          Returns the number of milliseconds before we will force the shutdown (unless all ShutdownDelayer let the shutdown proceed).
 long getWarningInterval()
          Returns the millisecond interval between warnings during the warning perdiod.
 long getWarningPeriod()
          Returns the millisecond period during which issue shutdown warnings through the UI.
 void registerShutdownManagerProcessor(ShutdownManagerProcessorIfc smp)
           
 void registerSignalHandlerForAsynchronousShutdown(java.lang.String signal)
          Creates and registers a SignalHandler for the given signal name which will trigger the execution of the asynchronous shutdown
 void registerSignalHandlerForSynchronousShutdown(java.lang.String signal)
          Creates and registers a SignalHandler for the given signal name which will trigger the execution of the asynchronous shutdown
static void restartAfterStartupError()
          Shutdowns a node so that it can restarted after a transient startup error.
 void rollingRestartBegin()
          Record start of Rolling Restart.
 void rollingRestartEnd()
          Record end of Rolling Restart.
 void rollingUpgradeBegin()
          Record start of Rolling Upgrade.
 void rollingUpgradeEnd()
          Record end of Rolling Upgrade.
static void setExitHook(ExitHook hook)
          Changes the ExitHook
 void setHookRunnerTimeout(int timeout)
          Defines the delay for which we wait for all the ShutdownHooks to complete.
 void setPingInterval(int interval)
          Defines the interval between queries to the ShutdownDelayer
 void setPrintExtraMessages(boolean value)
          Specifies whether to print extra messages during the shutdown.
 void setShutdownNotifier(ShutdownManager.ShutdownNotifier notifier)
          Set the shutdownNotifier.
 void setShutdownTimes(java.lang.String type, int gracePeriod, int warningPeriod, int warningInterval)
          Sets a group of shutdown times for a given key.
static void setSystemStatus(int status)
           
 void setThreadFactory(ThreadFactory tf)
          Sets the ThreadFactory that will be used for creating new threads as needed during the shutdown sequence
static void shutdown(int exitCode, java.lang.String type)
          Triggers the start of the asynchronous shutdown sequence.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NormalExitNoRestart

public static final int NormalExitNoRestart
Exit code to use on normal exit with no restart

See Also:
Constant Field Values

FatalExitRestart

public static final int FatalExitRestart
Exit code to use on fatal failure with restart.

See Also:
Constant Field Values

FatalExitNoRestart

public static final int FatalExitNoRestart
Exit code to use on fatal failure without restart.

See Also:
Constant Field Values

StatusSystemRunning

public static final int StatusSystemRunning
System is in normal running state.

See Also:
Constant Field Values

StatusSystemRollingUpgrade

public static final int StatusSystemRollingUpgrade
System is in Rolling Upgrade.

See Also:
Constant Field Values

StatusSystemRollingRestart

public static final int StatusSystemRollingRestart
System is in Rolling Restart.

See Also:
Constant Field Values

SystemStatusUnknown

public static final java.lang.String SystemStatusUnknown
See Also:
Constant Field Values

SystemStatusStrings

public static final java.lang.String[] SystemStatusStrings

StatusNodeRunning

public static final int StatusNodeRunning
Nodes is in normal running state.

See Also:
Constant Field Values

StatusNodeImmediate

public static final int StatusNodeImmediate
Node is in immediate (synchronous, forced) shutdown. There is no grace period.

See Also:
Constant Field Values

StatusNodeDirectAction

public static final int StatusNodeDirectAction
Node is in shutdown initiated by a Direct Action. Has DirectAction grace period.

See Also:
Constant Field Values

StatusNodeSignal

public static final int StatusNodeSignal
Node is in shutdown initiated by a signal. Has Signal grace period.

See Also:
Constant Field Values

StatusNodeAutoRecycle

public static final int StatusNodeAutoRecycle
Node is in Auto Recycle shutdown. Has AutoRecycle grace period.

See Also:
Constant Field Values

NodeStatusUnknown

public static final java.lang.String NodeStatusUnknown
See Also:
Constant Field Values

NodeStatusStrings

public static final java.lang.String[] NodeStatusStrings

DirectActionKey

public static final java.lang.String DirectActionKey
See Also:
Constant Field Values

SignalKey

public static final java.lang.String SignalKey
See Also:
Constant Field Values

AutoRecycleKey

public static final java.lang.String AutoRecycleKey
See Also:
Constant Field Values

FinalShutdownNoticeTopic

public static final java.lang.String FinalShutdownNoticeTopic
See Also:
Constant Field Values

NodeKey

public static final java.lang.String NodeKey
See Also:
Constant Field Values
Method Detail

get

public static ShutdownManager get()
Returns the instance of the ShutdownManager

Returns:
the singleton ShutdownManager

getRecycleMgr

public RecycleManager getRecycleMgr()

addShutdownDelayer

public static void addShutdownDelayer(ShutdownDelayer delayer)
Adds a ShutdownDelayer to be invoked during the asynhchronous shutdown

Parameters:
delayer - the ShutdownDelayer to be added

addShutdownHook

public static void addShutdownHook(java.lang.Thread hook)
Adds a ShutdownHook to be invoked before the exit

Parameters:
hook - the ShutdownHook to be added

addLastShutdownHook

public static void addLastShutdownHook(java.lang.Thread hook)
Adds a ShutdownHook to be invoked before the exit

Parameters:
hook - the ShutdownHook to be added

setExitHook

public static void setExitHook(ExitHook hook)
Changes the ExitHook

Parameters:
hook - the new ExitHook to use

shutdown

public static void shutdown(int exitCode,
                            java.lang.String type)
Triggers the start of the asynchronous shutdown sequence.

Parameters:
exitCode - the exit code to return at the end

forceShutdown

public static void forceShutdown(int exitCode)
Triggers the synchronous and immediate shutdown sequence

Parameters:
exitCode - the exit code to return

restartAfterStartupError

public static void restartAfterStartupError()
Shutdowns a node so that it can restarted after a transient startup error. For Ops instances, a normal exit is used, so Ops is not paged. Caller must log an error message before calling this method.


setHookRunnerTimeout

public void setHookRunnerTimeout(int timeout)
Defines the delay for which we wait for all the ShutdownHooks to complete.

Parameters:
timeout - delay in minutes

setShutdownTimes

public void setShutdownTimes(java.lang.String type,
                             int gracePeriod,
                             int warningPeriod,
                             int warningInterval)
Sets a group of shutdown times for a given key.

Parameters:
type - shutdown type
gracePeriod - overall delay period in minutes
warningPeriod - total period to issue warnings in UI in minutes
warningInterval - interval between UI warnings

getNodeStatus

public int getNodeStatus(java.lang.String type)
Returns the status code given a shutdown type.

Returns:
node shutdown status code.

rollingUpgradeBegin

public void rollingUpgradeBegin()
Record start of Rolling Upgrade.


rollingUpgradeEnd

public void rollingUpgradeEnd()
Record end of Rolling Upgrade.


rollingRestartBegin

public void rollingRestartBegin()
Record start of Rolling Restart.


rollingRestartEnd

public void rollingRestartEnd()
Record end of Rolling Restart.


getGracePeriod

public long getGracePeriod()
Returns the milliseconds for which we wait for all the ShutdownDelayers to complete.

Returns:
grace period in milliseconds

getWarningPeriod

public long getWarningPeriod()
Returns the millisecond period during which issue shutdown warnings through the UI.

Returns:
warning period in milliseconds

getWarningInterval

public long getWarningInterval()
Returns the millisecond interval between warnings during the warning perdiod.

Returns:
warning interval in milliseconds
See Also:
getWarningPeriod()

setPingInterval

public void setPingInterval(int interval)
Defines the interval between queries to the ShutdownDelayer

Parameters:
interval - delay in seconds

setThreadFactory

public void setThreadFactory(ThreadFactory tf)
Sets the ThreadFactory that will be used for creating new threads as needed during the shutdown sequence

Parameters:
tf - the new ThreadFactory

getThreadFactory

public ThreadFactory getThreadFactory()

setPrintExtraMessages

public void setPrintExtraMessages(boolean value)
Specifies whether to print extra messages during the shutdown. The Ops infrastructure looks for specific String to determine whether the server shutdown normally or crashed. These special String are only printed when true is passed to that method

Parameters:
value - if true the extra messages will be printed on the console

registerSignalHandlerForAsynchronousShutdown

public void registerSignalHandlerForAsynchronousShutdown(java.lang.String signal)
Creates and registers a SignalHandler for the given signal name which will trigger the execution of the asynchronous shutdown

Parameters:
signal - name of the signal to register with

registerSignalHandlerForSynchronousShutdown

public void registerSignalHandlerForSynchronousShutdown(java.lang.String signal)
Creates and registers a SignalHandler for the given signal name which will trigger the execution of the asynchronous shutdown

Parameters:
signal - name of the signal to register with

registerShutdownManagerProcessor

public void registerShutdownManagerProcessor(ShutdownManagerProcessorIfc smp)

getTimeBeforeShutdown

public long getTimeBeforeShutdown()
Returns the number of milliseconds before we will force the shutdown (unless all ShutdownDelayer let the shutdown proceed).

Returns:
the delay in milliseconds before the shutdown

setShutdownNotifier

public void setShutdownNotifier(ShutdownManager.ShutdownNotifier notifier)
Set the shutdownNotifier. This is the call back mechanism to send out the final shutdown notification.


getSystemStatus

public static int getSystemStatus()
Determine the current system shutdown (cluster) status. During initialization of a node this system shutdown status may be inaccurate for an interval; use getMetastableSystemStatus(int, int) instead to allow for a delayed response.

Returns:
possibly incorrect system status

getMetastableSystemStatus

public static int getMetastableSystemStatus(int minuteWindow,
                                            int samples)
Get a meta-stable value of the Shutdown Manager's state.

Since the initialization of nodes may cause a false presumption of "normal running" (StatusSystemRunning) while all the nodes get to the correct stable state, wait up to the specified number of minutes before returning the shutdown state of the cluster. Subsequent calls only wait additional time if the largest prior window, plus any time elapsed since then, is not long enough to cover the new window. If two distinct invocations have differing minute windows, both window requests will be effectively honored.

Parameters:
minuteWindow - maximum number of minutes to wait before considering the system stable; values below 1 treated as 1; values over 60 treated as 60 (i.e., maximum delay to obtain a stable sample is an hour)
samples - number of times to sample the shutdown state during window; values below 2 treated as 2 values over (the limited value of) 2*minuteWindow treated as that value (i.e., the maximum sample rate is twice per minute)
Returns:
stable cluster state

getSystemStatusAsString

public static java.lang.String getSystemStatusAsString(int status)

setSystemStatus

public static void setSystemStatus(int status)

getNodeStatus

public static int getNodeStatus()

getNodeStatusAsString

public static java.lang.String getNodeStatusAsString(int status)

getShutdownStartTime

public static long getShutdownStartTime()


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.