01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.jk.apr;
19:
20: import java.lang.reflect.Method;
21:
22: // Hack for Catalina 4.1 who hungs the calling thread.
23: // Also avoids delays in apache initialization ( tomcat can take a while )
24:
25: /**
26: * Start some tomcat.
27: *
28: */
29: public class TomcatStarter implements Runnable {
30: Class c;
31: String args[];
32: AprImpl apr = new AprImpl();
33:
34: public static String mainClasses[] = {
35: "org.apache.tomcat.startup.Main",
36: "org.apache.catalina.startup.BootstrapService",
37: "org.apache.catalina.startup.Bootstrap" };
38:
39: // If someone has time - we can also guess the classpath and do other
40: // fancy guessings.
41:
42: public static void main(String args[]) {
43: System.err.println("TomcatStarter: main()");
44: int nClasses = 0;
45:
46: try {
47: AprImpl.jniMode();
48: // Find the class
49: Class c = null;
50: for (int i = 0; i < mainClasses.length; i++) {
51: try {
52: System.err.println("Try " + mainClasses[i]);
53: c = Class.forName(mainClasses[i]);
54: } catch (ClassNotFoundException ex) {
55: continue;
56: }
57: if (c != null) {
58: ++nClasses;
59: Thread startThread = new Thread(new TomcatStarter(
60: c, args));
61: c = null;
62: startThread.start();
63: break;
64: }
65: }
66: if (nClasses == 0)
67: System.err.println("No class found ");
68:
69: } catch (Throwable t) {
70: t.printStackTrace(System.err);
71: }
72: }
73:
74: public TomcatStarter(Class c, String args[]) {
75: this .c = c;
76: this .args = args;
77: }
78:
79: public void run() {
80: System.err.println("Starting " + c.getName());
81: try {
82: Class argClass = args.getClass();
83: Method m = c.getMethod("main", new Class[] { argClass });
84: m.invoke(c, new Object[] { args });
85: System.out.println("TomcatStarter: Done");
86: if (apr.isLoaded())
87: apr.jkSetAttribute(0, 0, "channel:jni", "done");
88: if (args[0].equals("stop")) {
89: Thread.sleep(5000);
90: Runtime.getRuntime().exit(0);
91: }
92: } catch (Throwable t) {
93: t.printStackTrace(System.err);
94: }
95: }
96: }
|