001/* 002 * Copyright 2017-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2017-2019 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.unboundidds.tools; 022 023 024 025import com.unboundid.util.ThreadSafety; 026import com.unboundid.util.ThreadSafetyLevel; 027 028import static com.unboundid.ldap.sdk.unboundidds.tools.ToolMessages.*; 029 030 031 032/** 033 * This class provides a thread that will be registered as a JVM shutdown hook 034 * for any command-line tool for which invocation logging is to be performed. 035 * If the tool is interrupted by a JVM shutdown (for example, if the JVM 036 * receives a kill signal, if the user presses Control+C, or the tool calls 037 * System.exit) before it can complete naturally, then this shutdown hook thread 038 * will be run to try to ensure that the tool invocation log includes a record 039 * of the abnormal shutdown. 040 * <BR> 041 * <BLOCKQUOTE> 042 * <B>NOTE:</B> This class, and other classes within the 043 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 044 * supported for use against Ping Identity, UnboundID, and 045 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 046 * for proprietary functionality or for external specifications that are not 047 * considered stable or mature enough to be guaranteed to work in an 048 * interoperable way with other types of LDAP servers. 049 * </BLOCKQUOTE> 050 */ 051@ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE) 052public final class ToolInvocationLogShutdownHook 053 extends Thread 054{ 055 // An object with information about the logging that should be performed. 056 private final ToolInvocationLogDetails logDetails; 057 058 059 060 /** 061 * Creates a new instance of this shutdown hook with the provided log details. 062 * 063 * @param logDetails The log details of the tool. It must not be 064 * {@code null}. 065 */ 066 public ToolInvocationLogShutdownHook( 067 final ToolInvocationLogDetails logDetails) 068 { 069 this.logDetails = logDetails; 070 } 071 072 073 074 /** 075 * Logs a completion message indicating that tool processing was interrupted 076 * by a JVM shutdown. 077 */ 078 @Override() 079 public void run() 080 { 081 ToolInvocationLogger.logCompletionMessage(logDetails, null, 082 INFO_TOOL_INTERRUPTED_BY_JVM_SHUTDOWN.get()); 083 } 084}