001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.core.appender.rolling;
018
019import org.apache.logging.log4j.core.appender.rolling.action.Action;
020
021/**
022 * Description of actions needed to complete rollover.
023 */
024public final class RolloverDescriptionImpl implements RolloverDescription {
025    /**
026     * Active log file name after rollover.
027     */
028    private final String activeFileName;
029
030    /**
031     * Should active file be opened for appending.
032     */
033    private final boolean append;
034
035    /**
036     * Action to be completed after close of current active log file
037     * before returning control to caller.
038     */
039    private final Action synchronous;
040
041    /**
042     * Action to be completed after close of current active log file
043     * and before next rollover attempt, may be executed asynchronously.
044     */
045    private final Action asynchronous;
046
047    /**
048     * Create new instance.
049     *
050     * @param activeFileName active log file name after rollover, may not be null.
051     * @param append         true if active log file after rollover should be opened for appending.
052     * @param synchronous    action to be completed after close of current active log file, may be null.
053     * @param asynchronous   action to be completed after close of current active log file and
054     *                       before next rollover attempt.
055     */
056    public RolloverDescriptionImpl(final String activeFileName, final boolean append, final Action synchronous,
057                                   final Action asynchronous) {
058        if (activeFileName == null) {
059            throw new NullPointerException("activeFileName");
060        }
061
062        this.append = append;
063        this.activeFileName = activeFileName;
064        this.synchronous = synchronous;
065        this.asynchronous = asynchronous;
066    }
067
068    /**
069     * Active log file name after rollover.
070     *
071     * @return active log file name after rollover.
072     */
073    @Override
074    public String getActiveFileName() {
075        return activeFileName;
076    }
077
078    /**
079     * {@inheritDoc}
080     */
081    @Override
082    public boolean getAppend() {
083        return append;
084    }
085
086    /**
087     * Action to be completed after close of current active log file
088     * before returning control to caller.
089     *
090     * @return action, may be null.
091     */
092    @Override
093    public Action getSynchronous() {
094        return synchronous;
095    }
096
097    /**
098     * Action to be completed after close of current active log file
099     * and before next rollover attempt, may be executed asynchronously.
100     *
101     * @return action, may be null.
102     */
103    @Override
104    public Action getAsynchronous() {
105        return asynchronous;
106    }
107}