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