costin 02/01/26 09:23:19 Modified: jk/java/org/apache/jk/server JkMain.java Log: Get a worker.properties-like functionality for JkMain. It should be able to read the same file as mod_jk, so we have to configure the port in a single file instead of 2. It can now add dynamically workers and channels, no need to hardcode it. Revision Changes Path 1.7 +97 -32 jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkMain.java Index: JkMain.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkMain.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JkMain.java 21 Jan 2002 20:11:52 -0000 1.6 +++ JkMain.java 26 Jan 2002 17:23:19 -0000 1.7 @@ -68,6 +68,7 @@ import org.apache.tomcat.util.buf.*; import org.apache.tomcat.util.http.*; +import org.apache.tomcat.util.IntrospectionUtils; /** Main class used for testing jk core and common code and tunning. * @@ -78,20 +79,17 @@ { WorkerEnv wEnv=new WorkerEnv(); String propFile; - Properties props; + Properties props=new Properties(); Worker defaultWorker; String jkHome; - Class channelclass; - public JkMain() { } public void setPropFile( String p ) { propFile=p; - props=new Properties(); try { props.load( new FileInputStream(propFile) ); } catch(IOException ex ){ @@ -99,8 +97,24 @@ } } - public void setProperties( Properties p ) { - props=p; + public void setProperty( String n, String v ) { + props.put( n, v ); + } + + /** + * Set the <code>channelClassName</code> that will used to connect to + * httpd. + */ + public void setChannelClassName(String name) { + props.put( "channel.default.className",name); + } + + /** + * Set the <code>channelClassName</code> that will used to connect to + * httpd. + */ + public void setWorkerClassName(String name) { + props.put( "worker.default.className",name); } public void setDefaultWorker( Worker w ) { @@ -111,47 +125,98 @@ jkHome=s; } - public void setChannelClass( Class c ) { - channelclass = c; - } - - public void start() throws IOException { - Channel csocket=null; + private Object newInstance( String type, String name, String def ) + throws IOException + { try { - csocket=(Channel)channelclass.newInstance(); + String classN=props.getProperty( type + "." + name + ".className", + def ); + Class channelclass = Class.forName(classN); + return channelclass.newInstance(); } catch (Exception ex) { ex.printStackTrace(); throw new IOException("Cannot create channel class"); } + } + + public void start() throws IOException + { + String workers=props.getProperty( "worker.list", "default" ); + Vector workerNamesV= split( workers, ","); - // Set file. - if( jkHome==null ) - csocket.setFile( "/tmp/tomcatUnixSocket" ); - else - csocket.setFile( jkHome + "/WEB-INF/tomcatUnixSocket" ); - csocket.setJkHome( jkHome ); - - // Set port number. - csocket.setPort( 8009 ); + for( int i=0; i<workerNamesV.size(); i++ ) { + String name= (String)workerNamesV.elementAt( i ); + Worker w=(Worker)newInstance( "worker", name, + "org.apache.jk.common.WorkerDummy"); + + processProperties( w, "worker."+ name + "." ); - wEnv.addChannel( csocket ); + wEnv.addWorker( name, w ); + } + + defaultWorker = wEnv.getWorker( "default" ); - if( defaultWorker == null ) - defaultWorker=new WorkerDummy(); + // XXX alternatives, setters, etc + String channels=props.getProperty( "channel.list", "default" ); + Vector channelNamesV= split( channels, ","); + + for( int i=0; i<channelNamesV.size(); i++ ) { + String name= (String)channelNamesV.elementAt( i ); + Channel ch=(Channel)newInstance( "channel", name, + "org.apache.jk.common.ChannelSocket"); + processProperties( ch, "channel."+ name + "." ); + + if( jkHome != null ) + this.setProperty( ch, "jkHome", jkHome ); + + wEnv.addChannel( name, ch ); + ch.setWorker( defaultWorker ); + } + + // channel and handler should _pull_ the worker from we - csocket.setWorker( defaultWorker ); - wEnv.addWorker( defaultWorker ); - HandlerRequest hReq=new HandlerRequest(); - wEnv.addHandler( hReq ); hReq.setWorker( defaultWorker ); - - HandlerEcho hEcho=new HandlerEcho(); - wEnv.addHandler( hEcho ); + wEnv.addHandler( hReq ); wEnv.start(); } + /* A bit of magic to support workers.properties without giving + up the clean get/set + */ + public void setProperty( Object target, String name, String val ) { + /* XXX we need an improved IntrospectionUtils, to report error + without d() */ + d( "setProperty " + target + " " + name + "=" + val ); + IntrospectionUtils.setProperty( target, name, val ); + } + + private void processProperties(Object o, String prefix) { + Enumeration keys=props.keys(); + int plen=prefix.length(); + + while( keys.hasMoreElements() ) { + String k=(String)keys.nextElement(); + if( ! k.startsWith( prefix ) ) + continue; + + String name= k.substring( plen ); + String propValue=props.getProperty( k ); + if( "className".equals( name ) ) + continue; + this.setProperty( o, name, propValue ); + } + } + + private Vector split(String s, String delim ) { + Vector v=new Vector(); + StringTokenizer st=new StringTokenizer(s, delim ); + while( st.hasMoreTokens() ) { + v.addElement( st.nextToken()); + } + return v; + } public static void main(String args[]) { try {
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>