1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.osgi.extender.internal.dependencies.startup;
17
18 import org.springframework.core.enums.StaticLabeledEnum;
19
20 /**
21 * State of an application context while being processed by
22 * {@link DependencyWaiterApplicationContextExecutor}.
23 *
24 * This enumeration holds the state of an application context at a certain time,
25 * beyond the official states such as STARTED/STOPPED.
26 *
27 * @author Hal Hildebrand
28 * @author Costin Leau
29 *
30 */
31 public class ContextState extends StaticLabeledEnum {
32
33 private static final long serialVersionUID = 5799223470478297089L;
34
35 /**
36 * Application context has been initialized but not started (i.e. refresh
37 * hasn't been called).
38 */
39 public static final ContextState INITIALIZED = new ContextState(0, "initialized");
40
41 /**
42 * Application context has been started but the OSGi service dependencies
43 * haven't been yet resolved.
44 */
45 public static final ContextState RESOLVING_DEPENDENCIES = new ContextState(1, "resolving-dependencies");
46
47 /**
48 * Application context has been started and the OSGi dependencies have been
49 * resolved. However the context is not fully initialized (i.e. refresh
50 * hasn't been completed).
51 */
52 public static final ContextState DEPENDENCIES_RESOLVED = new ContextState(2, "dependencies-resolved");
53
54 /**
55 * Application context has been fully initialized. The OSGi dependencies
56 * have been resolved and refresh has fully completed.
57 */
58 public static final ContextState STARTED = new ContextState(3, "started");
59
60 /**
61 * Application context has been interruped. This state occurs if the context
62 * is being closed before being fully started.
63 */
64 public static final ContextState INTERRUPTED = new ContextState(4, "interrupted");
65
66 /**
67 * Application context has been stopped. This can occur even only if the
68 * context has been fully started for example; otherwise
69 * {@link #INTERRUPTED} state should be used.
70 */
71 public static final ContextState STOPPED = new ContextState(5, "stopped");
72
73 /**
74 * Constructs a new <code>ContextState</code> instance.
75 *
76 * @param value
77 * @param name
78 */
79 private ContextState(int value, String name) {
80 super(value, name);
81 }
82
83 /**
84 * Indicates whether the state is 'down' or not - that is a context which
85 * has been either closed or stopped.
86 *
87 * @return true if the context has been interrupted or stopped, false
88 * otherwise.
89 */
90 public boolean isDown() {
91 return (this == INTERRUPTED || this == STOPPED);
92 }
93
94 /**
95 * Indicates whether the state is unresolved or not. An unresolved state
96 * means a state which is active (started) in RESOLVING_DEPENDENCIES state.
97 *
98 * @return
99 */
100 public boolean isUnresolved() {
101 return (this == RESOLVING_DEPENDENCIES || this == INITIALIZED);
102 }
103
104 public boolean isResolved() {
105 return !isUnresolved();
106 }
107 }