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 018package 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 * @see AbstractLifeCycle 031 */ 032public interface LifeCycle { 033 034 /** 035 * Status of a life cycle like a {@link LoggerContext}. 036 */ 037 enum State { 038 /** Object is in its initial state and not yet initialized. */ 039 INITIALIZING, 040 /** Initialized but not yet started. */ 041 INITIALIZED, 042 /** In the process of starting. */ 043 STARTING, 044 /** Has started. */ 045 STARTED, 046 /** Stopping is in progress. */ 047 STOPPING, 048 /** Has stopped. */ 049 STOPPED 050 } 051 052 /** 053 * Gets the life-cycle state. 054 * 055 * @return the life-cycle state 056 */ 057 State getState(); 058 059 void initialize(); 060 061 void start(); 062 063 void stop(); 064 065 boolean isStarted(); 066 067 boolean isStopped(); 068 069}