📄 jkmain.java
字号:
} catch( IOException ex) { log.error("Error stoping " + wEnv.getHandler(i).getName(), ex); } } } started=false; } public void start() throws IOException { long t1=System.currentTimeMillis(); // We must have at least 3 handlers: // channel is the 'transport' // request is the request processor or 'global' chain // container is the 'provider' // Additional handlers may exist and be used internally // or be chained to create one of the standard handlers String handlers[]=defaultHandlers; String workers=props.getProperty( "handler.list", null ); if( workers!=null ) { handlers= split( workers, ","); } // Load additional component declarations processModules(); for( int i=0; i<handlers.length; i++ ) { String name= handlers[i]; JkHandler w=wEnv.getHandler( name ); if( w==null ) { newHandler( name, "", name ); } } // Process properties - and add aditional handlers. processProperties(); for( int i=0; i<wEnv.getHandlerCount(); i++ ) { if( wEnv.getHandler(i) != null ) { try { wEnv.getHandler(i).init(); } catch( IOException ex) { if( "apr".equals(wEnv.getHandler(i).getName() )) { log.info( "APR not loaded, disabling jni components: " + ex.toString()); } else { log.error( "error initializing " + wEnv.getHandler(i).getName(), ex ); } } } } started=true; long t2=System.currentTimeMillis(); startTime=t2-t1; this.saveProperties(); log.info("Jk running ID=" + wEnv.getLocalId() + " time=" + initTime + "/" + startTime + " config=" + propFile); } // -------------------- Usefull methods -------------------- public WorkerEnv getWorkerEnv() { return wEnv; } /* A bit of magic to support workers.properties without giving up the clean get/set */ public void setBeanProperty( Object target, String name, String val ) { if( val!=null ) val=IntrospectionUtils.replaceProperties( val, props ); if( log.isDebugEnabled()) log.debug( "setProperty " + target + " " + name + "=" + val ); IntrospectionUtils.setProperty( target, name, val ); } /* * Set a handler property */ public void setPropertyString( String handlerN, String name, String val ) { if( log.isDebugEnabled() ) log.debug( "setProperty " + handlerN + " " + name + "=" + val ); Object target=wEnv.getHandler( handlerN ); setBeanProperty( target, name, val ); if( started ) { saveProperties(); } } /** The time it took to initialize jk ( ms) */ public long getInitTime() { return initTime; } /** The time it took to start jk ( ms ) */ public long getStartTime() { return startTime; } // -------------------- Main -------------------- long initTime; long startTime; static JkMain jkMain=null; public static void main(String args[]) { try { if( args.length == 1 && ( "-?".equals(args[0]) || "-h".equals( args[0])) ) { System.out.println("Usage: "); System.out.println(" JkMain [args]"); System.out.println(); System.out.println(" Each bean setter corresponds to an arg ( like -debug 10 )"); System.out.println(" System properties:"); System.out.println(" jk2.home Base dir of jk2"); return; } jkMain=new JkMain(); IntrospectionUtils.processArgs( jkMain, args, new String[] {}, null, new Hashtable()); jkMain.init(); jkMain.start(); } catch( Exception ex ) { ex.printStackTrace(); } } // -------------------- Private methods -------------------- public void saveProperties() { if( !saveProperties) return; // Temp - to check if it works String outFile=propFile + ".save"; log.debug("Saving properties " + outFile ); try { props.save( new FileOutputStream(outFile), "AUTOMATICALLY GENERATED" ); } catch(IOException ex ){ ex.printStackTrace(); } } // translate top-level keys ( from coyote or generic ) into component keys static Hashtable replacements=new Hashtable(); static { replacements.put("port","channelSocket.port"); replacements.put("maxThreads", "channelSocket.maxThreads"); replacements.put("backlog", "channelSocket.backlog"); replacements.put("tcpNoDelay", "channelSocket.tcpNoDelay"); replacements.put("soTimeout", "channelSocket.soTimeout"); replacements.put("timeout", "channelSocket.timeout"); replacements.put("address", "channelSocket.address"); } private void preProcessProperties() { Enumeration keys=props.keys(); Vector v=new Vector(); while( keys.hasMoreElements() ) { String key=(String)keys.nextElement(); Object newName=replacements.get(key); if( newName !=null ) { v.addElement(key); } } keys=v.elements(); while( keys.hasMoreElements() ) { String key=(String)keys.nextElement(); Object propValue=props.getProperty( key ); String replacement=(String)replacements.get(key); props.put(replacement, propValue); if( log.isDebugEnabled()) log.debug("Substituting " + key + " " + replacement + " " + propValue); } } private void processProperties() { preProcessProperties(); Enumeration keys=props.keys(); while( keys.hasMoreElements() ) { String name=(String)keys.nextElement(); String propValue=props.getProperty( name ); processProperty( name, propValue ); } } private void processProperty(String name, String propValue) { String type=name; String fullName=name; String localName=""; String propName=""; int dot=name.indexOf("."); int lastDot=name.lastIndexOf("."); if( dot > 0 ) { type=name.substring(0, dot ); if( dot != lastDot ) { localName=name.substring( dot + 1, lastDot ); fullName=type + "." + localName; } else { fullName=type; } propName=name.substring( lastDot+1); } else { return; } if( log.isDebugEnabled() ) log.debug( "Processing " + type + ":" + localName + ":" + fullName + " " + propName ); if( "class".equals( type ) || "handler".equals( type ) ) { return; } JkHandler comp=wEnv.getHandler( fullName ); if( comp==null ) { comp=newHandler( type, localName, fullName ); } if( comp==null ) return; if( log.isDebugEnabled() ) log.debug("Setting " + propName + " on " + fullName + " " + comp); this.setBeanProperty( comp, propName, propValue ); } private JkHandler newHandler( String type, String localName, String fullName ) { JkHandler handler; String classN=modules.getProperty(type); if( classN == null ) { log.error("No class name for " + fullName + " " + type ); return null; } try { Class channelclass = Class.forName(classN); handler=(JkHandler)channelclass.newInstance(); } catch (Throwable ex) { handler=null; log.error( "Can't create " + fullName, ex ); return null; } wEnv.addHandler( fullName, handler ); return handler; } private void processModules() { Enumeration keys=props.keys(); int plen=6; while( keys.hasMoreElements() ) { String k=(String)keys.nextElement(); if( ! k.startsWith( "class." ) ) continue; String name= k.substring( plen ); String propValue=props.getProperty( k ); if( log.isDebugEnabled()) log.debug("Register " + name + " " + propValue ); modules.put( name, propValue ); } } private String[] split(String s, String delim ) { Vector v=new Vector(); StringTokenizer st=new StringTokenizer(s, delim ); while( st.hasMoreTokens() ) { v.addElement( st.nextToken()); } String res[]=new String[ v.size() ]; for( int i=0; i<res.length; i++ ) { res[i]=(String)v.elementAt(i); } return res; } // guessing home private static String CNAME="org/apache/jk/server/JkMain.class"; private void guessHome() { String home= wEnv.getJkHome(); if( home != null ) return; home=IntrospectionUtils.guessInstall( "jk2.home","jk2.home", "tomcat-jk2.jar", CNAME ); if( home != null ) { log.info("Guessed home " + home ); wEnv.setJkHome( home ); } } static org.apache.commons.logging.Log log= org.apache.commons.logging.LogFactory.getLog( JkMain.class );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -