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 18 package org.apache.geronimo.deployment.plugin.local; 19 20 import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl; 21 import org.apache.geronimo.kernel.Kernel; 22 import org.apache.geronimo.kernel.config.ConfigurationManager; 23 import org.apache.geronimo.kernel.config.ConfigurationUtil; 24 import org.apache.geronimo.kernel.repository.Artifact; 25 26 import java.util.List; 27 import javax.enterprise.deploy.shared.CommandType; 28 import javax.enterprise.deploy.shared.ModuleType; 29 import javax.enterprise.deploy.spi.TargetModuleID; 30 31 /** 32 * @version $Rev: 689884 $ $Date: 2008-08-28 09:42:47 -0700 (Thu, 28 Aug 2008) $ 33 */ 34 public class StopCommand extends CommandSupport { 35 private final Kernel kernel; 36 private final TargetModuleID[] modules; 37 38 public StopCommand(Kernel kernel, TargetModuleID modules[]) { 39 super(CommandType.STOP); 40 this.kernel = kernel; 41 this.modules = modules; 42 } 43 44 public void run() { 45 try { 46 ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel); 47 int alreadyStopped = 0; 48 49 try { 50 for (int i = 0; i < modules.length; i++) { 51 TargetModuleID module = modules[i]; 52 Artifact moduleID = Artifact.create(module.getModuleID()); 53 org.apache.geronimo.kernel.config.LifecycleResults lcresult = null; 54 55 if (configurationManager.isRunning(moduleID)) { 56 lcresult = configurationManager.stopConfiguration(moduleID); 57 addModule(module); 58 } else { 59 updateStatus("Module " + moduleID + " is already stopped"); 60 alreadyStopped++; 61 } 62 63 if (configurationManager.isLoaded(moduleID)) { 64 configurationManager.unloadConfiguration(moduleID); 65 } 66 67 if (lcresult != null) { 68 java.util.Iterator iterator = lcresult.getStopped().iterator(); 69 while (iterator.hasNext()) { 70 Artifact config = (Artifact)iterator.next(); 71 if (!config.toString().equals(module.getModuleID())) { 72 //TODO might be a hack 73 List kidsChild = loadChildren(kernel, config.toString()); 74 //this.updateStatus("printing kidsChild="+kidsChild); 75 //this.updateStatus("printing config="+config.toString()); 76 // Build a response obect containg the started configuration and a list of it's contained modules 77 TargetModuleIDImpl idChild = new TargetModuleIDImpl(null, config.toString(), 78 (String[]) kidsChild.toArray(new String[kidsChild.size()])); 79 if (isWebApp(kernel, config.toString())) { 80 idChild.setType(ModuleType.WAR); 81 } 82 if (idChild.getChildTargetModuleID() != null) { 83 for (int k = 0; k < idChild.getChildTargetModuleID().length; k++) { 84 TargetModuleIDImpl child = (TargetModuleIDImpl) idChild.getChildTargetModuleID()[k]; 85 if (isWebApp(kernel, child.getModuleID())) { 86 child.setType(ModuleType.WAR); 87 } 88 } 89 } 90 addModule(idChild); 91 } 92 } 93 } 94 } 95 } finally { 96 ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager); 97 } 98 if ((getModuleCount() + alreadyStopped) < modules.length) { 99 fail("Some modules could not be stopped"); 100 } else { 101 complete("Completed"); 102 } 103 } catch (Throwable e) { 104 doFail(e); 105 } 106 } 107 }