| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | * Portions Copyright 2006-2008 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.loggers; |
| | | import org.opends.messages.Message; |
| | | import static org.opends.messages.LoggerMessages.ERR_LOGGER_ERROR_LISTING_FILES; |
| | | |
| | | import org.opends.server.admin.std.server.FileCountLogRetentionPolicyCfg; |
| | | import org.opends.server.admin.server.ConfigurationChangeListener; |
| | |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.types.ConfigChangeResult; |
| | | import org.opends.server.types.ResultCode; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | private static final DebugTracer TRACER = getTracer(); |
| | | |
| | | |
| | | private int numFiles = 0; |
| | | private FileCountLogRetentionPolicyCfg config; |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | |
| | | public void initializeLogRetentionPolicy( |
| | | FileCountLogRetentionPolicyCfg config) |
| | | { |
| | | numFiles = config.getNumberOfFiles(); |
| | | this.numFiles = config.getNumberOfFiles(); |
| | | this.config = config; |
| | | |
| | | config.addFileCountChangeListener(this); |
| | | } |
| | |
| | | boolean adminActionRequired = false; |
| | | ArrayList<Message> messages = new ArrayList<Message>(); |
| | | |
| | | numFiles = config.getNumberOfFiles(); |
| | | this.numFiles = config.getNumberOfFiles(); |
| | | this.config = config; |
| | | |
| | | return new ConfigChangeResult(resultCode, adminActionRequired, messages); |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public int deleteFiles(MultifileTextWriter writer) |
| | | public File[] deleteFiles(FileNamingPolicy fileNamingPolicy) |
| | | throws DirectoryException |
| | | { |
| | | int count = 0; |
| | | File[] files = writer.getNamingPolicy().listFiles(); |
| | | File[] files = fileNamingPolicy.listFiles(); |
| | | if(files == null) |
| | | { |
| | | Message message = |
| | | ERR_LOGGER_ERROR_LISTING_FILES.get( |
| | | fileNamingPolicy.getInitialName().toString()); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message); |
| | | } |
| | | |
| | | ArrayList<File> filesToDelete = new ArrayList<File>(); |
| | | |
| | | if (files.length <= numFiles) |
| | | { |
| | | return 0; |
| | | return new File[0]; |
| | | } |
| | | |
| | | // Sort files based on last modified time. |
| | |
| | | |
| | | for (int j = numFiles; j < files.length; j++) |
| | | { |
| | | if(debugEnabled()) |
| | | { |
| | | TRACER.debugInfo("Deleting log file:", files[j]); |
| | | } |
| | | files[j].delete(); |
| | | count++; |
| | | filesToDelete.add(files[j]); |
| | | } |
| | | |
| | | return count; |
| | | return filesToDelete.toArray(new File[0]); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public String toString() |
| | | { |
| | | return "Free Number Retention Policy " + config.dn().toString(); |
| | | } |
| | | } |
| | | |