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 java.io.Serializable;
20
21 import org.apache.logging.log4j.status.StatusLogger;
22
23
24
25
26
27
28
29 public class AbstractLifeCycle implements LifeCycle, Serializable {
30
31
32
33
34 protected static final org.apache.logging.log4j.Logger LOGGER = StatusLogger.getLogger();
35
36 private static final long serialVersionUID = 1L;
37
38 private volatile LifeCycle.State state = LifeCycle.State.INITIALIZED;
39
40 @Override
41 public boolean equals(final Object obj) {
42 if (this == obj) {
43 return true;
44 }
45 if (obj == null) {
46 return false;
47 }
48 if (getClass() != obj.getClass()) {
49 return false;
50 }
51 final AbstractLifeCycle other = (AbstractLifeCycle) obj;
52 if (state != other.state) {
53 return false;
54 }
55 return true;
56 }
57
58 public LifeCycle.State getState() {
59 return this.state;
60 }
61
62 @Override
63 public int hashCode() {
64 final int prime = 31;
65 int result = 1;
66 result = prime * result + ((state == null) ? 0 : state.hashCode());
67 return result;
68 }
69
70 public boolean isInitialized() {
71 return this.state == LifeCycle.State.INITIALIZED;
72 }
73
74 @Override
75 public boolean isStarted() {
76 return this.state == LifeCycle.State.STARTED;
77 }
78
79 public boolean isStarting() {
80 return this.state == LifeCycle.State.STARTING;
81 }
82
83 @Override
84 public boolean isStopped() {
85 return this.state == LifeCycle.State.STOPPED;
86 }
87
88 public boolean isStopping() {
89 return this.state == LifeCycle.State.STOPPING;
90 }
91
92 protected void setStarted() {
93 this.setState(LifeCycle.State.STARTED);
94 }
95
96 protected void setStarting() {
97 this.setState(LifeCycle.State.STARTING);
98 }
99
100 protected void setState(final LifeCycle.State newState) {
101 this.state = newState;
102
103
104 }
105
106 protected void setStopped() {
107 this.setState(LifeCycle.State.STOPPED);
108 }
109
110 protected void setStopping() {
111 this.setState(LifeCycle.State.STOPPING);
112 }
113
114 @Override
115 public void start() {
116 this.setStarted();
117 }
118
119 @Override
120 public void stop() {
121 this.state = LifeCycle.State.STOPPED;
122 }
123
124 }