package org.apache.logging.log4j.core;

import org.apache.logging.log4j.status.StatusLogger;

public class AbstractLifeCycle implements LifeCycle {
   protected static final org.apache.logging.log4j.Logger LOGGER = StatusLogger.getLogger();
   private volatile LifeCycle.State state;

   public AbstractLifeCycle() {
      this.state = LifeCycle.State.INITIALIZED;
   }

   public LifeCycle.State getState() {
      return this.state;
   }

   public boolean isInitialized() {
      return this.state == LifeCycle.State.INITIALIZED;
   }

   public boolean isStarted() {
      return this.state == LifeCycle.State.STARTED;
   }

   public boolean isStarting() {
      return this.state == LifeCycle.State.STARTING;
   }

   public boolean isStopped() {
      return this.state == LifeCycle.State.STOPPED;
   }

   public boolean isStopping() {
      return this.state == LifeCycle.State.STOPPING;
   }

   protected void setStarted() {
      this.setState(LifeCycle.State.STARTED);
   }

   protected void setStarting() {
      this.setState(LifeCycle.State.STARTING);
   }

   protected void setState(LifeCycle.State newState) {
      this.state = newState;
   }

   protected void setStopped() {
      this.setState(LifeCycle.State.STOPPED);
   }

   protected void setStopping() {
      this.setState(LifeCycle.State.STOPPING);
   }

   public void start() {
      this.setStarted();
   }

   public void stop() {
      this.state = LifeCycle.State.STOPPED;
   }
}
