1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.catalina;
18
19 /**
20  * The list of valid states for components that implement {@link Lifecycle}.
21  * See {@link Lifecycle} for the state transition diagram.
22  */

23 public enum LifecycleState {
24     NEW(falsenull),
25     INITIALIZING(false, Lifecycle.BEFORE_INIT_EVENT),
26     INITIALIZED(false, Lifecycle.AFTER_INIT_EVENT),
27     STARTING_PREP(false, Lifecycle.BEFORE_START_EVENT),
28     STARTING(true, Lifecycle.START_EVENT),
29     STARTED(true, Lifecycle.AFTER_START_EVENT),
30     STOPPING_PREP(true, Lifecycle.BEFORE_STOP_EVENT),
31     STOPPING(false, Lifecycle.STOP_EVENT),
32     STOPPED(false, Lifecycle.AFTER_STOP_EVENT),
33     DESTROYING(false, Lifecycle.BEFORE_DESTROY_EVENT),
34     DESTROYED(false, Lifecycle.AFTER_DESTROY_EVENT),
35     FAILED(falsenull);
36
37     private final boolean available;
38     private final String lifecycleEvent;
39
40     private LifecycleState(boolean available, String lifecycleEvent) {
41         this.available = available;
42         this.lifecycleEvent = lifecycleEvent;
43     }
44
45     /**
46      * May the public methods other than property getters/setters and lifecycle
47      * methods be called for a component in this state? It returns
48      * <code>true</code> for any component in any of the following states:
49      * <ul>
50      * <li>{@link #STARTING}</li>
51      * <li>{@link #STARTED}</li>
52      * <li>{@link #STOPPING_PREP}</li>
53      * </ul>
54      *
55      * @return <code>true</code> if the component is available for use,
56      *         otherwise <code>false</code>
57      */

58     public boolean isAvailable() {
59         return available;
60     }
61
62     public String getLifecycleEvent() {
63         return lifecycleEvent;
64     }
65 }
66