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 java.util.Objects;
020
021import org.apache.logging.log4j.core.appender.rolling.action.Action;
022
023/**
024 * Description of actions needed to complete rollover.
025 */
026public final class RolloverDescriptionImpl implements RolloverDescription {
027    /**
028     * Active log file name after rollover.
029     */
030    private final String activeFileName;
031
032    /**
033     * Should active file be opened for appending.
034     */
035    private final boolean append;
036
037    /**
038     * Action to be completed after close of current active log file
039     * before returning control to caller.
040     */
041    private final Action synchronous;
042
043    /**
044     * Action to be completed after close of current active log file
045     * and before next rollover attempt, may be executed asynchronously.
046     */
047    private final Action asynchronous;
048
049    /**
050     * Create new instance.
051     *
052     * @param activeFileName active log file name after rollover, may not be null.
053     * @param append         true if active log file after rollover should be opened for appending.
054     * @param synchronous    action to be completed after close of current active log file, may be null.
055     * @param asynchronous   action to be completed after close of current active log file and
056     *                       before next rollover attempt.
057     */
058    public RolloverDescriptionImpl(final String activeFileName, final boolean append, final Action synchronous,
059                                   final Action asynchronous) {
060        Objects.requireNonNull(activeFileName, "activeFileName");
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}