01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.jk.apr;
18:
19: import java.lang.reflect.Method;
20:
21: // Hack for Catalina 4.1 who hungs the calling thread.
22: // Also avoids delays in apache initialization ( tomcat can take a while )
23:
24: /**
25: * Start some tomcat.
26: *
27: */
28: public class TomcatStarter implements Runnable {
29: Class c;
30: String args[];
31: AprImpl apr = new AprImpl();
32:
33: public static String mainClasses[] = {
34: "org.apache.tomcat.startup.Main",
35: "org.apache.catalina.startup.BootstrapService",
36: "org.apache.catalina.startup.Bootstrap" };
37:
38: // If someone has time - we can also guess the classpath and do other
39: // fancy guessings.
40:
41: public static void main(String args[]) {
42: System.err.println("TomcatStarter: main()");
43: int nClasses = 0;
44:
45: try {
46: AprImpl.jniMode();
47: // Find the class
48: Class c = null;
49: for (int i = 0; i < mainClasses.length; i++) {
50: try {
51: System.err.println("Try " + mainClasses[i]);
52: c = Class.forName(mainClasses[i]);
53: } catch (ClassNotFoundException ex) {
54: continue;
55: }
56: if (c != null) {
57: ++nClasses;
58: Thread startThread = new Thread(new TomcatStarter(
59: c, args));
60: c = null;
61: startThread.start();
62: break;
63: }
64: }
65: if (nClasses == 0)
66: System.err.println("No class found ");
67:
68: } catch (Throwable t) {
69: t.printStackTrace(System.err);
70: }
71: }
72:
73: public TomcatStarter(Class c, String args[]) {
74: this .c = c;
75: this .args = args;
76: }
77:
78: public void run() {
79: System.err.println("Starting " + c.getName());
80: try {
81: Class argClass = args.getClass();
82: Method m = c.getMethod("main", new Class[] { argClass });
83: m.invoke(c, new Object[] { args });
84: System.out.println("TomcatStarter: Done");
85: if (apr.isLoaded())
86: apr.jkSetAttribute(0, 0, "channel:jni", "done");
87: if (args[0].equals("stop")) {
88: Thread.sleep(5000);
89: Runtime.getRuntime().exit(0);
90: }
91: } catch (Throwable t) {
92: t.printStackTrace(System.err);
93: }
94: }
95: }
|