[jboss-cvs] JBossAS SVN: r76262 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/impl.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Jul 27 14:08:06 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-07-27 14:08:06 -0400 (Sun, 27 Jul 2008)
New Revision: 76262

Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
[JBAS-5659] Add method for sending multiple requests; rationalize method names; port recent changes from JBoss Web ClusterListener class

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/impl/DefaultMCMPHandler.java	2008-07-27 18:07:30 UTC (rev 76261)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/impl/DefaultMCMPHandler.java	2008-07-27 18:08:06 UTC (rev 76262)
@@ -54,7 +54,6 @@
 import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPHandler;
 import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPRequest;
 import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPRequestType;
-import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPServer;
 import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPServerState;
 import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPUtils;
 import org.jboss.web.tomcat.service.modcluster.mcmp.ResetRequestSource;
@@ -149,20 +148,17 @@
    
    // -------------------------------------------------------------- Properties
 
-
+   public ResetRequestSource getResetRequestSource() 
+   { 
+      return this.resetRequestSource; 
+   }
    
-   
    // ------------------------------------------------------------  MCMPHandler
    
    public MCMPHandlerConfiguration getConfiguration()
    {
       return this.config;
    }
-
-   public ResetRequestSource getResetRequestSource() 
-   { 
-      return this.resetRequestSource; 
-   }
    
    public synchronized void init()
    {
@@ -249,18 +245,12 @@
       this.init = false;
    }
    
-   /**
-    * Add proxy.
-    */
    public void addProxy(String address) {
        
        AddressPort ap = MCMPUtils.parseAddressPort(address);
        addProxy(ap.address, ap.port);
    }   
    
-   /**
-    * Add proxy.
-    */
    public synchronized void addProxy(String host, int port) 
    {
       InetAddress address = null;
@@ -302,16 +292,13 @@
       return proxy;
    }
    
-   public synchronized void establishProxy(MCMPServer server)
+   public synchronized void addProxy(InetAddress address, int port, boolean established)
    {     
-      Proxy proxy = addProxyInternal(server.getAddress(), server.getPort());
-      proxy.setEstablished(server.isEstablished());
+      Proxy proxy = addProxyInternal(address, port);
+      proxy.setEstablished(established);
    }
    
    
-   /**
-    * Remove proxy.
-    */
    public synchronized void removeProxy(String host, int port) 
    {
       InetAddress address = null;
@@ -323,9 +310,6 @@
       removeProxy(address, port);
    }   
    
-   /**
-    * Remove proxy.
-    */
    public synchronized void removeProxy(InetAddress address, int port) 
    {
       Proxy proxy = new Proxy(address, port, this.sslSocketFactory, this.config.getSocketTimeout());
@@ -351,12 +335,15 @@
    {
       boolean ok = true;
       Proxy[] local = proxies;
-      for (Proxy proxy : local)
+      if (local != null)
       {
-         if (proxy.getState() != MCMPServerState.State.OK)
+         for (Proxy proxy : local)
          {
-            ok = false;
-            break;
+            if (proxy.getState() != MCMPServerState.State.OK)
+            {
+               ok = false;
+               break;
+            }
          }
       }
       return ok;
@@ -365,16 +352,19 @@
    public synchronized void markProxiesInError()
    {
       Proxy[] local = proxies;
-      for (Proxy proxy : local)
+      if (local != null)
       {
-         synchronized (proxy)
+         for (Proxy proxy : local)
          {
-            if (proxy.getState() == State.OK)
+            synchronized (proxy)
             {
-               proxy.setState(Proxy.State.ERROR);
+               if (proxy.getState() == State.OK)
+               {
+                  proxy.setState(Proxy.State.ERROR);
+               }
             }
          }
-      }      
+      }
    }
    
    /**
@@ -399,7 +389,7 @@
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < local.length; i++) {
           
-           result.append("Proxy[").append(i).append("]:[").append(local[i].getAddress())
+           result.append("Proxy[").append(i).append("]: [").append(local[i].getAddress())
                    .append(':').append(local[i].getPort()).append("]: \r\n");
            synchronized (local[i])
            {
@@ -477,35 +467,33 @@
     * 
     * @param engine
     */
-   public void status() {
+   public synchronized void status() {
        
        // Check to add or remove proxies, and rebuild a new list if needed
-       synchronized (this) {
-           if (!addProxies.isEmpty() || !removeProxies.isEmpty()) {
-               ArrayList<Proxy> currentProxies = new ArrayList<Proxy>();
-               for (int i = 0; i < proxies.length; i++) {
-                   currentProxies.add(proxies[i]);
-               }
-               for (int i = 0; i < addProxies.size(); i++) {
-                   if (!currentProxies.contains(addProxies.get(i))) {
-                       currentProxies.add(addProxies.get(i));
-                   }
-               }
-               for (int i = 0; i < removeProxies.size(); i++) {
-                   if (currentProxies.contains(removeProxies.get(i))) {
-                       currentProxies.remove(removeProxies.get(i));
-                   }
-               }
-               addProxies.clear();
-               removeProxies.clear();
-               proxies = currentProxies.toArray(new Proxy[0]);
-               
-               // Reset all connections
-               for (Proxy proxy : proxies)
-               {                  
-                  proxy.closeConnection();
-               }
-           }
+       if (!addProxies.isEmpty() || !removeProxies.isEmpty()) {
+            ArrayList<Proxy> currentProxies = new ArrayList<Proxy>();
+            for (int i = 0; i < proxies.length; i++) {
+                currentProxies.add(proxies[i]);
+            }
+            for (int i = 0; i < addProxies.size(); i++) {
+                if (!currentProxies.contains(addProxies.get(i))) {
+                    currentProxies.add(addProxies.get(i));
+                }
+            }
+            for (int i = 0; i < removeProxies.size(); i++) {
+                if (currentProxies.contains(removeProxies.get(i))) {
+                    currentProxies.remove(removeProxies.get(i));
+                }
+            }
+            addProxies.clear();
+            removeProxies.clear();
+            proxies = currentProxies.toArray(new Proxy[0]);
+            
+            // Reset all connections
+            for (Proxy proxy : proxies)
+            {                  
+               proxy.closeConnection();
+            }
        }
        
        // Attempt to reset any proxies in error
@@ -517,10 +505,14 @@
               if (proxy.getState() == Proxy.State.ERROR) {
                  proxy.setState(Proxy.State.OK);
                  
-                 sendRequest(MCMPUtils.getInfoRequest());
+                 sendRequest(MCMPUtils.getInfoRequest(), proxy);
                  
                  if (proxy.getState() == Proxy.State.OK)
                  {
+                    // We recovered above; if we get another IOException 
+                    // we should log it                    
+                    proxy.setIoErrorLogged(false);
+                    
                     if (resetRequests == null)
                     {
                        resetRequests = this.resetRequestSource.getResetRequests();
@@ -554,9 +546,23 @@
           sendRequest(request, proxy);
        }
    }
+   
+   
 
-   private String sendRequest(MCMPRequest request, Proxy proxy) {
+   public void sendRequests(List<MCMPRequest> requests)
+   {
+      Proxy[] local = proxies;
+      for (Proxy proxy : local)
+      {
+         for (MCMPRequest request : requests)
+         {
+            sendRequest(request, proxy);
+         }
+      }      
+   }
 
+   private synchronized String sendRequest(MCMPRequest request, Proxy proxy) {
+
        BufferedReader reader = null;
        BufferedWriter writer = null;
        CharChunk body = null;
@@ -722,7 +728,12 @@
            } catch (IOException e) {
                // Most likely this is a connection error with the proxy
                proxy.setState(Proxy.State.ERROR);
-               log.info(sm.getString("clusterListener.error.io", command, proxy), e);
+               
+               // Log it only if we haven't done so already. Don't spam the log
+               if (proxy.isIoErrorLogged() == false) {                  
+                  log.info(sm.getString("clusterListener.error.io", command, proxy), e);
+                  proxy.setIoErrorLogged(true);
+               }
            } finally {
                // If there's an error of any sort, or if the proxy did not return 200, it is an error
                if (proxy.getState() != Proxy.State.OK) {
@@ -804,6 +815,7 @@
       private Socket connection;
       private BufferedReader connectionReader;
       private BufferedWriter connectionWriter;
+      private boolean ioErrorLogged;
 
       /**
        * The string manager for this package.
@@ -1000,6 +1012,18 @@
           }
           connection = null;
       }
+
+      private boolean isIoErrorLogged()
+      {
+         return this.ioErrorLogged;
+      }
+
+      private void setIoErrorLogged(boolean ioErrorLogged)
+      {
+         this.ioErrorLogged = ioErrorLogged;
+      }
+      
+      
    }
    
    @Immutable




More information about the jboss-cvs-commits mailing list