costin      02/04/18 12:12:36

  Modified:    jk/java/org/apache/jk/common ChannelSocket.java
                        ChannelUn.java
  Log:
  Allow a 'range' of ports to be used.
  
  This allows multiple tomcats to be started on the same machine with the
  same configuration - and get consecutive sockets ( tcp and unix ) automatically.
  Needed for jni, it also simplify the configuration of lb workers - no need
  to use separate config files for each worker ( on a machine ).
  
  The port will also determine the local part of the instance ID ( the hostname
  or address should form the other part - and we need a way to push this up
  into the coyote and container ).
  
  If Shm is detected it'll set the instance id based on the shared memory
  protocol ( i.e. each worker will get a unique id based on the position
  of the worker def in the shared mem ) .
  
  Revision  Changes    Path
  1.9       +49 -3     
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java
  
  Index: ChannelSocket.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ChannelSocket.java        17 Apr 2002 22:38:16 -0000      1.8
  +++ ChannelSocket.java        18 Apr 2002 19:12:36 -0000      1.9
  @@ -98,7 +98,9 @@
       private static org.apache.commons.logging.Log log=
           org.apache.commons.logging.LogFactory.getLog( ChannelSocket.class );
   
  -    int port=8009;
  +    int startPort=8009;
  +    int maxPort=8019; // 0 for backward compat.
  +    int port=startPort;
       InetAddress inet;
       int serverTimeout;
       boolean tcpNoDelay;
  @@ -112,9 +114,18 @@
       public ThreadPool getThreadPool() {
           return tp;
       }
  -    
  +
  +    /** Set the port for the ajp13 channel.
  +     *  To support seemless load balancing and jni, we treat this
  +     *  as the 'base' port - we'll try up until we find one that is not
  +     *  used. We'll also provide the 'difference' to the main coyote
  +     *  handler - that will be our 'sessionID' and the position in
  +     *  the scoreboard and the suffix for the unix domain socket.
  +     */
       public void setPort( int port ) {
  +        this.startPort=port;
           this.port=port;
  +        this.maxPort=port+10;
       }
   
       public void setAddress(InetAddress inet) {
  @@ -153,6 +164,14 @@
        socketTimeout=i;
       }
   
  +    public void setMaxPort( int i ) {
  +        maxPort=i;
  +    }
  +
  +    public int getInstanceId() {
  +        return port-startPort;
  +    }
  +    
       /* ==================== ==================== */
       ServerSocket sSocket;
       int socketNote=1;
  @@ -160,6 +179,7 @@
       int osNote=3;
   
       public void accept( MsgContext ep ) throws IOException {
  +        if( sSocket==null ) return;
           Socket s=sSocket.accept();
           ep.setNote( socketNote, s );
           if(log.isDebugEnabled() )
  @@ -176,7 +196,33 @@
       }
   
       public void init() throws IOException {
  -        sSocket=new ServerSocket( port );
  +        // Find a port.
  +        if( maxPort<startPort) maxPort=startPort;
  +
  +        for( int i=startPort; i<=maxPort; i++ ) {
  +            try {
  +                sSocket=new ServerSocket( i );
  +                port=i;
  +                break;
  +            } catch( IOException ex ) {
  +                log.info("Port busy " + i + " " + ex.toString());
  +                continue;
  +            }
  +        }
  +        
  +        if( sSocket==null ) {
  +            log.error("Can't find free port " + startPort + " " + maxPort );
  +            return;
  +        }
  +        log.info("Init " + port );
  +        
  +        // If this is not the base port and we are the 'main' channleSocket and
  +        // SHM didn't already set the localId - we'll set the instance id
  +        if( "channelSocket".equals( name ) &&
  +            port != startPort &&
  +            (wEnv.getLocalId()==0) ) {
  +            wEnv.setLocalId(  port - startPort );
  +        }
           if( serverTimeout > 0 )
               sSocket.setSoTimeout( serverTimeout );
   
  
  
  
  1.14      +4 -0      
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelUn.java
  
  Index: ChannelUn.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelUn.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ChannelUn.java    18 Apr 2002 17:44:49 -0000      1.13
  +++ ChannelUn.java    18 Apr 2002 19:12:36 -0000      1.14
  @@ -136,6 +136,10 @@
               log.error("No file, disabling unix channel");
               return;
           }
  +        if( wEnv.getLocalId() != 0 ) {
  +            file=file+ wEnv.getLocalId();
  +        }
  +        
           if( next==null ) {
               if( nextName!=null ) 
                   setNext( wEnv.getHandler( nextName ) );
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to