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     */
017    
018    package org.apache.logging.log4j.core;
019    
020    /**
021     * All proper Java frameworks implement some sort of object life cycle. In Log4j, the main interface for handling
022     * the life cycle context of an object is this one. An object first starts in the {@link State#INITIALIZED} state
023     * by default to indicate the class has been loaded. From here, calling the {@link #start()} method will change this
024     * state to {@link State#STARTING}. After successfully being started, this state is changed to {@link State#STARTED}.
025     * When the {@link #stop()} is called, this goes into the {@link State#STOPPING} state. After successfully being
026     * stopped, this goes into the {@link State#STOPPED} state. In most circumstances, implementation classes should
027     * store their {@link State} in a {@code volatile} field or inside an
028     * {@link java.util.concurrent.atomic.AtomicReference} dependent on synchronization and concurrency requirements.
029     */
030    public interface LifeCycle {
031        
032        /**
033         * Status of a life cycle like a {@link LoggerContext}.
034         */
035        public enum State {
036            /** Initialized but not yet started. */
037            INITIALIZED,
038            /** In the process of starting. */
039            STARTING,
040            /** Has started. */
041            STARTED,
042            /** Stopping is in progress. */
043            STOPPING,
044            /** Has stopped. */
045            STOPPED
046        }
047        
048        /**
049         * Gets the life-cycle state
050         * 
051         * @return the life-cycle state
052         */
053        State getState();
054        
055        void start();
056    
057        void stop();
058    
059        boolean isStarted();
060    
061        boolean isStopped();
062    }