001 /** 002 * 003 * Copyright 2005 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 */ 017 package org.apache.geronimo.kernel.config; 018 019 import java.util.LinkedHashSet; 020 import java.util.LinkedHashMap; 021 import java.util.Set; 022 import java.util.Map; 023 import java.util.Collections; 024 import java.util.Iterator; 025 import java.io.Serializable; 026 027 import org.apache.geronimo.kernel.repository.Artifact; 028 029 /** 030 * This class contains the results of a lifecycle operation on the configuation manager. 031 * @version $Rev: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 2006) $ 032 */ 033 public class LifecycleResults implements Serializable { 034 private static final long serialVersionUID = 4660197333193740244L; 035 private final Set loaded = new LinkedHashSet(); 036 private final Set unloaded = new LinkedHashSet(); 037 private final Set started = new LinkedHashSet(); 038 private final Set stopped = new LinkedHashSet(); 039 private final Map failed = new LinkedHashMap(); 040 041 /** 042 * Checks whether the specified configuration was loaded. 043 * 044 * @param configurationId the configuration identifier, which must be fully 045 * resolved (isResolved() == true) 046 * 047 * @return true if the specified configuration was loaded during the lifecycle operation 048 */ 049 public boolean wasLoaded(Artifact configurationId) { 050 return loaded.contains(configurationId); 051 } 052 053 /** 054 * Gets the configuration identifiers (Artifact) of the configurations loaded. 055 * @return the configuration identifiers (Artifact) 056 */ 057 public Set getLoaded() { 058 return Collections.unmodifiableSet(loaded); 059 } 060 061 /** 062 * Adds a configuration the set of loaded configurations. 063 * @param configurationId the configuration identifiers (Artifact) 064 */ 065 public void addLoaded(Artifact configurationId) { 066 loaded.add(configurationId); 067 } 068 069 /** 070 * Clears the existing loaded set and add alls the specified configurations to the set 071 * @param loaded the configuration identifiers (Artifact) 072 */ 073 public void setLoaded(Set loaded) { 074 this.loaded.clear(); 075 this.loaded.addAll(loaded); 076 } 077 078 /** 079 * Checks whether the specified configuration was unloaded. 080 * 081 * @param configurationId the configuration identifier, which must be fully 082 * resolved (isResolved() == true) 083 * 084 * @return true if the specified configuration was unloaded during the lifecycle operation 085 */ 086 public boolean wasUnloaded(Artifact configurationId) { 087 return unloaded.contains(configurationId); 088 } 089 090 /** 091 * Gets the configuration identifiers (Artifact) of the configurations unloaded. 092 * @return the configuration identifiers (Artifact) 093 */ 094 public Set getUnloaded() { 095 return Collections.unmodifiableSet(unloaded); 096 } 097 098 /** 099 * 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 }