tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/res LocalStrings.properties LocalStrings_fr.properties
Date Fri, 10 Jan 2003 20:22:38 GMT
remm        2003/01/10 12:22:38

  Modified:    util/java/org/apache/tomcat/util/net PoolTcpEndpoint.java
               util/java/org/apache/tomcat/util/net/res
                        LocalStrings.properties LocalStrings_fr.properties
  Log:
  - Refactor the server socket restart code.
  
  Revision  Changes    Path
  1.12      +76 -55    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PoolTcpEndpoint.java	1 Jan 2003 13:55:22 -0000	1.11
  +++ PoolTcpEndpoint.java	10 Jan 2003 20:22:37 -0000	1.12
  @@ -122,6 +122,7 @@
       ThreadPoolRunnable listener;
       private volatile boolean running = false;
       private boolean initialized = false;
  +    private boolean reinitializing = false;
       static final int debug=0;
   
       ThreadPool tp;
  @@ -311,28 +312,34 @@
   	if (running) {
   	    tp.shutdown();
   	    running = false;
  -	    try {
  -		// Need to create a connection to unlock the accept();
  -		Socket s;
  -		if (inet == null) {
  -		    s=new Socket("127.0.0.1", port );
  -		}else{
  -		    s=new Socket(inet, port );
  +            if (serverSocket != null) {
  +                closeServerSocket();
  +            }
  +	}
  +    }
  +
  +    protected void closeServerSocket() {
  +        try {
  +            // Need to create a connection to unlock the accept();
  +            Socket s;
  +            if (inet == null) {
  +                s=new Socket("127.0.0.1", port );
  +            }else{
  +                s=new Socket(inet, port );
                       // setting soLinger to a small value will help shutdown the
                       // connection quicker
  -                    s.setSoLinger(true, 0);
  -		}
  -		s.close();
  -	    } catch(Exception e) {
  -                log.error("Caught exception trying to unlock accept.", e);
  -	    }
  -	    try {
  -		serverSocket.close();
  -	    } catch(Exception e) {
  -                log.error("Caught exception trying to close socket.", e);
  -	    }
  -	    serverSocket = null;
  -	}
  +                s.setSoLinger(true, 0);
  +            }
  +            s.close();
  +        } catch(Exception e) {
  +            log.error("Caught exception trying to unlock accept.", e);
  +        }
  +        try {
  +            serverSocket.close();
  +        } catch(Exception e) {
  +            log.error("Caught exception trying to close socket.", e);
  +        }
  +        serverSocket = null;
       }
   
       // -------------------- Private methods
  @@ -362,49 +369,62 @@
           }
           catch (IOException e) {
   
  -            if (running) {
  +            String msg = null;
   
  -                String msg = sm.getString("endpoint.err.nonfatal",
  +            if (running) {
  +                msg = sm.getString("endpoint.err.nonfatal",
                           serverSocket, e);
                   log.error(msg, e);
  +            }
   
  -                if (accepted != null) {
  -                    try {
  -                        accepted.close();
  -                        accepted = null;
  -                    } catch(Exception ex) {
  -                        msg = sm.getString("endpoint.err.nonfatal",
  -                                accepted, ex);
  -                        log.warn(msg, ex);
  -                    }
  +            if (accepted != null) {
  +                try {
  +                    accepted.close();
  +                    accepted = null;
  +                } catch(Exception ex) {
  +                    msg = sm.getString("endpoint.err.nonfatal",
  +                                       accepted, ex);
  +                    log.warn(msg, ex);
                   }
  -                // Restart endpoint when getting an IOException during accept
  -                synchronized (threadSync) {
  +            }
  +
  +            reinitializing = true;
  +            // Restart endpoint when getting an IOException during accept
  +            synchronized (threadSync) {
  +                if (reinitializing) {
  +                    reinitializing = false;
  +                    // 1) Attempt to close server socket
  +                    closeServerSocket();
  +                    initialized = false;
  +                    // 2) Reinit endpoint (recreate server socket)
                       try {
  -                        serverSocket.close();
  -                    } catch(Exception ex) {
  +                        msg = sm.getString("endpoint.warn.reinit");
  +                        log.warn(msg);
  +                        initEndpoint();
  +                    } catch (Throwable t) {
                           msg = sm.getString("endpoint.err.nonfatal",
  -                                serverSocket, ex);
  -                        log.warn(msg, ex);
  +                                           serverSocket, t);
  +                        log.error(msg, t);
                       }
  -                    serverSocket = null;
  -                    try {
  -                        if (inet == null) {
  -                            serverSocket = factory.createSocket(port, backlog);
  -                        } else {
  -                            serverSocket =
  -                                    factory.createSocket(port, backlog, inet);
  +                    // 3) If failed, attempt to restart endpoint
  +                    if (!initialized) {
  +                        msg = sm.getString("endpoint.warn.restart");
  +                        log.warn(msg);
  +                        try {
  +                            stopEndpoint();
  +                            initEndpoint();
  +                            startEndpoint();
  +                        } catch (Throwable t) {
  +                            msg = sm.getString("endpoint.err.fatal",
  +                                               serverSocket, t);
  +                            log.error(msg, t);
  +                        } finally {
  +                            // Current thread is now invalid: kill it
  +                            throw new IllegalStateException
  +                                ("Terminating thread");
                           }
  -                        if (serverTimeout >= 0)
  -                            serverSocket.setSoTimeout(serverTimeout);
  -                    } catch (Throwable t) {
  -                        msg = sm.getString("endpoint.err.fatal",
  -                                serverSocket, t);
  -                        log.error(msg, t);
  -                        stopEndpoint();
                       }
                   }
  -
               }
   
           }
  @@ -509,6 +529,7 @@
   		s = endpoint.acceptSocket();
   	    } catch (Throwable t) {
   		endpoint.log.error("Exception in acceptSocket", t);
  +                throw new IllegalStateException("Terminating thread");
   	    }
   	    if(null != s) {
   		// Continue accepting on another thread...
  
  
  
  1.3       +2 -1      jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/res/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/res/LocalStrings.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LocalStrings.properties	15 May 2002 17:38:37 -0000	1.2
  +++ LocalStrings.properties	10 Jan 2003 20:22:38 -0000	1.3
  @@ -1,4 +1,5 @@
   # net resources
   endpoint.err.fatal=Endpoint {0} shutdown due to exception: {1}
   endpoint.err.nonfatal=Endpoint {0} ignored exception: {1}
  -
  +endpoint.warn.reinit=Reinitializing ServerSocket
  +endpoint.warn.restart=Restarting endpoint
  
  
  
  1.2       +2 -0      jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/res/LocalStrings_fr.properties
  
  Index: LocalStrings_fr.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/res/LocalStrings_fr.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalStrings_fr.properties	5 Nov 2002 09:37:35 -0000	1.1
  +++ LocalStrings_fr.properties	10 Jan 2003 20:22:38 -0000	1.2
  @@ -1,4 +1,6 @@
   # net resources
   endpoint.err.fatal=Le point de contact {0} a été éteint suite à l''exception{1}
   endpoint.err.nonfatal=Le point de contact {0} a ignoré l''exception: {1}
  +endpoint.warn.reinit=Réinitialisation du ServerSocket
  +endpoint.warn.restart=Redémarrage du point de contact
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message