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 java.util.List; 21 import javax.enterprise.deploy.shared.CommandType; 22 import javax.enterprise.deploy.shared.ModuleType; 23 import javax.enterprise.deploy.spi.TargetModuleID; 24 25 import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl; 26 import org.apache.geronimo.kernel.Kernel; 27 import org.apache.geronimo.kernel.config.Configuration; 28 import org.apache.geronimo.kernel.config.ConfigurationManager; 29 import org.apache.geronimo.kernel.config.ConfigurationUtil; 30 import org.apache.geronimo.kernel.repository.Artifact; 31 import org.apache.geronimo.gbean.AbstractName; 32 33 /** 34 * @version $Rev:392614 $ $Date: 2008-08-28 09:42:47 -0700 (Thu, 28 Aug 2008) $ 35 */ 36 public class StartCommand extends CommandSupport { 37 private final Kernel kernel; 38 private final TargetModuleID[] modules; 39 40 public StartCommand(Kernel kernel, TargetModuleID modules[]) { 41 super(CommandType.START); 42 this.kernel = kernel; 43 this.modules = modules; 44 } 45 46 public void run() { 47 try { 48 ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel); 49 try { 50 for (int i = 0; i < modules.length; i++) { 51 TargetModuleID module = modules[i]; 52 53 // Check to see whether the module is already started 54 Artifact moduleID = Artifact.create(module.getModuleID()); 55 if (configurationManager.isRunning(moduleID)) { 56 updateStatus("Module " + moduleID + " is already running"); 57 Thread.sleep(100); 58 continue; 59 } 60 61 // Load 62 if(!configurationManager.isLoaded(moduleID)) { 63 configurationManager.loadConfiguration(moduleID); 64 } 65 66 // Start 67 org.apache.geronimo.kernel.config.LifecycleResults lcresult = configurationManager.startConfiguration(moduleID); 68 69 // Determine the child modules of the configuration 70 //TODO might be a hack 71 List kids = loadChildren(kernel, moduleID.toString()); 72 73 // Build a response obect containg the started configuration and a list of it's contained modules 74 TargetModuleIDImpl id = new TargetModuleIDImpl(modules[i].getTarget(), module.getModuleID(), 75 (String[]) kids.toArray(new String[kids.size()])); 76 if (isWebApp(kernel, moduleID.toString())) { 77 id.setType(ModuleType.WAR); 78 } 79 if (id.getChildTargetModuleID() != null) { 80 for (int k = 0; k < id.getChildTargetModuleID().length; k++) { 81 TargetModuleIDImpl child = (TargetModuleIDImpl) id.getChildTargetModuleID()[k]; 82 if (isWebApp(kernel, child.getModuleID())) { 83 child.setType(ModuleType.WAR); 84 } 85 } 86 } 87 addModule(id); 88 java.util.Iterator iterator = lcresult.getStarted().iterator(); 89 while (iterator.hasNext()) { 90 Artifact config = (Artifact)iterator.next(); 91 if (!config.toString().equals(id.getModuleID())) { 92 //TODO might be a hack 93 List kidsChild = loadChildren(kernel, config.toString()); 94 95 // Build a response obect containg the started configuration and a list of it's contained modules 96 TargetModuleIDImpl idChild = new TargetModuleIDImpl(null, config.toString(), 97 (String[]) kidsChild.toArray(new String[kidsChild.size()])); 98 if (isWebApp(kernel, config.toString())) { 99 idChild.setType(ModuleType.WAR); 100 } 101 if (idChild.getChildTargetModuleID() != null) { 102 for (int k = 0; k < idChild.getChildTargetModuleID().length; k++) { 103 TargetModuleIDImpl child = (TargetModuleIDImpl) idChild.getChildTargetModuleID()[k]; 104 if (isWebApp(kernel, child.getModuleID())) { 105 child.setType(ModuleType.WAR); 106 } 107 } 108 } 109 addModule(idChild); 110 } 111 } 112 } 113 } finally { 114 ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager); 115 } 116 addWebURLs(kernel); 117 complete("Completed"); 118 } catch (Throwable e) { 119 doFail(e); 120 } 121 } 122 }