001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.kernel.config;
017:
018: import java.util.LinkedHashSet;
019: import java.util.LinkedHashMap;
020: import java.util.Set;
021: import java.util.Map;
022: import java.util.Collections;
023: import java.util.Iterator;
024: import java.io.Serializable;
025:
026: import org.apache.geronimo.kernel.repository.Artifact;
027:
028: /**
029: * This class contains the results of a lifecycle operation on the configuation manager.
030: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
031: */
032: public class LifecycleResults implements Serializable {
033: private static final long serialVersionUID = 4660197333193740244L;
034: private final Set loaded = new LinkedHashSet();
035: private final Set unloaded = new LinkedHashSet();
036: private final Set started = new LinkedHashSet();
037: private final Set stopped = new LinkedHashSet();
038: private final Map failed = new LinkedHashMap();
039:
040: /**
041: * Checks whether the specified configuration was loaded.
042: *
043: * @param configurationId the configuration identifier, which must be fully
044: * resolved (isResolved() == true)
045: *
046: * @return true if the specified configuration was loaded during the lifecycle operation
047: */
048: public boolean wasLoaded(Artifact configurationId) {
049: return loaded.contains(configurationId);
050: }
051:
052: /**
053: * Gets the configuration identifiers (Artifact) of the configurations loaded.
054: * @return the configuration identifiers (Artifact)
055: */
056: public Set getLoaded() {
057: return Collections.unmodifiableSet(loaded);
058: }
059:
060: /**
061: * Adds a configuration the set of loaded configurations.
062: * @param configurationId the configuration identifiers (Artifact)
063: */
064: public void addLoaded(Artifact configurationId) {
065: loaded.add(configurationId);
066: }
067:
068: /**
069: * Clears the existing loaded set and add alls the specified configurations to the set
070: * @param loaded the configuration identifiers (Artifact)
071: */
072: public void setLoaded(Set loaded) {
073: this .loaded.clear();
074: this .loaded.addAll(loaded);
075: }
076:
077: /**
078: * Checks whether the specified configuration was unloaded.
079: *
080: * @param configurationId the configuration identifier, which must be fully
081: * resolved (isResolved() == true)
082: *
083: * @return true if the specified configuration was unloaded during the lifecycle operation
084: */
085: public boolean wasUnloaded(Artifact configurationId) {
086: return unloaded.contains(configurationId);
087: }
088:
089: /**
090: * Gets the configuration identifiers (Artifact) of the configurations unloaded.
091: * @return the configuration identifiers (Artifact)
092: */
093: public Set getUnloaded() {
094: return Collections.unmodifiableSet(unloaded);
095: }
096:
097: /**
098: * Adds a configuration the set of unloaded configurations.
099: * @param configurationId the configuration identifiers (Artifact)
100: */
101: public void addUnloaded(Artifact configurationId) {
102: unloaded.add(configurationId);
103: }
104:
105: /**
106: * Clears the existing unloaded set and add alls the specified configurations to the set
107: * @param unloaded the configuration identifiers (Artifact)
108: */
109: public void setUnloaded(Set unloaded) {
110: this .unloaded.clear();
111: this .unloaded.addAll(unloaded);
112: }
113:
114: /**
115: * Checks whether the specified configuration was started.
116: *
117: * @param configurationId the configuration identifier, which must be fully
118: * resolved (isResolved() == true)
119: *
120: * @return true if the specified configuration was started during the lifecycle operation
121: */
122: public boolean wasStarted(Artifact configurationId) {
123: return started.contains(configurationId);
124: }
125:
126: /**
127: * Gets the configuration identifiers (Artifact) of the configurations started.
128: * @return the configuration identifiers (Artifact)
129: */
130: public Set getStarted() {
131: return Collections.unmodifiableSet(started);
132: }
133:
134: /**
135: * Adds a configuration the set of started configurations.
136: * @param configurationId the configuration identifiers (Artifact)
137: */
138: public void addStarted(Artifact configurationId) {
139: started.add(configurationId);
140: }
141:
142: /**
143: * Clears the existing started set and add alls the specified configurations to the set
144: * @param started the configuration identifiers (Artifact)
145: */
146: public void setStarted(Set started) {
147: this .started.clear();
148: this .started.addAll(started);
149: }
150:
151: /**
152: * Checks whether the specified configuration was stopped.
153: *
154: * @param configurationId the configuration identifier, which must be fully
155: * resolved (isResolved() == true)
156: *
157: * @return true if the specified configuration was stopped during the lifecycle operation
158: */
159: public boolean wasStopped(Artifact configurationId) {
160: return stopped.contains(configurationId);
161: }
162:
163: /**
164: * Gets the configuration identifiers (Artifact) of the configurations stopped.
165: * @return the configuration identifiers (Artifact)
166: */
167: public Set getStopped() {
168: return Collections.unmodifiableSet(stopped);
169: }
170:
171: /**
172: * Adds a configuration the set of stopped configurations.
173: * @param configurationId the configuration identifiers (Artifact)
174: */
175: public void addStopped(Artifact configurationId) {
176: stopped.add(configurationId);
177: }
178:
179: /**
180: * Clears the existing stopped set and add alls the specified configurations to the set
181: * @param stopped the configuration identifiers (Artifact)
182: */
183: public void setStopped(Set stopped) {
184: this .stopped.clear();
185: this .stopped.addAll(stopped);
186: }
187:
188: /**
189: * Was the specified configuration failed the operation and threw an
190: * exception.
191: *
192: * @param configurationId the configuration identifier. May be a partial
193: * ID, in which case will check whether any
194: * matching conifguration failed.
195: *
196: * @return true if the specified (or any matching) configuration failed
197: * the operation and threw an exception during the lifecycle
198: * operation
199: */
200: public boolean wasFailed(Artifact configurationId) {
201: for (Iterator it = failed.keySet().iterator(); it.hasNext();) {
202: Artifact failID = (Artifact) it.next();
203: if (configurationId.matches(failID)) {
204: return true;
205: }
206: }
207: return false;
208: }
209:
210: /**
211: * Gets the exception that caused the operation on the specified configuration to fail.
212: * @return the configuration identifiers (Artifact)
213: */
214: public Throwable getFailedCause(Artifact configurationId) {
215: return (Throwable) failed.get(configurationId);
216: }
217:
218: /**
219: * Gets the configuration identifiers (Artifact) of the configurations that failed the operation and threw an exception.
220: * @return the configuration identifiers (Artifact)
221: */
222: public Map getFailed() {
223: return Collections.unmodifiableMap(failed);
224: }
225:
226: /**
227: * Adds a configuration and associated causal exception to this result.
228: * @param configurationId the configuration identifiers (Artifact)
229: * @param cause the exception that caused the operation on the specified configuration to fail
230: */
231: public void addFailed(Artifact configurationId, Throwable cause) {
232: failed.put(configurationId, cause);
233: }
234:
235: /**
236: * Clears the existing failed map and add alls the specified configurations to the map
237: * @param failed a map from configuration identifier (Artifact) to causal exception
238: */
239: public void setFailed(Map failed) {
240: this.failed.clear();
241: this.failed.putAll(failed);
242: }
243: }
|