remm        2004/01/26 10:19:48

  Modified:    util/java/org/apache/tomcat/util/net PoolTcpEndpoint.java
  Log:
  - Implement clean shutdown of the connectors (my third proposal).
  - Add pause and resume methods on the TCP endpoint.
  - The method I've choosen is to stop accepting to inform whatever the load balancer 
is
    that the server is down. A plus: clients will wait until the connector is 
unpaused, up
    to the configured backlog for the server socket. Another method would be to accept 
and
    close the connection right away.
    accept and close the socket right away
  
  Revision  Changes    Path
  1.32      +50 -12    
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/PoolTcpEndpoint.java
  
  Index: PoolTcpEndpoint.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/PoolTcpEndpoint.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- PoolTcpEndpoint.java      13 Jan 2004 10:16:38 -0000      1.31
  +++ PoolTcpEndpoint.java      26 Jan 2004 18:19:48 -0000      1.32
  @@ -127,6 +127,7 @@
   
       ThreadPoolRunnable listener;
       private volatile boolean running = false;
  +    private volatile boolean paused = false;
       private boolean initialized = false;
       private boolean reinitializing = false;
       static final int debug=0;
  @@ -227,6 +228,10 @@
        return running;
       }
       
  +    public boolean isPaused() {
  +     return paused;
  +    }
  +    
       /**
        * Allows the server developer to specify the backlog that
        * should be used for server sockets. By default, this value
  @@ -322,6 +327,7 @@
            tp.start();
        }
        running = true;
  +        paused = false;
           if(isPool) {
            listener = new TcpWorkerThread(this);
               tp.runIt(listener);
  @@ -330,6 +336,19 @@
        }
       }
   
  +    public void pauseEndpoint() {
  +        if (running && !paused) {
  +            paused = true;
  +            unlockAccept();
  +        }
  +    }
  +
  +    public void resumeEndpoint() {
  +        if (running) {
  +            paused = false;
  +        }
  +    }
  +
       public void stopEndpoint() {
        if (running) {
            tp.shutdown();
  @@ -341,6 +360,18 @@
       }
   
       protected void closeServerSocket() {
  +        if (!paused)
  +            unlockAccept();
  +        try {
  +            if( serverSocket!=null)
  +                serverSocket.close();
  +        } catch(Exception e) {
  +            log.error("Caught exception trying to close socket.", e);
  +        }
  +        serverSocket = null;
  +    }
  +
  +    protected void unlockAccept() {
           Socket s = null;
           try {
               // Need to create a connection to unlock the accept();
  @@ -353,8 +384,8 @@
                   s.setSoLinger(true, 0);
               }
           } catch(Exception e) {
  -            log.error("Caught exception trying to unlock accept on " + port
  -                    + " " + e.toString());
  +            log.debug("Caught exception trying to unlock accept on " + port
  +                      + " " + e.toString());
           } finally {
               if (s != null) {
                   try {
  @@ -364,13 +395,6 @@
                   }
               }
           }
  -        try {
  -            if( serverSocket!=null)
  -                serverSocket.close();
  -        } catch(Exception e) {
  -            log.error("Caught exception trying to close socket.", e);
  -        }
  -        serverSocket = null;
       }
   
       // -------------------- Private methods
  @@ -552,6 +576,17 @@
   
        // Create per-thread cache
        if (endpoint.isRunning()) {
  +
  +            // Loop if endpoint is paused
  +            while (endpoint.isPaused()) {
  +                try {
  +                    Thread.sleep(1000);
  +                } catch (InterruptedException e) {
  +                    // Ignore
  +                }
  +            }
  +
  +            // Accept a new connection
            Socket s = null;
            try {
                   s = endpoint.acceptSocket();
  @@ -561,6 +596,8 @@
                       endpoint.tp.runIt(this);
                   }
               }
  +
  +            // Process the connection
            if (null != s) {
   
                   TcpConnection con = null;
  @@ -608,6 +645,7 @@
                       }
                   }
            }
  +
        }
       }
   
  
  
  

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

Reply via email to