View Javadoc

1   /*
2    * Copyright 2006-2009 the original author or authors.
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 org.springframework.osgi.extender.internal.dependencies.startup;
17  
18  /**
19   * State of an application context while being processed by {@link DependencyWaiterApplicationContextExecutor}.
20   * 
21   * This enumeration holds the state of an application context at a certain time, beyond the official states such as
22   * STARTED/STOPPED.
23   * 
24   * @author Hal Hildebrand
25   * @author Costin Leau
26   * 
27   */
28  public enum ContextState {
29  
30  	/**
31  	 * Application context has been initialized but not started (i.e. refresh hasn't been called).
32  	 */
33  	INITIALIZED,
34  
35  	/**
36  	 * Application context has been started but the OSGi service dependencies haven't been yet resolved.
37  	 */
38  	RESOLVING_DEPENDENCIES,
39  
40  	/**
41  	 * Application context has been started and the OSGi dependencies have been resolved. However the context is not
42  	 * fully initialized (i.e. refresh hasn't been completed).
43  	 */
44  	DEPENDENCIES_RESOLVED,
45  
46  	/**
47  	 * Application context has been fully initialized. The OSGi dependencies have been resolved and refresh has fully
48  	 * completed.
49  	 */
50  	STARTED,
51  
52  	/**
53  	 * Application context has been interrupted. This state occurs if the context is being closed before being fully
54  	 * started.
55  	 */
56  	INTERRUPTED,
57  
58  	/**
59  	 * Application context has been stopped. This can occur even only if the context has been fully started for example;
60  	 * otherwise {@link #INTERRUPTED} state should be used.
61  	 */
62  	STOPPED;
63  
64  	/**
65  	 * Indicates whether the state is 'down' or not - that is a context which has been either closed or stopped.
66  	 * 
67  	 * @return true if the context has been interrupted or stopped, false otherwise.
68  	 */
69  	public boolean isDown() {
70  		return (this.equals(INTERRUPTED) || this.equals(STOPPED));
71  	}
72  
73  	/**
74  	 * Indicates whether the state is unresolved or not. An unresolved state means a state which is active (started) in
75  	 * RESOLVING_DEPENDENCIES state.
76  	 * 
77  	 * @return
78  	 */
79  	public boolean isUnresolved() {
80  		return (this.equals(RESOLVING_DEPENDENCIES) || this.equals(INITIALIZED));
81  	}
82  
83  	public boolean isResolved() {
84  		return !isUnresolved();
85  	}
86  }