e.g. Calendar Search Help
You must enter a value before pressing Search
tomcat

Class: org.apache.jk.apr.TomcatStarter   ©

 OK to copy?
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[]={ "org.apache.tomcat.startup.Main",
34                                          "org.apache.catalina.startup.BootstrapService",
35                                          "org.apache.catalina.startup.Bootstrap"};
36 
37     // If someone has time - we can also guess the classpath and do other
38     // fancy guessings.
39     
40     public static void main( String args[] ) {
41         System.err.println("TomcatStarter: main()");
42         int nClasses = 0;
43         
44         try {
45             AprImpl.jniMode();            
46             // Find the class
47             Class c=null;
48             for( int i=0; i<mainClasses.length; i++ ) {
49                 try {
50                     System.err.println("Try  " + mainClasses[i]);
51                     c=Class.forName( mainClasses[i] );
52                 } catch( ClassNotFoundException ex  ) {
53                     continue;
54                 }
55                 if( c!= null ) {
56                     ++nClasses;
57                     Thread startThread=new Thread( new TomcatStarter(c, args));
58                     c=null;
59                     startThread.start();
60                     break;
61                 }
62             }
63             if (nClasses==0)
64                 System.err.println("No class found  ");
65 
66         } catch (Throwable t ) {
67             t.printStackTrace(System.err);
68         }
69     }
70 
71     public TomcatStarter( Class c, String args[] ) {
72         this.c=c;
73         this.args=args;
74     }
75     
76     public void run() {
77         System.err.println("Starting " + c.getName());
78         try {
79             Class argClass=args.getClass();
80             Method m=c.getMethod( "main", new Class[] {argClass} );
81             m.invoke( c, new Object[] { args } );
82             System.out.println("TomcatStarter: Done");
83             if (apr.isLoaded())
84                 apr.jkSetAttribute(0, 0, "channel:jni", "done");
85             if (args[0].equals("stop")) {
86                   Thread.sleep(5000);
Rate87                   Runtime.getRuntime().exit(0);
88             }
89         } catch( Throwable t ) {
90             t.printStackTrace(System.err);
91         }
92     }
93 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
87 0% of 0