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 2015 ForgeRock AS. 015 */ 016 017package org.forgerock.audit.rotation; 018 019import java.io.IOException; 020 021import org.forgerock.audit.retention.RetentionPolicy; 022import org.joda.time.DateTime; 023 024/** 025 * Interface defining methods a rotatable file needs. 026 */ 027public interface RotatableObject { 028 /** 029 * Retrieves the number of bytes written to the file. 030 * 031 * @return The number of bytes written to the file. 032 */ 033 long getBytesWritten(); 034 035 /** 036 * Retrieves the last time the file was rotated. If a file rotation never 037 * occurred, this value will be the time the server started. 038 * 039 * @return The last time file rotation occurred. 040 */ 041 DateTime getLastRotationTime(); 042 043 /** 044 * Checks the rotatable file for rotation then retention. The file is rotated if the configured 045 * {@link RotationPolicy}'s are true. The old audit files are retained/deleted according to 046 * the {@link RetentionPolicy}'s configured. 047 * @throws IOException If unable to rotateIfNeeded the audit file. 048 */ 049 void rotateIfNeeded() throws IOException; 050 051 /** 052 * Closes the rotatable file. 053 */ 054 void close() throws IOException; 055 056 /** 057 * Registers hooks into the rotation process. 058 * @param rotationHooks The {@link RotationHooks} into the rotation process. 059 */ 060 void registerRotationHooks(final RotationHooks rotationHooks); 061 062}