1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core;
18
19 import org.apache.logging.log4j.status.StatusLogger;
20
21
22
23
24
25
26
27 public class AbstractLifeCycle implements LifeCycle {
28
29
30
31
32 protected static final org.apache.logging.log4j.Logger LOGGER = StatusLogger.getLogger();
33
34 private volatile LifeCycle.State state = LifeCycle.State.INITIALIZED;
35
36 public LifeCycle.State getState() {
37 return this.state;
38 }
39
40 public boolean isInitialized() {
41 return this.state == LifeCycle.State.INITIALIZED;
42 }
43
44 @Override
45 public boolean isStarted() {
46 return this.state == LifeCycle.State.STARTED;
47 }
48
49 public boolean isStarting() {
50 return this.state == LifeCycle.State.STARTING;
51 }
52
53 @Override
54 public boolean isStopped() {
55 return this.state == LifeCycle.State.STOPPED;
56 }
57
58 public boolean isStopping() {
59 return this.state == LifeCycle.State.STOPPING;
60 }
61
62 protected void setStarted() {
63 this.setState(LifeCycle.State.STARTED);
64 }
65
66 protected void setStarting() {
67 this.setState(LifeCycle.State.STARTING);
68 }
69
70 protected void setState(final LifeCycle.State newState) {
71 this.state = newState;
72
73
74 }
75
76 protected void setStopped() {
77 this.setState(LifeCycle.State.STOPPED);
78 }
79
80 protected void setStopping() {
81 this.setState(LifeCycle.State.STOPPING);
82 }
83
84 @Override
85 public void start() {
86 this.setStarted();
87 }
88
89 @Override
90 public void stop() {
91 this.state = LifeCycle.State.STOPPED;
92 }
93
94 }