KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > kernel > config > SimpleConfigurationManager


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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.io.IOException JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.LinkedHashMap JavaDoc;
25 import java.util.LinkedHashSet JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.ListIterator JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.Set JavaDoc;
30 import java.util.HashSet JavaDoc;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34 import org.apache.geronimo.gbean.AbstractName;
35 import org.apache.geronimo.kernel.management.State;
36 import org.apache.geronimo.kernel.repository.Artifact;
37 import org.apache.geronimo.kernel.repository.ArtifactResolver;
38 import org.apache.geronimo.kernel.repository.Dependency;
39 import org.apache.geronimo.kernel.repository.Environment;
40 import org.apache.geronimo.kernel.repository.ImportType;
41 import org.apache.geronimo.kernel.repository.MissingDependencyException;
42 import org.apache.geronimo.kernel.repository.Version;
43
44 /**
45  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
46  */

47 public class SimpleConfigurationManager implements ConfigurationManager {
48     protected static final Log log = LogFactory.getLog(SimpleConfigurationManager.class);
49     protected final Collection JavaDoc stores;
50     private final ArtifactResolver artifactResolver;
51     protected final Map JavaDoc configurations = new LinkedHashMap JavaDoc();
52     protected final ConfigurationModel configurationModel = new ConfigurationModel();
53     protected final Collection JavaDoc repositories;
54     protected final Collection JavaDoc watchers;
55
56     /**
57      * When this is not null, it points to the "new" configuration that is
58      * part of an in-process reload operation. This configuration will
59      * definitely be loaded, but might not be started yet. It shold never be
60      * populated outside the scope of a reload operation.
61      */

62     private Configuration reloadingConfiguration;
63
64
65     public SimpleConfigurationManager(Collection JavaDoc stores, ArtifactResolver artifactResolver, Collection JavaDoc repositories) {
66         this(stores, artifactResolver, repositories, Collections.EMPTY_SET);
67     }
68     
69     public SimpleConfigurationManager(Collection JavaDoc stores, ArtifactResolver artifactResolver, Collection JavaDoc repositories, Collection JavaDoc watchers) {
70         if (stores == null) stores = Collections.EMPTY_SET;
71         if (repositories == null) repositories = Collections.EMPTY_SET;
72         if (watchers == null) watchers = Collections.EMPTY_SET;
73
74         this.stores = stores;
75         this.artifactResolver = artifactResolver;
76         this.repositories = repositories;
77         this.watchers = watchers;
78     }
79
80     public synchronized boolean isInstalled(Artifact configId) {
81         if(!configId.isResolved()) {
82             throw new IllegalArgumentException JavaDoc("Artifact "+configId+" is not fully resolved");
83         }
84         List JavaDoc storeSnapshot = getStoreList();
85         for (int i = 0; i < storeSnapshot.size(); i++) {
86             ConfigurationStore store = (ConfigurationStore) storeSnapshot.get(i);
87             if(store.containsConfiguration(configId)) {
88                 return true;
89             }
90         }
91         return false;
92     }
93
94     public synchronized boolean isLoaded(Artifact configId) {
95         if(!configId.isResolved()) {
96             throw new IllegalArgumentException JavaDoc("Artifact "+configId+" is not fully resolved");
97         }
98         if(reloadingConfiguration != null && reloadingConfiguration.getId().equals(configId)) {
99             return true;
100         }
101         return configurationModel.isLoaded(configId);
102     }
103
104     public synchronized boolean isRunning(Artifact configId) {
105         if(!configId.isResolved()) {
106             throw new IllegalArgumentException JavaDoc("Artifact "+configId+" is not fully resolved");
107         }
108         return configurationModel.isStarted(configId);
109     }
110
111     public Artifact[] getInstalled(Artifact query) {
112         Artifact[] all = artifactResolver.queryArtifacts(query);
113         List JavaDoc configs = new ArrayList JavaDoc();
114         for (int i = 0; i < all.length; i++) {
115             Artifact artifact = all[i];
116             if(isConfiguration(artifact)) {
117                 configs.add(artifact);
118             }
119         }
120         if(configs.size() == all.length) {
121             return all;
122         }
123         return (Artifact[]) configs.toArray(new Artifact[configs.size()]);
124     }
125
126     public Artifact[] getLoaded(Artifact query) {
127         return configurationModel.getLoaded(query);
128     }
129
130     public Artifact[] getRunning(Artifact query) {
131         return configurationModel.getStarted(query);
132     }
133
134
135     public List JavaDoc listStores() {
136         List JavaDoc storeSnapshot = getStoreList();
137         List JavaDoc result = new ArrayList JavaDoc(storeSnapshot.size());
138         for (int i = 0; i < storeSnapshot.size(); i++) {
139             ConfigurationStore store = (ConfigurationStore) storeSnapshot.get(i);
140             result.add(store.getAbstractName());
141         }
142         return result;
143     }
144
145     public ConfigurationStore[] getStores() {
146         List JavaDoc storeSnapshot = getStoreList();
147         return (ConfigurationStore[]) storeSnapshot.toArray(new ConfigurationStore[storeSnapshot.size()]);
148     }
149
150     public Collection JavaDoc getRepositories() {
151         return repositories;
152     }
153
154     public List JavaDoc listConfigurations() {
155         List JavaDoc storeSnapshot = getStoreList();
156         List JavaDoc list = new ArrayList JavaDoc();
157         for (int i = 0; i < storeSnapshot.size(); i++) {
158             ConfigurationStore store = (ConfigurationStore) storeSnapshot.get(i);
159             list.addAll(listConfigurations(store));
160         }
161         return list;
162     }
163
164     public ConfigurationStore getStoreForConfiguration(Artifact configId) {
165         if(!configId.isResolved()) {
166             throw new IllegalArgumentException JavaDoc("Artifact "+configId+" is not fully resolved");
167         }
168         List JavaDoc storeSnapshot = getStoreList();
169         for (int i = 0; i < storeSnapshot.size(); i++) {
170             ConfigurationStore store = (ConfigurationStore) storeSnapshot.get(i);
171             if(store.containsConfiguration(configId)) {
172                 return store;
173             }
174         }
175         return null;
176     }
177
178     public List JavaDoc listConfigurations(AbstractName storeName) throws NoSuchStoreException {
179         List JavaDoc storeSnapshot = getStoreList();
180         for (int i = 0; i < storeSnapshot.size(); i++) {
181             ConfigurationStore store = (ConfigurationStore) storeSnapshot.get(i);
182             if (storeName.equals(store.getAbstractName())) {
183                 return listConfigurations(store);
184             }
185         }
186         throw new NoSuchStoreException("No such store: " + storeName);
187     }
188
189     private List JavaDoc listConfigurations(ConfigurationStore store) {
190         List JavaDoc list = store.listConfigurations();
191         for (ListIterator JavaDoc iterator = list.listIterator(); iterator.hasNext();) {
192             ConfigurationInfo configurationInfo = (ConfigurationInfo) iterator.next();
193             if (isRunning(configurationInfo.getConfigID())) {
194                 configurationInfo = new ConfigurationInfo(store.getAbstractName(),
195                         configurationInfo.getConfigID(),
196                         configurationInfo.getType(),
197                         configurationInfo.getCreated(),
198                         configurationInfo.getOwnedConfigurations(),
199                         configurationInfo.getChildConfigurations(),
200                         configurationInfo.getInPlaceLocation(),
201                         State.RUNNING);
202             } else {
203                 configurationInfo = new ConfigurationInfo(store.getAbstractName(),
204                         configurationInfo.getConfigID(),
205                         configurationInfo.getType(),
206                         configurationInfo.getCreated(),
207                         configurationInfo.getOwnedConfigurations(),
208                         configurationInfo.getChildConfigurations(),
209                         configurationInfo.getInPlaceLocation(),
210                         State.STOPPED);
211             }
212             iterator.set(configurationInfo);
213         }
214         return list;
215     }
216
217     public boolean isConfiguration(Artifact artifact) {
218         if(!artifact.isResolved()) {
219             throw new IllegalArgumentException JavaDoc("Artifact "+artifact+" is not fully resolved");
220         }
221         synchronized (this) {
222             // if it is loaded, it is definitely a configuration
223
if (configurations.containsKey(artifact)) {
224                 return true;
225             }
226         }
227
228         // see if any stores think it is a configuration
229
List JavaDoc storeSnapshot = getStoreList();
230         for (int i = 0; i < storeSnapshot.size(); i++) {
231             ConfigurationStore store = (ConfigurationStore) storeSnapshot.get(i);
232             if (store.containsConfiguration(artifact)) {
233                 return true;
234             }
235         }
236         return false;
237     }
238
239     public synchronized Configuration getConfiguration(Artifact configurationId) {
240         if(!configurationId.isResolved()) {
241             throw new IllegalArgumentException JavaDoc("Artifact "+configurationId+" is not fully resolved");
242         }
243         if(reloadingConfiguration != null && reloadingConfiguration.getId().equals(configurationId)) {
244             return reloadingConfiguration;
245         }
246         return (Configuration) configurations.get(configurationId);
247     }
248
249     public synchronized LifecycleResults loadConfiguration(Artifact configurationId) throws NoSuchConfigException, LifecycleException {
250         return loadConfiguration(configurationId, NullLifecycleMonitor.INSTANCE);
251     }
252
253     public synchronized LifecycleResults loadConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
254         if(!configurationId.isResolved()) {
255             throw new IllegalArgumentException JavaDoc("Artifact "+configurationId+" is not fully resolved");
256         }
257         if (isLoaded(configurationId)) {
258             // already loaded, so just mark the configuration as user loaded
259
load(configurationId);
260
261             monitor.finished();
262             return new LifecycleResults();
263         }
264
265         // load the ConfigurationData for the new configuration
266
ConfigurationData configurationData = null;
267         try {
268             configurationData = loadConfigurationData(configurationId, monitor);
269         } catch (Exception JavaDoc e) {
270             monitor.finished();
271             throw new LifecycleException("load", configurationId, e);
272         }
273
274         // load the configuration
275
LifecycleResults results = loadConfiguration(configurationData, monitor);
276
277         return results;
278     }
279
280     public synchronized LifecycleResults loadConfiguration(ConfigurationData configurationData) throws NoSuchConfigException, LifecycleException {
281         return loadConfiguration(configurationData, NullLifecycleMonitor.INSTANCE);
282     }
283
284     public synchronized LifecycleResults loadConfiguration(ConfigurationData configurationData, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
285         Artifact id = configurationData.getId();
286         LifecycleResults results = new LifecycleResults();
287         if (!isLoaded(id)) {
288             // recursively load configurations from the new child to the parents
289
LinkedHashMap JavaDoc configurationsToLoad = new LinkedHashMap JavaDoc();
290             try {
291                 loadDepthFirst(configurationData, configurationsToLoad, monitor);
292             } catch (Exception JavaDoc e) {
293                 monitor.finished();
294                 throw new LifecycleException("load", id, e);
295             }
296
297             // load and start the unloaded the gbean for each configuration (depth first)
298
Map JavaDoc actuallyLoaded = new LinkedHashMap JavaDoc(configurationsToLoad.size());
299             Artifact configurationId = null;
300             try {
301                 for (Iterator JavaDoc iterator = configurationsToLoad.entrySet().iterator(); iterator.hasNext();) {
302                     Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
303                     configurationId = (Artifact) entry.getKey();
304                     UnloadedConfiguration unloadedConfiguration = (UnloadedConfiguration) entry.getValue();
305
306                     monitor.loading(configurationId);
307                     Configuration configuration = load(unloadedConfiguration.getConfigurationData(), unloadedConfiguration.getResolvedParentIds(), actuallyLoaded);
308                     monitor.succeeded(configurationId);
309
310                     actuallyLoaded.put(configurationId, configuration);
311                 }
312             } catch (Exception JavaDoc e) {
313                 monitor.failed(configurationId, e);
314
315                 // there was a problem, so we need to unload all configurations that were actually loaded
316
for (Iterator JavaDoc iterator = actuallyLoaded.values().iterator(); iterator.hasNext();) {
317                     Configuration configuration = (Configuration) iterator.next();
318                     unload(configuration);
319                 }
320
321                 monitor.finished();
322                 throw new LifecycleException("load", id, e);
323             }
324
325             // update the status of the loaded configurations
326
addNewConfigurationsToModel(actuallyLoaded);
327             results.setLoaded(actuallyLoaded.keySet());
328         }
329         load(id);
330         monitor.finished();
331         return results;
332     }
333
334     protected void load(Artifact configurationId) throws NoSuchConfigException {
335         configurationModel.load(configurationId);
336     }
337
338     protected Configuration load(ConfigurationData configurationData, LinkedHashSet JavaDoc resolvedParentIds, Map JavaDoc loadedConfigurations) throws InvalidConfigException {
339         Artifact configurationId = configurationData.getId();
340         try {
341             Collection JavaDoc parents = findParentConfigurations(resolvedParentIds, loadedConfigurations);
342
343             Configuration configuration = new Configuration(parents, configurationData, new ConfigurationResolver(configurationData, repositories, artifactResolver), null);
344             configuration.doStart();
345             return configuration;
346         } catch (Exception JavaDoc e) {
347             throw new InvalidConfigException("Error starting configuration gbean " + configurationId, e);
348         }
349     }
350
351     private Collection JavaDoc findParentConfigurations(LinkedHashSet JavaDoc resolvedParentIds, Map JavaDoc loadedConfigurations) throws InvalidConfigException {
352         LinkedHashMap JavaDoc parents = new LinkedHashMap JavaDoc();
353         for (Iterator JavaDoc iterator = resolvedParentIds.iterator(); iterator.hasNext();) {
354             Artifact resolvedArtifact = (Artifact) iterator.next();
355
356             Configuration parent = null;
357             if (loadedConfigurations.containsKey(resolvedArtifact)) {
358                 parent = (Configuration) loadedConfigurations.get(resolvedArtifact);
359             } else if (isLoaded(resolvedArtifact)) {
360                 parent = getConfiguration(resolvedArtifact);
361             } else {
362                 throw new InvalidConfigException("Cound not find parent configuration: " + resolvedArtifact);
363             }
364
365             parents.put(resolvedArtifact, parent);
366         }
367         return parents.values();
368     }
369
370     private void addNewConfigurationsToModel(Map JavaDoc loadedConfigurations) throws NoSuchConfigException {
371         for (Iterator JavaDoc iterator = loadedConfigurations.values().iterator(); iterator.hasNext();) {
372             Configuration configuration = (Configuration) iterator.next();
373             addNewConfigurationToModel(configuration);
374         }
375     }
376
377     protected void addNewConfigurationToModel(Configuration configuration) throws NoSuchConfigException {
378         configurationModel.addConfiguation(configuration.getId(),
379                 getConfigurationIds(getLoadParents(configuration)),
380                 getConfigurationIds(getStartParents(configuration)));
381         configurations.put(configuration.getId(), configuration);
382     }
383
384     protected LinkedHashSet JavaDoc getLoadParents(Configuration configuration) {
385         LinkedHashSet JavaDoc loadParent = new LinkedHashSet JavaDoc(configuration.getClassParents());
386         for (Iterator JavaDoc iterator = configuration.getChildren().iterator(); iterator.hasNext();) {
387             Configuration childConfiguration = (Configuration) iterator.next();
388             LinkedHashSet JavaDoc childLoadParent = getLoadParents(childConfiguration);
389
390             // remove this configuration from the parent Ids since it will cause an infinite loop
391
childLoadParent.remove(configuration);
392
393             loadParent.addAll(childLoadParent);
394         }
395         return loadParent;
396     }
397
398     protected LinkedHashSet JavaDoc getStartParents(Configuration configuration) {
399         LinkedHashSet JavaDoc startParent = new LinkedHashSet JavaDoc(configuration.getServiceParents());
400         for (Iterator JavaDoc iterator = configuration.getChildren().iterator(); iterator.hasNext();) {
401             Configuration childConfiguration = (Configuration) iterator.next();
402             LinkedHashSet JavaDoc childStartParent = getStartParents(childConfiguration);
403
404             // remove this configuration from the parent Ids since it will cause an infinite loop
405
childStartParent.remove(configuration);
406
407             startParent.addAll(childStartParent);
408         }
409         return startParent;
410     }
411
412     private static LinkedHashSet JavaDoc getConfigurationIds(Collection JavaDoc configurations) {
413         LinkedHashSet JavaDoc configurationIds = new LinkedHashSet JavaDoc(configurations.size());
414         for (Iterator JavaDoc iterator = configurations.iterator(); iterator.hasNext();) {
415             Configuration configuration = (Configuration) iterator.next();
416             configurationIds.add(configuration.getId());
417         }
418         return configurationIds;
419     }
420
421     private synchronized void loadDepthFirst(ConfigurationData configurationData, LinkedHashMap JavaDoc configurationsToLoad, LifecycleMonitor monitor) throws NoSuchConfigException, IOException JavaDoc, InvalidConfigException, MissingDependencyException {
422         // if this parent hasn't already been processed, iterate into the parent
423
Artifact configurationId = configurationData.getId();
424         if (!configurationsToLoad.containsKey(configurationId)) {
425             LinkedHashSet JavaDoc resolvedParentIds = resolveParentIds(configurationData);
426
427             for (Iterator JavaDoc iterator = resolvedParentIds.iterator(); iterator.hasNext();) {
428                 Artifact parentId = (Artifact) iterator.next();
429                 // if this parent id hasn't already been loaded and is actually a configuration
430
if (!isLoaded(parentId) && isConfiguration(parentId)) {
431                     ConfigurationData parentConfigurationData = loadConfigurationData(parentId, monitor);
432                     loadDepthFirst(parentConfigurationData, configurationsToLoad, monitor);
433                 }
434             }
435
436             // depth first - all unloaded parents have been added, now add this configuration
437
configurationsToLoad.put(configurationId, new UnloadedConfiguration(configurationData, resolvedParentIds));
438         }
439     }
440
441     private ConfigurationData loadConfigurationData(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, IOException JavaDoc, InvalidConfigException {
442         List JavaDoc storeSnapshot = getStoreList();
443
444         monitor.addConfiguration(configurationId);
445         monitor.reading(configurationId);
446         for (int i = 0; i < storeSnapshot.size(); i++) {
447             ConfigurationStore store = (ConfigurationStore) storeSnapshot.get(i);
448             if (store.containsConfiguration(configurationId)) {
449                 ConfigurationData configurationData = store.loadConfiguration(configurationId);
450                 monitor.succeeded(configurationId);
451                 return configurationData;
452             }
453         }
454         NoSuchConfigException exception = new NoSuchConfigException(configurationId);
455         monitor.failed(configurationId, exception);
456         throw exception;
457     }
458
459     private LinkedHashSet JavaDoc resolveParentIds(ConfigurationData configurationData) throws MissingDependencyException, InvalidConfigException {
460         Environment environment = configurationData.getEnvironment();
461
462         LinkedHashSet JavaDoc parentIds = new LinkedHashSet JavaDoc();
463         List JavaDoc dependencies = new ArrayList JavaDoc(environment.getDependencies());
464         for (ListIterator JavaDoc iterator = dependencies.listIterator(); iterator.hasNext();) {
465             Dependency dependency = (Dependency) iterator.next();
466             Artifact resolvedArtifact = artifactResolver.resolveInClassLoader(dependency.getArtifact());
467             if (isConfiguration(resolvedArtifact)) {
468                 parentIds.add(resolvedArtifact);
469
470                 // update the dependency list to contain the resolved artifact
471
dependency = new Dependency(resolvedArtifact, dependency.getImportType());
472                 iterator.set(dependency);
473             } else if (dependency.getImportType() == ImportType.SERVICES) {
474                 // Service depdendencies require that the depdencency be a configuration
475
throw new InvalidConfigException("Dependency does not have services: " + resolvedArtifact);
476             }
477         }
478
479         for (Iterator JavaDoc iterator = configurationData.getChildConfigurations().values().iterator(); iterator.hasNext();) {
480             ConfigurationData childConfigurationData = (ConfigurationData) iterator.next();
481             LinkedHashSet JavaDoc childParentIds = resolveParentIds(childConfigurationData);
482             // remove this configuration's id from the parent Ids since it will cause an infinite loop
483
childParentIds.remove(configurationData.getId());
484             parentIds.addAll(childParentIds);
485         }
486         return parentIds;
487     }
488
489     private static class UnloadedConfiguration {
490         private final ConfigurationData configurationData;
491         private final LinkedHashSet JavaDoc resolvedParentIds;
492
493         public UnloadedConfiguration(ConfigurationData configurationData, LinkedHashSet JavaDoc resolvedParentIds) {
494             this.configurationData = configurationData;
495             this.resolvedParentIds = resolvedParentIds;
496         }
497
498         public ConfigurationData getConfigurationData() {
499             return configurationData;
500         }
501
502         public LinkedHashSet JavaDoc getResolvedParentIds() {
503             return resolvedParentIds;
504         }
505     }
506
507     public synchronized LifecycleResults startConfiguration(Artifact id) throws NoSuchConfigException, LifecycleException {
508         return startConfiguration(id, NullLifecycleMonitor.INSTANCE);
509     }
510
511     public synchronized LifecycleResults startConfiguration(Artifact id, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
512         if(!id.isResolved()) {
513             throw new IllegalArgumentException JavaDoc("Artifact "+id+" is not fully resolved");
514         }
515         LinkedHashSet JavaDoc unstartedConfigurations = configurationModel.start(id);
516
517         addConfigurationsToMonitor(monitor, unstartedConfigurations);
518
519         LifecycleResults results = new LifecycleResults();
520         Artifact configurationId = null;
521         try {
522             for (Iterator JavaDoc iterator = unstartedConfigurations.iterator(); iterator.hasNext();) {
523                 configurationId = (Artifact) iterator.next();
524                 Configuration configuration = getConfiguration(configurationId);
525
526                 monitor.starting(configurationId);
527                 start(configuration);
528                 monitor.succeeded(configurationId);
529
530                 results.addStarted(configurationId);
531             }
532         } catch (Exception JavaDoc e) {
533             monitor.failed(configurationId, e);
534             configurationModel.stop(id);
535
536             for (Iterator JavaDoc iterator = results.getStarted().iterator(); iterator.hasNext();) {
537                 configurationId = (Artifact) iterator.next();
538                 Configuration configuration = getConfiguration(configurationId);
539                 monitor.stopping(configurationId);
540                 stop(configuration);
541                 monitor.succeeded(configurationId);
542             }
543             monitor.finished();
544             throw new LifecycleException("start", id, e);
545         }
546         monitor.finished();
547         return results;
548     }
549
550     protected void start(Configuration configuration) throws Exception JavaDoc {
551         throw new UnsupportedOperationException JavaDoc();
552     }
553
554     public synchronized LifecycleResults stopConfiguration(Artifact id) throws NoSuchConfigException {
555         return stopConfiguration(id, NullLifecycleMonitor.INSTANCE);
556     }
557
558     public synchronized LifecycleResults stopConfiguration(Artifact id, LifecycleMonitor monitor) throws NoSuchConfigException {
559         if(!id.isResolved()) {
560             throw new IllegalArgumentException JavaDoc("Artifact "+id+" is not fully resolved");
561         }
562         LinkedHashSet JavaDoc stopList = configurationModel.stop(id);
563
564         addConfigurationsToMonitor(monitor, stopList);
565
566         LifecycleResults results = new LifecycleResults();
567         for (Iterator JavaDoc iterator = stopList.iterator(); iterator.hasNext();) {
568             Artifact configurationId = (Artifact) iterator.next();
569             Configuration configuration = getConfiguration(configurationId);
570
571             monitor.stopping(configurationId);
572             stop(configuration);
573             monitor.succeeded(configurationId);
574
575             results.addStopped(configurationId);
576         }
577
578         monitor.finished();
579         return results;
580     }
581
582     protected void stop(Configuration configuration) {
583         // Don't throw an exception because we call this from unload to be sure that all
584
// unloaded configurations are stopped first
585
}
586
587     public synchronized LifecycleResults restartConfiguration(Artifact id) throws NoSuchConfigException, LifecycleException {
588         return restartConfiguration(id, NullLifecycleMonitor.INSTANCE);
589     }
590
591     public synchronized LifecycleResults restartConfiguration(Artifact id, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
592         if(!id.isResolved()) {
593             throw new IllegalArgumentException JavaDoc("Artifact "+id+" is not fully resolved");
594         }
595         // get a sorted list of configurations to restart
596
LinkedHashSet JavaDoc restartList = configurationModel.restart(id);
597
598         addConfigurationsToMonitor(monitor, restartList);
599
600         // stop the configuations
601
LifecycleResults results = new LifecycleResults();
602         for (Iterator JavaDoc iterator = restartList.iterator(); iterator.hasNext();) {
603             Artifact configurationId = (Artifact) iterator.next();
604             Configuration configuration = getConfiguration(configurationId);
605             monitor.stopping(configurationId);
606             stop(configuration);
607             monitor.succeeded(configurationId);
608             results.addStopped(configurationId);
609         }
610
611         // reverse the list
612
restartList = reverse(restartList);
613
614         // restart the configurations
615
Set JavaDoc skip = new HashSet JavaDoc();
616         for (Iterator JavaDoc iterator = restartList.iterator(); iterator.hasNext();) {
617             Artifact configurationId = (Artifact) iterator.next();
618
619          &nbs