/**
*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.deployment.plugin.local;
import java.net.URI;
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.util.Iterator;
import javax.enterprise.deploy.shared.CommandType;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.TargetModuleID;
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.management.State;
import org.apache.geronimo.kernel.config.ConfigurationManager;
import org.apache.geronimo.kernel.config.ConfigurationUtil;
import org.apache.geronimo.kernel.config.Configuration;
import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
/**
*
*
* @version $Rev: 263877 $ $Date: 2005-08-28 08:05:10 -0600 (Sun, 28 Aug 2005) $
*/
public class StartCommand extends CommandSupport {
private final Kernel kernel;
private final TargetModuleID[] modules;
public StartCommand(Kernel kernel, TargetModuleID modules[]) {
super(CommandType.START);
this.kernel = kernel;
this.modules = modules;
}
public void run() {
try {
ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
try {
for (int i = 0; i < modules.length; i++) {
TargetModuleID module = modules[i];
// Check to see whether the module is already started
URI moduleID = URI.create(module.getModuleID());
try {
if(kernel.getGBeanState(Configuration.getConfigurationObjectName(moduleID)) == State.RUNNING_INDEX) {
updateStatus("Module "+moduleID+" is already running");
Thread.sleep(100);
continue;
}
} catch (GBeanNotFoundException e) {
// That means that the configuration may have been distributed but has not yet been loaded.
// That's fine, we'll load it next.
}
// Load and start the module
List list = configurationManager.loadRecursive(moduleID);
for (int j = 0; j < list.size(); j++) {
ObjectName name = (ObjectName) list.get(j);
kernel.startRecursiveGBean(name);
String configName = ObjectName.unquote(name.getKeyProperty("name"));
List kids = loadChildren(kernel, configName);
TargetModuleIDImpl id = new TargetModuleIDImpl(modules[i].getTarget(), configName,
(String[]) kids.toArray(new String[kids.size()]));
if(isWebApp(kernel, configName)) {
id.setType(ModuleType.WAR);
}
if(id.getChildTargetModuleID() != null) {
for (int k = 0; k < id.getChildTargetModuleID().length; k++) {
TargetModuleIDImpl child = (TargetModuleIDImpl) id.getChildTargetModuleID()[k];
if(isWebApp(kernel, child.getModuleID())) {
child.setType(ModuleType.WAR);
}
}
}
addModule(id);
}
}
} finally {
ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
}
addWebURLs(kernel);
complete("Completed");
} catch (Exception e) {
e.printStackTrace();
doFail(e);
}
}
}