View Javadoc

1   /**
2    *
3    * Copyright 2005 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  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.geronimo.kernel.config;
18  
19  import java.util.LinkedHashSet;
20  import java.util.LinkedHashMap;
21  import java.util.Set;
22  import java.util.Map;
23  import java.util.Collections;
24  import java.util.Iterator;
25  import java.io.Serializable;
26  
27  import org.apache.geronimo.kernel.repository.Artifact;
28  
29  /**
30   * This class contains the results of a lifecycle operation on the configuation manager.
31   * @version $Rev: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 2006) $
32   */
33  public class LifecycleResults implements Serializable {
34      private static final long serialVersionUID = 4660197333193740244L;
35      private final Set loaded = new LinkedHashSet();
36      private final Set unloaded = new LinkedHashSet();
37      private final Set started = new LinkedHashSet();
38      private final Set stopped = new LinkedHashSet();
39      private final Map failed = new LinkedHashMap();
40  
41      /**
42       * Checks whether the specified configuration was loaded.
43       *
44       * @param configurationId the configuration identifier, which must be fully
45       *                        resolved (isResolved() == true)
46       *
47       * @return true if the specified configuration was loaded during the lifecycle operation
48       */
49      public boolean wasLoaded(Artifact configurationId) {
50          return loaded.contains(configurationId);
51      }
52  
53      /**
54       * Gets the configuration identifiers (Artifact) of the configurations loaded.
55       * @return the configuration identifiers (Artifact)
56       */
57      public Set getLoaded() {
58          return Collections.unmodifiableSet(loaded);
59      }
60  
61      /**
62       * Adds a configuration the set of loaded configurations.
63       * @param configurationId the configuration identifiers (Artifact)
64       */
65      public void addLoaded(Artifact configurationId) {
66          loaded.add(configurationId);
67      }
68  
69      /**
70       * Clears the existing loaded set and add alls the specified configurations to the set
71       * @param loaded the configuration identifiers (Artifact)
72       */
73      public void setLoaded(Set loaded) {
74          this.loaded.clear();
75          this.loaded.addAll(loaded);
76      }
77  
78      /**
79       * Checks whether the specified configuration was unloaded.
80       *
81       * @param configurationId the configuration identifier, which must be fully
82       *                        resolved (isResolved() == true)
83       *
84       * @return true if the specified configuration was unloaded during the lifecycle operation
85       */
86      public boolean wasUnloaded(Artifact configurationId) {
87          return unloaded.contains(configurationId);
88      }
89  
90      /**
91       * Gets the configuration identifiers (Artifact) of the configurations unloaded.
92       * @return the configuration identifiers (Artifact)
93       */
94      public Set getUnloaded() {
95          return Collections.unmodifiableSet(unloaded);
96      }
97  
98      /**
99       * Adds a configuration the set of unloaded configurations.
100      * @param configurationId the configuration identifiers (Artifact)
101      */
102     public void addUnloaded(Artifact configurationId) {
103         unloaded.add(configurationId);
104     }
105 
106     /**
107      * Clears the existing unloaded set and add alls the specified configurations to the set
108      * @param unloaded the configuration identifiers (Artifact)
109      */
110     public void setUnloaded(Set unloaded) {
111         this.unloaded.clear();
112         this.unloaded.addAll(unloaded);
113     }
114 
115     /**
116      * Checks whether the specified configuration was started.
117      *
118      * @param configurationId the configuration identifier, which must be fully
119      *                        resolved (isResolved() == true)
120      *
121      * @return true if the specified configuration was started during the lifecycle operation
122      */
123     public boolean wasStarted(Artifact configurationId) {
124         return started.contains(configurationId);
125     }
126 
127     /**
128      * Gets the configuration identifiers (Artifact) of the configurations started.
129      * @return the configuration identifiers (Artifact)
130      */
131     public Set getStarted() {
132         return Collections.unmodifiableSet(started);
133     }
134 
135     /**
136      * Adds a configuration the set of started configurations.
137      * @param configurationId the configuration identifiers (Artifact)
138      */
139     public void addStarted(Artifact configurationId) {
140         started.add(configurationId);
141     }
142 
143     /**
144      * Clears the existing started set and add alls the specified configurations to the set
145      * @param started the configuration identifiers (Artifact)
146      */
147     public void setStarted(Set started) {
148         this.started.clear();
149         this.started.addAll(started);
150     }
151 
152     /**
153      * Checks whether the specified configuration was stopped.
154      *
155      * @param configurationId the configuration identifier, which must be fully
156      *                        resolved (isResolved() == true)
157      *
158      * @return true if the specified configuration was stopped during the lifecycle operation
159      */
160     public boolean wasStopped(Artifact configurationId) {
161         return stopped.contains(configurationId);
162     }
163 
164     /**
165      * Gets the configuration identifiers (Artifact) of the configurations stopped.
166      * @return the configuration identifiers (Artifact)
167      */
168     public Set getStopped() {
169         return Collections.unmodifiableSet(stopped);
170     }
171 
172     /**
173      * Adds a configuration the set of stopped configurations.
174      * @param configurationId the configuration identifiers (Artifact)
175      */
176     public void addStopped(Artifact configurationId) {
177         stopped.add(configurationId);
178     }
179 
180     /**
181      * Clears the existing stopped set and add alls the specified configurations to the set
182      * @param stopped the configuration identifiers (Artifact)
183      */
184     public void setStopped(Set stopped) {
185         this.stopped.clear();
186         this.stopped.addAll(stopped);
187     }
188 
189     /**
190      * Was the specified configuration failed the operation and threw an
191      * exception.
192      *
193      * @param configurationId the configuration identifier.  May be a partial
194      *                        ID, in which case will check whether any
195      *                        matching conifguration failed.
196      *
197      * @return true if the specified (or any matching) configuration failed
198      *              the operation and threw an exception during the lifecycle
199      *              operation
200      */
201     public boolean wasFailed(Artifact configurationId) {
202         for (Iterator it = failed.keySet().iterator(); it.hasNext();) {
203             Artifact failID = (Artifact) it.next();
204             if(configurationId.matches(failID)) {
205                 return true;
206             }
207         }
208         return false;
209     }
210 
211     /**
212      * Gets the exception that caused the operation on the specified configuration to fail.
213      * @return the configuration identifiers (Artifact)
214      */
215     public Throwable getFailedCause(Artifact configurationId) {
216         return (Throwable) failed.get(configurationId);
217     }
218 
219     /**
220      * Gets the configuration identifiers (Artifact) of the configurations that failed the operation and threw an exception.
221      * @return the configuration identifiers (Artifact)
222      */
223     public Map getFailed() {
224         return Collections.unmodifiableMap(failed);
225     }
226 
227     /**
228      * Adds a configuration and associated causal exception to this result.
229      * @param configurationId the configuration identifiers (Artifact)
230      * @param cause the exception that caused the operation on the specified configuration to fail
231      */
232     public void addFailed(Artifact configurationId, Throwable cause) {
233         failed.put(configurationId, cause);
234     }
235 
236     /**
237      * Clears the existing failed map and add alls the specified configurations to the map
238      * @param failed a map from configuration identifier (Artifact) to causal exception
239      */
240     public void setFailed(Map failed) {
241         this.failed.clear();
242         this.failed.putAll(failed);
243     }
244 }