0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License, Version 1.0 only
0N/A * (the "License"). You may not use this file except in compliance
0N/A * with the License.
0N/A *
6983N/A * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
6983N/A * or http://forgerock.org/license/CDDLv1.0.html.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
6983N/A * file and include the License file at legal-notices/CDDLv1_0.txt.
6983N/A * If applicable, add the following below this CDDL HEADER, with the
6983N/A * fields enclosed by brackets "[]" replaced with your own identifying
6983N/A * information:
0N/A * Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A *
0N/A *
3215N/A * Copyright 2006-2008 Sun Microsystems, Inc.
7141N/A * Portions Copyright 2014 ForgeRock AS
0N/A */
0N/Apackage org.opends.server.loggers;
2086N/Aimport org.opends.messages.Message;
0N/A
0N/A
1280N/Aimport org.opends.server.admin.std.server.SizeLimitLogRotationPolicyCfg;
1280N/Aimport org.opends.server.admin.server.ConfigurationChangeListener;
1280N/Aimport org.opends.server.types.InitializationException;
1280N/Aimport org.opends.server.types.ConfigChangeResult;
1280N/Aimport org.opends.server.types.ResultCode;
1280N/Aimport org.opends.server.config.ConfigException;
1280N/A
2086N/A
1280N/Aimport java.util.List;
1280N/Aimport java.util.ArrayList;
0N/A
0N/A/**
0N/A * This class implements a rotation policy based on the size of the
0N/A * file.
0N/A */
1280N/Apublic class SizeBasedRotationPolicy implements
1280N/A RotationPolicy<SizeLimitLogRotationPolicyCfg>,
1280N/A ConfigurationChangeListener<SizeLimitLogRotationPolicyCfg>
0N/A{
0N/A private long sizeLimit;
1280N/A
1280N/A SizeLimitLogRotationPolicyCfg currentConfig;
0N/A
0N/A /**
1280N/A * {@inheritDoc}
0N/A */
1280N/A public void initializeLogRotationPolicy(SizeLimitLogRotationPolicyCfg config)
1280N/A throws ConfigException, InitializationException
0N/A {
1280N/A sizeLimit = config.getFileSizeLimit();
1280N/A
1280N/A config.addSizeLimitChangeListener(this);
1280N/A currentConfig = config;
0N/A }
0N/A
0N/A /**
1280N/A * {@inheritDoc}
0N/A */
1280N/A public boolean isConfigurationChangeAcceptable(
2086N/A SizeLimitLogRotationPolicyCfg config, List<Message> unacceptableReasons)
0N/A {
1280N/A // Changes should always be OK
1280N/A return true;
0N/A }
0N/A
0N/A /**
1280N/A * {@inheritDoc}
0N/A */
1280N/A public ConfigChangeResult applyConfigurationChange(
1280N/A SizeLimitLogRotationPolicyCfg config)
0N/A {
1280N/A // Default result code.
1280N/A ResultCode resultCode = ResultCode.SUCCESS;
1280N/A boolean adminActionRequired = false;
2086N/A ArrayList<Message> messages = new ArrayList<Message>();
1280N/A
1280N/A sizeLimit = config.getFileSizeLimit();
1280N/A
1280N/A currentConfig = config;
1280N/A
1280N/A return new ConfigChangeResult(resultCode, adminActionRequired, messages);
0N/A }
0N/A
0N/A /**
0N/A * This method indicates if the log file should be
0N/A * rotated or not.
0N/A *
1280N/A * @param writer The multi file text writer writing the log file.
0N/A * @return true if the file needs to be rotated, false otherwise.
0N/A */
7141N/A public boolean rotateFile(RotatableLogFile writer)
0N/A {
1400N/A long fileSize = writer.getBytesWritten();
1400N/A
1400N/A return fileSize >= sizeLimit;
0N/A }
0N/A
0N/A}
0N/A