View Javadoc

1   /**
2    *
3    * Copyright 2003-2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  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: 2006-05-08 16:44:03 -0700 (Mon, 08 May 2006) $
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                      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                  }
89              } finally {
90                  ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
91              }
92              addWebURLs(kernel);
93              complete("Completed");
94          } catch (Exception e) {
95              e.printStackTrace();
96              doFail(e);
97          }
98      }
99  }