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