[jboss-cvs] JBossAS SVN: r77545 - in trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster: mcmp and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 27 14:47:17 EDT 2008


Author: pferraro
Date: 2008-08-27 14:47:17 -0400 (Wed, 27 Aug 2008)
New Revision: 77545

Added:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/AbstractMCMPHandler.java
Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/ha/ClusteredMCMPHandlerImpl.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Consolidate duplicate MCMPHandler logic into common base class.

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/ha/ClusteredMCMPHandlerImpl.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/ha/ClusteredMCMPHandlerImpl.java	2008-08-27 18:25:50 UTC (rev 77544)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/ha/ClusteredMCMPHandlerImpl.java	2008-08-27 18:47:17 UTC (rev 77545)
@@ -45,14 +45,14 @@
 import org.jboss.web.tomcat.service.modcluster.ha.rpc.MCMPServerDiscoveryEvent;
 import org.jboss.web.tomcat.service.modcluster.ha.rpc.StringGroupRpcResponse;
 import org.jboss.web.tomcat.service.modcluster.ha.rpc.ThrowableGroupRpcResponse;
+import org.jboss.web.tomcat.service.modcluster.mcmp.AbstractMCMPHandler;
 import org.jboss.web.tomcat.service.modcluster.mcmp.AddressPort;
 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.MCMPServer;
 import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPServerState;
-import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPUtils;
 
-public class ClusteredMCMPHandlerImpl implements ClusteredMCMPHandler
+public class ClusteredMCMPHandlerImpl extends AbstractMCMPHandler implements ClusteredMCMPHandler
 {
    static final Object[] NULL_ARGS = new Object[0];
    static final Class<?>[] NULL_TYPES = new Class[0];
@@ -206,24 +206,6 @@
       return this.localHandler.getConfiguration();
    }
 
-   public void addProxy(String address)
-   {
-      AddressPort ap = MCMPUtils.parseAddressPort(address);
-      this.addProxy(ap.address, ap.port);
-   }
-
-   public void addProxy(String host, int port)
-   {
-      InetAddress address = null;
-      try {
-         address = InetAddress.getByName(host);
-      } catch (Exception e) {
-         throw new IllegalArgumentException(e);
-      }
-      
-      this.addProxy(address, port);
-   }
-
    public synchronized void addProxy(InetAddress address, int port)
    {
       if (this.isMasterNode())
@@ -244,23 +226,6 @@
    /**
     * Remove proxy.
     */
-   public synchronized void removeProxy(String host, int port)
-   {
-      try
-      {
-         InetAddress address = InetAddress.getByName(host);
-         
-         this.removeProxy(address, port);
-      }
-      catch (Exception e)
-      {
-         throw new IllegalArgumentException(e);
-      }
-   }
-   
-   /**
-    * Remove proxy.
-    */
    public synchronized void removeProxy(InetAddress address, int port)
    {
       if (this.isMasterNode())
@@ -388,16 +353,6 @@
          this.validateResponse(response, true);
       }
    }
-
-   private void validateResponse(GroupRpcResponse response, boolean recordFailure)
-   {
-      if (response instanceof ThrowableGroupRpcResponse)
-      {
-         if (recordFailure) this.recordRequestFailure();
-         
-         throw ((ThrowableGroupRpcResponse) response).getValueAsRuntimeException();
-      }
-   }
    
    public void shutdown()
    {
@@ -411,6 +366,19 @@
    
    // ----------------------------------------------------------------  Private
    
+   private void validateResponse(GroupRpcResponse response, boolean recordFailure)
+   {
+      if (response instanceof ThrowableGroupRpcResponse)
+      {
+         if (recordFailure)
+         {
+            this.recordRequestFailure();
+         }
+         
+         throw ((ThrowableGroupRpcResponse) response).getValueAsRuntimeException();
+      }
+   }
+   
    private synchronized void sendDiscoveryEventToPartition(InetAddress address, int port, boolean addition)
    {
       AddressPort ap = new AddressPort(address, port);

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/AbstractMCMPHandler.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/AbstractMCMPHandler.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/AbstractMCMPHandler.java	2008-08-27 18:47:17 UTC (rev 77545)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.modcluster.mcmp;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * Abstract {@link MCMPHandler} that implements the trivial convenience methods.
+ * 
+ * @author Paul Ferraro
+ */
+public abstract class AbstractMCMPHandler implements MCMPHandler
+{
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.mcmp.MCMPHandler#addProxy(java.lang.String)
+    */
+   public void addProxy(String address)
+   {
+      AddressPort ap = MCMPUtils.parseAddressPort(address);
+      
+      this.addProxy(ap.address, ap.port);
+   }
+
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.mcmp.MCMPHandler#addProxy(java.lang.String, int)
+    */
+   public void addProxy(String host, int port)
+   {
+      try
+      {
+         InetAddress address = InetAddress.getByName(host);
+
+         this.addProxy(address, port);
+      }
+      catch (UnknownHostException e)
+      {
+         throw new IllegalArgumentException(e);
+      }
+   }
+
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.mcmp.MCMPHandler#removeProxy(java.lang.String, int)
+    */
+   public void removeProxy(String host, int port)
+   {
+      try
+      {
+         InetAddress address = InetAddress.getByName(host);
+
+         this.removeProxy(address, port);
+      }
+      catch (UnknownHostException e)
+      {
+         throw new IllegalArgumentException(e);
+      }
+   }
+}

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-08-27 18:25:50 UTC (rev 77544)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/mcmp/impl/DefaultMCMPHandler.java	2008-08-27 18:47:17 UTC (rev 77545)
@@ -46,6 +46,7 @@
 import org.jboss.logging.Logger;
 import org.jboss.web.tomcat.service.modcluster.Constants;
 import org.jboss.web.tomcat.service.modcluster.config.MCMPHandlerConfiguration;
+import org.jboss.web.tomcat.service.modcluster.mcmp.AbstractMCMPHandler;
 import org.jboss.web.tomcat.service.modcluster.mcmp.AddressPort;
 import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPHandler;
 import org.jboss.web.tomcat.service.modcluster.mcmp.MCMPRequest;
@@ -61,7 +62,7 @@
  * @author Brian Stansberry
  * @version $Revision$
  */
-public class DefaultMCMPHandler implements MCMPHandler
+public class DefaultMCMPHandler extends AbstractMCMPHandler
 {
    protected static Logger log = Logger.getLogger(DefaultMCMPHandler.class);
 
@@ -170,26 +171,6 @@
       this.init = false;
    }
 
-   public void addProxy(String address)
-   {
-      AddressPort ap = MCMPUtils.parseAddressPort(address);
-      this.addProxy(ap.address, ap.port);
-   }
-
-   public synchronized void addProxy(String host, int port)
-   {
-      try
-      {
-         InetAddress address = InetAddress.getByName(host);
-
-         this.addProxyInternal(address, port);
-      }
-      catch (Exception e)
-      {
-         throw new IllegalArgumentException(e);
-      }
-   }
-
    public synchronized void addProxy(InetAddress address, int port)
    {
       this.addProxyInternal(address, port);
@@ -197,22 +178,25 @@
 
    private synchronized Proxy addProxyInternal(InetAddress address, int port)
    {
-      for (Proxy candidate : this.proxies)
+      Proxy proxy = new Proxy(address, port, this.sslSocketFactory, this.config.getSocketTimeout());
+      
+      for (Proxy candidate: this.proxies)
       {
-         if (candidate.getAddress().equals(address) && candidate.getPort() == port) return candidate;
+         if (candidate.equals(proxy)) return candidate;
       }
-      for (Proxy candidate : this.addProxies)
+      for (Proxy candidate: this.addProxies)
       {
-         if (candidate.getAddress().equals(address) && candidate.getPort() == port) return candidate;
+         if (candidate.equals(proxy)) return candidate;
       }
-      for (Proxy candidate : this.removeProxies)
+      for (Proxy candidate: this.removeProxies)
       {
-         if (candidate.getAddress().equals(address) && candidate.getPort() == port) return candidate;
+         if (candidate.equals(proxy)) return candidate;
       }
 
-      Proxy proxy = new Proxy(address, port, this.sslSocketFactory, this.config.getSocketTimeout());
       proxy.setState(Proxy.State.ERROR);
+      
       this.addProxies.add(proxy);
+      
       return proxy;
    }
 
@@ -222,20 +206,6 @@
       proxy.setEstablished(established);
    }
 
-   public synchronized void removeProxy(String host, int port)
-   {
-      try
-      {
-         InetAddress address = InetAddress.getByName(host);
-         
-         this.removeProxy(address, port);
-      }
-      catch (Exception e)
-      {
-         throw new IllegalArgumentException(e);
-      }
-   }
-
    public synchronized void removeProxy(InetAddress address, int port)
    {
       Proxy proxy = new Proxy(address, port, this.sslSocketFactory, this.config.getSocketTimeout());
@@ -801,19 +771,14 @@
       }
 
       @Override
-      public boolean equals(Object o)
+      public boolean equals(Object object)
       {
-         if (o instanceof Proxy)
-         {
-            Proxy compare = (Proxy) o;
-            if (this.port != compare.port) return false;
-            if (compare.address == null)
-            {
-               if (this.address == null) return true;
-            }
-            else if ((compare.address.equals(this.address)) && this.port == compare.port) return true;
-         }
-         return false;
+         if (!(object instanceof Proxy)) return false;
+
+         Proxy proxy = (Proxy) object;
+         InetAddress address = proxy.address;
+         
+         return ((this.address != null) && (address != null) ? this.address.equals(address) : this.address == address) && (this.port == proxy.port);
       }
 
       @Override




More information about the jboss-cvs-commits mailing list