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 protected boolean equalsImpl(final Object obj) {
41 if (this == obj) {
42 return true;
43 }
44 if (obj == null) {
45 return false;
46 }
47 if (getClass() != obj.getClass()) {
48 return false;
49 }
50 final LifeCycle other = (LifeCycle) obj;
51 if (state != other.getState()) {
52 return false;
53 }
54 return true;
55 }
56
57 @Override
58 public LifeCycle.State getState() {
59 return this.state;
60 }
61
62 protected int hashCodeImpl() {
63 final int prime = 31;
64 int result = 1;
65 result = prime * result + ((state == null) ? 0 : state.hashCode());
66 return result;
67 }
68
69 public boolean isInitialized() {
70 return this.state == LifeCycle.State.INITIALIZED;
71 }
72
73 @Override
74 public boolean isStarted() {
75 return this.state == LifeCycle.State.STARTED;
76 }
77
78 public boolean isStarting() {
79 return this.state == LifeCycle.State.STARTING;
80 }
81
82 @Override
83 public boolean isStopped() {
84 return this.state == LifeCycle.State.STOPPED;
85 }
86
87 public boolean isStopping() {
88 return this.state == LifeCycle.State.STOPPING;
89 }
90
91 protected void setStarted() {
92 this.setState(LifeCycle.State.STARTED);
93 }
94
95 protected void setStarting() {
96 this.setState(LifeCycle.State.STARTING);
97 }
98
99 protected void setState(final LifeCycle.State newState) {
100 this.state = newState;
101
102
103 }
104
105 protected void setStopped() {
106 this.setState(LifeCycle.State.STOPPED);
107 }
108
109 protected void setStopping() {
110 this.setState(LifeCycle.State.STOPPING);
111 }
112
113 @Override
114 public void start() {
115 this.setStarted();
116 }
117
118 @Override
119 public void stop() {
120 this.state = LifeCycle.State.STOPPED;
121 }
122
123 }