• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aspectran / aspectran / #3971

08 Jan 2025 12:17PM CUT coverage: 35.017% (-0.009%) from 35.026%
#3971

push

github

topframe
Update

8 of 27 new or added lines in 6 files covered. (29.63%)

7 existing lines in 5 files now uncovered.

14188 of 40517 relevant lines covered (35.02%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/utils/src/main/java/com/aspectran/utils/lifecycle/LifeCycle.java
1
/*
2
 * Copyright (c) 2008-2025 The Aspectran Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.aspectran.utils.lifecycle;
17

18
import java.util.EventListener;
19

20
/**
21
 * The lifecycle interface for generic components.
22
 * <p>
23
 * Classes implementing this interface have a defined life cycle
24
 * defined by the methods of this interface.</p>
25
 */
26
public interface LifeCycle {
27

28
    String STOPPED = "STOPPED";
29

30
    String FAILED = "FAILED";
31

32
    String STARTING = "STARTING";
33

34
    String STARTED = "STARTED";
35

36
    String STOPPING = "STOPPING";
37

38
    String RUNNING = "RUNNING";
39

40
    /**
41
     * Starts the component.
42
     * @throws Exception If the component fails to start
43
     * @see #isStarted()
44
     * @see #stop()
45
     * @see #isFailed()
46
     */
47
    void start() throws Exception;
48

49
    /**
50
     * Stops the component.
51
     * The component may wait for current activities to complete
52
     * normally, but it can be interrupted.
53
     * @throws Exception If the component fails to stop
54
     * @see #isStopped()
55
     * @see #start()
56
     * @see #isFailed()
57
     */
58
    void stop() throws Exception;
59

60
    /**
61
     * @return true if the component is starting or has been started
62
     */
63
    boolean isRunning();
64

65
    /**
66
     * @return true if the component has been started.
67
     * @see #start()
68
     * @see #isStarting()
69
     */
70
    boolean isStarted();
71

72
    /**
73
     * @return true if the component is starting
74
     * @see #isStarted()
75
     */
76
    boolean isStarting();
77

78
    /**
79
     * @return true if the component is stopping
80
     * @see #isStopped()
81
     */
82
    boolean isStopping();
83

84
    /**
85
     * @return true if the component has been stopped
86
     * @see #stop()
87
     * @see #isStopping()
88
     */
89
    boolean isStopped();
90

91
    /**
92
     * @return true if the component has failed to start or has failed to stop
93
     */
94
    boolean isFailed();
95

96
    void addLifeCycleListener(LifeCycle.Listener listener);
97

98
    void removeLifeCycleListener(LifeCycle.Listener listener);
99

100
    String getState();
101

102
    /**
103
     * A listener for Lifecycle events.
104
     */
105
    interface Listener extends EventListener {
106

107
        default void lifeCycleStarting(LifeCycle event) {
108
        }
×
109

110
        default void lifeCycleStarted(LifeCycle event) {
111
        }
×
112

113
        default void lifeCycleFailure(LifeCycle event, Throwable cause) {
114
        }
×
115

116
        default void lifeCycleStopping(LifeCycle event) {
117
        }
×
118

119
        default void lifeCycleStopped(LifeCycle event) {
120
        }
×
121

122
    }
123

124
    /**
125
     * Utility to start an object if it is a LifeCycle and to convert
126
     * any exception thrown to a {@link RuntimeException}.
127
     * @param object the instance to start.
128
     * @throws RuntimeException if the call to start throws an exception
129
     */
130
    static void start(Object object) {
NEW
131
        if (object instanceof LifeCycle lifeCycle) {
×
132
            try {
NEW
133
                lifeCycle.start();
×
134
            } catch (Exception e) {
×
135
                throw new RuntimeException(e);
×
136
            }
×
137
        }
138
    }
×
139

140
    /**
141
     * Utility to stop an object if it is a LifeCycle and to convert
142
     * any exception thrown to a {@link RuntimeException}.
143
     * @param object the instance to stop.
144
     * @throws RuntimeException if the call to stop throws an exception
145
     */
146
    static void stop(Object object) {
NEW
147
        if (object instanceof LifeCycle lifeCycle) {
×
148
            try {
NEW
149
                lifeCycle.stop();
×
150
            } catch (Exception e) {
×
151
                throw new RuntimeException(e);
×
152
            }
×
153
        }
154
    }
×
155

156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc