com.microsoft.tfs.util.shutdown
Class ShutdownManager

java.lang.Object
  extended by com.microsoft.tfs.util.shutdown.ShutdownManager

public final class ShutdownManager
extends java.lang.Object

Overview

Manages the lifecycle of core objects that implement one or more of the event listener interfaces in com.microsoft.tfs.core.events. This class is a singleton which should be accessed through the public static method getInstance().

The general use case for this class is that objects that implement the lifecycle event listener interfaces will register themselves on creation with this manager (via add*EventListener()). These events are fired on the registered objects when the Java virtual machine is shutting down.

Usage Notes

To register events with the shutdown manager, simply get a reference via getInstance() and call addShutdownEventListener(ShutdownEventListener, Priority) and removeShutdownEventListener(ShutdownEventListener, Priority). Application should manually invoke shutdown() when they exit (read the Javadoc on the method). Because of how the JVM handles its shutdown process, this class's shutdown event can be fired from any thread.

This class is a singleton (use getInstance()).

Since:
TEE-SDK-10.1
Thread-safety:
thread-safe

Nested Class Summary
static class ShutdownManager.Priority
           
 
Method Summary
 void addShutdownEventListener(ShutdownEventListener listener, ShutdownManager.Priority priority)
          Add a listener for the event fired when core is being shut down.
static ShutdownManager getInstance()
          Gets the single instance of ShutdownManager for any process.
 void removeShutdownEventListener(ShutdownEventListener listener, ShutdownManager.Priority priority)
          Remove a listener for the event fired when core is being shut down.
 void shutdown()
          Instructs all registered listeners to shutdown.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ShutdownManager getInstance()
Gets the single instance of ShutdownManager for any process.

Returns:
the ShutdownManager instance.

shutdown

public void shutdown()
Instructs all registered listeners to shutdown.

Using the shutdown manager for the first time causes it to establish a link with the Java virtual machine that ensures it will be invoked during JVM shutdown. However, when an application exits normally, the shutdown hooks may not be called. Applications that use ShutdownManager should call shutdown() directly as part of their application exit procedure to ensure all listeners are invoked before the JVM exits.


addShutdownEventListener

public void addShutdownEventListener(ShutdownEventListener listener,
                                     ShutdownManager.Priority priority)
Add a listener for the event fired when core is being shut down.

Parameters:
listener - the listener to add (not null.
priority - the priority of the listener (not null).

removeShutdownEventListener

public void removeShutdownEventListener(ShutdownEventListener listener,
                                        ShutdownManager.Priority priority)
Remove a listener for the event fired when core is being shut down.

Parameters:
listener - the listener to remove (not null).
priority - the priority of the listener to remove (not null). Must match the original priority supplied to be removed.


© 2015 Microsoft. All rights reserved.