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