001 /**
002 *
003 * Copyright 2003-2004 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
018 package org.apache.geronimo.deployment.plugin.local;
019
020 import java.util.List;
021 import javax.enterprise.deploy.shared.CommandType;
022 import javax.enterprise.deploy.shared.ModuleType;
023 import javax.enterprise.deploy.spi.TargetModuleID;
024
025 import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
026 import org.apache.geronimo.kernel.Kernel;
027 import org.apache.geronimo.kernel.config.Configuration;
028 import org.apache.geronimo.kernel.config.ConfigurationManager;
029 import org.apache.geronimo.kernel.config.ConfigurationUtil;
030 import org.apache.geronimo.kernel.repository.Artifact;
031 import org.apache.geronimo.gbean.AbstractName;
032
033 /**
034 * @version $Rev:392614 $ $Date: 2006-05-08 16:44:03 -0700 (Mon, 08 May 2006) $
035 */
036 public class StartCommand extends CommandSupport {
037 private final Kernel kernel;
038 private final TargetModuleID[] modules;
039
040 public StartCommand(Kernel kernel, TargetModuleID modules[]) {
041 super(CommandType.START);
042 this.kernel = kernel;
043 this.modules = modules;
044 }
045
046 public void run() {
047 try {
048 ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
049 try {
050 for (int i = 0; i < modules.length; i++) {
051 TargetModuleID module = modules[i];
052
053 // Check to see whether the module is already started
054 Artifact moduleID = Artifact.create(module.getModuleID());
055 if (configurationManager.isRunning(moduleID)) {
056 updateStatus("Module " + moduleID + " is already running");
057 Thread.sleep(100);
058 continue;
059 }
060
061 // Load
062 if(!configurationManager.isLoaded(moduleID)) {
063 configurationManager.loadConfiguration(moduleID);
064 }
065
066 // Start
067 configurationManager.startConfiguration(moduleID);
068
069 // Determine the child modules of the configuration
070 //TODO might be a hack
071 List kids = loadChildren(kernel, moduleID.toString());
072
073 // Build a response obect containg the started configuration and a list of it's contained modules
074 TargetModuleIDImpl id = new TargetModuleIDImpl(modules[i].getTarget(), module.getModuleID(),
075 (String[]) kids.toArray(new String[kids.size()]));
076 if (isWebApp(kernel, moduleID.toString())) {
077 id.setType(ModuleType.WAR);
078 }
079 if (id.getChildTargetModuleID() != null) {
080 for (int k = 0; k < id.getChildTargetModuleID().length; k++) {
081 TargetModuleIDImpl child = (TargetModuleIDImpl) id.getChildTargetModuleID()[k];
082 if (isWebApp(kernel, child.getModuleID())) {
083 child.setType(ModuleType.WAR);
084 }
085 }
086 }
087 addModule(id);
088 }
089 } finally {
090 ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
091 }
092 addWebURLs(kernel);
093 complete("Completed");
094 } catch (Exception e) {
095 e.printStackTrace();
096 doFail(e);
097 }
098 }
099 }