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-2015 ForgeRock AS 026 */ 027package org.opends.server.loggers; 028 029import java.util.ArrayList; 030 031import org.forgerock.i18n.slf4j.LocalizedLogger; 032import org.opends.server.api.DirectoryThread; 033import org.opends.server.config.ConfigEntry; 034 035/** 036 * This thread is spawned off at the time of file rotation to 037 * execute specific actions such as compression, encryption, 038 * and signing of the log files. 039 */ 040public class RotationActionThread extends DirectoryThread 041{ 042 private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); 043 044 private ArrayList<ActionType> actions; 045 private String filename; 046 private ConfigEntry configEntry; 047 048 /** 049 * Create the logger thread along with the specified file name, 050 * and the rotation actions. 051 * 052 * @param filename The name of the file to be rotated. 053 * @param actions The set of actions that should be performed when the 054 * file is rotated. 055 * @param configEntry The entry that contains the rotation configuration. 056 */ 057 public RotationActionThread(String filename, 058 ArrayList<ActionType> actions, 059 ConfigEntry configEntry) 060 { 061 super("Logger Rotation Action Thread"); 062 063 this.filename = filename; 064 this.actions = actions; 065 this.configEntry = configEntry; 066 } 067 068 /** 069 * The run method of the thread. 070 */ 071 public void run() 072 { 073 try 074 { 075 for(ActionType at : actions) 076 { 077 PostRotationAction action = null; 078 switch(at) 079 { 080 case GZIP_COMPRESS: 081 String gzipFile = filename + ".gz"; 082 action = new GZIPAction(filename, gzipFile, true); 083 break; 084 case ZIP_COMPRESS: 085 String zipFile = filename + ".zip"; 086 action = new ZIPAction(filename, zipFile, true); 087 break; 088 case SIGN: 089 case ENCRYPT: 090 break; 091 default: 092 System.err.println("Invalid post rollover action:" + at); 093 break; 094 } 095 if(action != null && !action.execute()) 096 { 097 System.err.println("Post rotation action failed."); 098 } 099 } 100 } catch(Exception e) 101 { 102 logger.traceException(e); 103 } 104 } 105}