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-2009 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.opends.server.tasks;
018
019import org.forgerock.i18n.LocalizableMessage;
020
021import org.opends.server.core.DirectoryServer;
022import org.opends.server.api.DirectoryThread;
023
024/**
025 * This class defines a thread that will be spawned to invoke a Directory Server
026 * in-core restart.  That is, the server will perform an internal shutdown, and
027 * will then re-bootstrap and start itself up again without ever exiting the
028 * JVM.
029 * <BR><BR>
030 * Note that there are two significant differences between this thread and the
031 * shutdown task thread (other than the obvious difference that this one does a
032 * restart while the other does a shutdown):  this class extends
033 * <CODE>java.lang.Thread</CODE> instead of
034 * <CODE>org.opends.server.core.DirectoryThread</CODE>, and this thread is not a
035 * daemon thread.  These changes are needed to guarantee that the JVM does not
036 * exit before we get a chance to restart it if all non-daemon threads go away.
037 */
038public class RestartTaskThread
039       extends DirectoryThread
040{
041  /**
042   * The fully-qualified name of this class.
043   */
044  private static final String CLASS_NAME =
045       "org.opends.server.tasks.RestartTaskThread";
046
047
048
049  /** The shutdown message that will be used. */
050  private LocalizableMessage shutdownMessage;
051
052
053
054  /**
055   * Creates a new instance of this shutdown task thread with the provided
056   * message.
057   *
058   * @param  shutdownMessage  The shutdown message that will be used.
059   */
060  public RestartTaskThread(LocalizableMessage shutdownMessage)
061  {
062    super("Restart Task Thread");
063
064
065    this.shutdownMessage = shutdownMessage;
066  }
067
068
069
070  /**
071   * Invokes the Directory Server shutdown process.
072   */
073  @Override
074  public void run()
075  {
076    DirectoryServer.restart(CLASS_NAME, shutdownMessage);
077  }
078}
079