001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014 ForgeRock AS
026 */
027package org.opends.server.core;
028
029
030import org.opends.server.api.DirectoryThread;
031
032import org.forgerock.i18n.slf4j.LocalizedLogger;
033import static org.opends.messages.CoreMessages.*;
034/**
035 * This class defines a shutdown hook that will be invoked automatically when
036 * the JVM is shutting down.  It may be able to detect certain kinds of shutdown
037 * events that are not invoked by the Directory Server itself (e.g., an
038 * administrator killing the Java process).
039 */
040public class DirectoryServerShutdownHook
041       extends DirectoryThread
042{
043  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
044
045  /**
046   * The fully-qualified name of this class.
047   */
048  private static final String CLASS_NAME =
049       "org.opends.server.core.DirectoryServerShutdownHook";
050
051
052
053  /**
054   * Creates a new shutdown hook that will stop the Directory Server when it is
055   * determined that the JVM is shutting down.
056   */
057  public DirectoryServerShutdownHook()
058  {
059    super("Directory Server Shutdown Hook");
060
061  }
062
063
064
065  /**
066   * Invokes the shutdown hook to signal the Directory Server to stop running.
067   */
068  public void run()
069  {
070    logger.trace(
071        "Directory Server shutdown hook has been invoked.");
072
073    DirectoryServer.shutDown(CLASS_NAME,
074                             ERR_SHUTDOWN_DUE_TO_SHUTDOWN_HOOK.get());
075  }
076}
077