001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. 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: */package org.apache.geronimo.deployment.plugin.local;
017:
018: import java.util.List;
019: import javax.enterprise.deploy.shared.CommandType;
020: import javax.enterprise.deploy.shared.ModuleType;
021: import javax.enterprise.deploy.spi.TargetModuleID;
022:
023: import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
024: import org.apache.geronimo.kernel.Kernel;
025: import org.apache.geronimo.kernel.config.Configuration;
026: import org.apache.geronimo.kernel.config.ConfigurationManager;
027: import org.apache.geronimo.kernel.config.ConfigurationUtil;
028: import org.apache.geronimo.kernel.repository.Artifact;
029: import org.apache.geronimo.gbean.AbstractName;
030:
031: /**
032: * @version $Rev:392614 $ $Date: 2007-05-11 09:25:51 -0700 (Fri, 11 May 2007) $
033: */
034: public class StartCommand extends CommandSupport {
035: private final Kernel kernel;
036: private final TargetModuleID[] modules;
037:
038: public StartCommand(Kernel kernel, TargetModuleID modules[]) {
039: super (CommandType.START);
040: this .kernel = kernel;
041: this .modules = modules;
042: }
043:
044: public void run() {
045: try {
046: ConfigurationManager configurationManager = ConfigurationUtil
047: .getConfigurationManager(kernel);
048: try {
049: for (int i = 0; i < modules.length; i++) {
050: TargetModuleID module = modules[i];
051:
052: // Check to see whether the module is already started
053: Artifact moduleID = Artifact.create(module
054: .getModuleID());
055: if (configurationManager.isRunning(moduleID)) {
056: updateStatus("Module " + moduleID
057: + " is already running");
058: Thread.sleep(100);
059: continue;
060: }
061:
062: // Load
063: if (!configurationManager.isLoaded(moduleID)) {
064: configurationManager
065: .loadConfiguration(moduleID);
066: }
067:
068: // Start
069: org.apache.geronimo.kernel.config.LifecycleResults lcresult = configurationManager
070: .startConfiguration(moduleID);
071:
072: // Determine the child modules of the configuration
073: //TODO might be a hack
074: List kids = loadChildren(kernel, moduleID
075: .toString());
076:
077: // Build a response obect containg the started configuration and a list of it's contained modules
078: TargetModuleIDImpl id = new TargetModuleIDImpl(
079: modules[i].getTarget(), module
080: .getModuleID(), (String[]) kids
081: .toArray(new String[kids.size()]));
082: if (isWebApp(kernel, moduleID.toString())) {
083: id.setType(ModuleType.WAR);
084: }
085: if (id.getChildTargetModuleID() != null) {
086: for (int k = 0; k < id.getChildTargetModuleID().length; k++) {
087: TargetModuleIDImpl child = (TargetModuleIDImpl) id
088: .getChildTargetModuleID()[k];
089: if (isWebApp(kernel, child.getModuleID())) {
090: child.setType(ModuleType.WAR);
091: }
092: }
093: }
094: addModule(id);
095: java.util.Iterator iterator = lcresult.getStarted()
096: .iterator();
097: while (iterator.hasNext()) {
098: Artifact config = (Artifact) iterator.next();
099: if (!config.toString().equals(id.getModuleID())) {
100: //TODO might be a hack
101: List kidsChild = loadChildren(kernel,
102: config.toString());
103:
104: // Build a response obect containg the started configuration and a list of it's contained modules
105: TargetModuleIDImpl idChild = new TargetModuleIDImpl(
106: null,
107: config.toString(),
108: (String[]) kidsChild
109: .toArray(new String[kidsChild
110: .size()]));
111: if (isWebApp(kernel, config.toString())) {
112: idChild.setType(ModuleType.WAR);
113: }
114: if (idChild.getChildTargetModuleID() != null) {
115: for (int k = 0; k < idChild
116: .getChildTargetModuleID().length; k++) {
117: TargetModuleIDImpl child = (TargetModuleIDImpl) idChild
118: .getChildTargetModuleID()[k];
119: if (isWebApp(kernel, child
120: .getModuleID())) {
121: child.setType(ModuleType.WAR);
122: }
123: }
124: }
125: addModule(idChild);
126: }
127: }
128: }
129: } finally {
130: ConfigurationUtil.releaseConfigurationManager(kernel,
131: configurationManager);
132: }
133: addWebURLs(kernel);
134: complete("Completed");
135: } catch (Exception e) {
136: e.printStackTrace();
137: doFail(e);
138: }
139: }
140: }
|