001/* A class to notify listeners when Kepler is about to exit.
002 * 
003 * Copyright (c) 2011 The Regents of the University of California.
004 * All rights reserved.
005 *
006 * '$Author: crawl $'
007 * '$Date: 2012-11-26 22:21:34 +0000 (Mon, 26 Nov 2012) $' 
008 * '$Revision: 31119 $'
009 * 
010 * Permission is hereby granted, without written agreement and without
011 * license or royalty fees, to use, copy, modify, and distribute this
012 * software and its documentation for any purpose, provided that the above
013 * copyright notice and the following two paragraphs appear in all copies
014 * of this software.
015 *
016 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
017 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
018 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
019 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
020 * SUCH DAMAGE.
021 *
022 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
023 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
024 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
025 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
026 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
027 * ENHANCEMENTS, OR MODIFICATIONS.
028 *
029 */
030package org.kepler.util;
031
032import java.util.Collections;
033import java.util.HashSet;
034import java.util.Set;
035
036public class ShutdownNotifier {
037
038    /** Add a ShutdownListener to be called when Kepler is about to exit. */
039    public static void addShutdownListener(ShutdownListener listener) {
040        _shutdownListeners.add(listener);
041    }
042
043    /** Notify listeners that Kepler is about to exit. */
044    public static void shutdown() {
045        for(ShutdownListener shutdownListener : _shutdownListeners) {
046            shutdownListener.shutdown();
047        }
048    }
049    
050    /** A list of shutdown listeners. */
051    private static Set<ShutdownListener> _shutdownListeners =
052        Collections.synchronizedSet(new HashSet<ShutdownListener>());
053
054}