[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport/rmi ...

Ron Sigal ron_sigal at yahoo.com
Tue Jan 16 01:16:21 EST 2007


  User: rsigal  
  Date: 07/01/16 01:16:21

  Modified:    src/main/org/jboss/remoting/transport/rmi  Tag: remoting_2_x
                        RemotingRMIClientSocketFactory.java
  Log:
  JBREM-298, JBREM-670: (1) Refactored with SerializableSSLClientSocketFactory to allow storage of client side config parameters for RMI as well as SSLRMI; (2) removed equals() and hashCode(); (3) removed some unused constructors.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.9.4.1   +81 -144   JBossRemoting/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RemotingRMIClientSocketFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java,v
  retrieving revision 1.9
  retrieving revision 1.9.4.1
  diff -u -b -r1.9 -r1.9.4.1
  --- RemotingRMIClientSocketFactory.java	25 Jul 2006 19:52:21 -0000	1.9
  +++ RemotingRMIClientSocketFactory.java	16 Jan 2007 06:16:21 -0000	1.9.4.1
  @@ -22,13 +22,20 @@
   
   package org.jboss.remoting.transport.rmi;
   
  -import org.jboss.remoting.Version;
  -
  -import javax.net.SocketFactory;
   import java.io.IOException;
   import java.io.Serializable;
   import java.net.Socket;
   import java.rmi.server.RMIClientSocketFactory;
  +import java.util.HashMap;
  +import java.util.Map;
  +
  +import javax.net.SocketFactory;
  +
  +import org.jboss.logging.Logger;
  +import org.jboss.remoting.AbstractInvoker;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.Remoting;
  +import org.jboss.remoting.Version;
   
   
   /**
  @@ -57,7 +64,7 @@
    * with localhost will allow the retrieval of objects bound to localhost.
    *
    * @author <a href="mailto:r.sigal at computer.org">Ron Sigal</a>
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.9.4.1 $
    *          <p/>
    *          Copyright (c) 2005
    *          </p>
  @@ -67,6 +74,13 @@
   {
      static final long serialVersionUID;
   
  +   protected static Logger log = Logger.getLogger(RemotingRMIClientSocketFactory.class);
  +   protected static HashMap configMaps = new HashMap();
  +   protected static Map socketFactories = new HashMap();
  +
  +   protected Map configuration;
  +   protected InvokerLocator invokerLocator;
  +   
      transient protected SocketFactory socketFactory;
      private int timeout = 60000;
   
  @@ -85,8 +99,6 @@
   
      protected String hostName;
   
  -   private static int defaultHashCode = "RemotingRMISocketFactory".hashCode();
  -
      static
      {
         if(Version.getDefaultVersion() == Version.VERSION_1)
  @@ -99,48 +111,30 @@
         }
      }
   
  -   /**
  -    */
  -   public RemotingRMIClientSocketFactory()
  -   {
  -   }
  -
   
  -   /**
  -    * @param socketFactory the <code>SocketFactory</code> to be used to generate sockets
  -    */
  -   public RemotingRMIClientSocketFactory(SocketFactory socketFactory)
  +   public static void addLocalConfiguration(InvokerLocator invokerLocator, Map localConfig)
      {
  -      this.socketFactory = socketFactory;
  +      configMaps.put(new ComparableHolder(invokerLocator), localConfig);
      }
   
   
      /**
  -    * @param hostName name of host to which all generated sockets should be connected
  +    * @param locator
  +    * @param hostName
  +    * @param timeout
  +    * @param config
       */
  -   public RemotingRMIClientSocketFactory(String hostName, int timeout)
  +   public RemotingRMIClientSocketFactory(InvokerLocator locator,
  +                                         String hostName,
  +                                         int timeout,
  +                                         Map config)
      {
  +      this.invokerLocator = locator;
         this.hostName = hostName;
         this.timeout = timeout;
  +      this.configuration = new HashMap(config);
      }
   
  -   public RemotingRMIClientSocketFactory(SocketFactory socketFactory, String hostName, int timeout)
  -   {
  -      this.socketFactory = socketFactory;
  -      this.hostName = hostName;
  -      this.timeout = timeout;
  -   }
  -
  -
  -   /**
  -    * @param socketFactory the <code>SocketFactory</code> to be used to generate sockets
  -    * @param hostName      name of host to which all generated sockets should be connected
  -    */
  -   public RemotingRMIClientSocketFactory(SocketFactory socketFactory, String hostName)
  -   {
  -      this.hostName = hostName;
  -      this.socketFactory = socketFactory;
  -   }
   
   //   public RemotingRMISocketFactory(Constructor constructor, Object[] args, int hostPosition, int portPosition)
   //   throws ClassNotFoundException, NoSuchMethodException
  @@ -162,6 +156,13 @@
       */
      public Socket createSocket(String host, int port) throws IOException
      {
  +      // If invokerLocator isn't in configMaps, an SSLRMICLientInvoker has not been created
  +      // yet.  This call was probably made by an RMI thread, and is premature.
  +      ComparableHolder holder = new ComparableHolder(invokerLocator);
  +      if (!configMaps.containsKey(holder))
  +         return null;
  +      
  +      socketFactory = retrieveSocketFactory(holder);
         String effectiveHost = hostName != null ? hostName : host;
   
         Socket socket = null;
  @@ -194,137 +195,73 @@
         }
   
         socket.setSoTimeout(timeout);
  +      socketFactory = null;
         return socket;
      }
   
   
  -   /**
  -    * Overrides <code>equals()</code> method provided by <code>Object</code> class.  It looks for
  -    * equality of host name and socket factory parameters.
  -    *
  -    * @param o <code>Object</code> to which <code>this</code> is to be compared
  -    * @return true if and only if <code>o</code> and <code>this</code> are equal
  -    */
  -   public boolean equals(Object o)
  +   public SocketFactory retrieveSocketFactory(ComparableHolder holder)
  +      throws IOException
      {
  -      if(! (o instanceof RemotingRMIClientSocketFactory))
  +      SocketFactory sf = (SocketFactory) socketFactories.get(this);
  +      if (sf == null)
         {
  -         return false;
  -      }
  +         // We want to keep the local configuration map, which might contain a
  +         // SocketFactory, separate from the configuration map, which is meant
  +         // to contain only serializable objects.
  +         Map tempConfig = new HashMap(configuration);
  +         Map localConfig = (Map) configMaps.get(holder);
  +         if (localConfig != null)
  +            tempConfig.putAll(localConfig);
   
  -      RemotingRMIClientSocketFactory sf = (RemotingRMIClientSocketFactory) o;
  -
  -      // This is for the version that uses a SocketFactory
  -      if(socketFactory != null)
  -      {
  -         if(sf.socketFactory == null || ! socketFactory.equals(sf.socketFactory))
  +         if (tempConfig.containsKey(Remoting.CUSTOM_SOCKET_FACTORY))
            {
  -            return false;
  +            sf = (SocketFactory) tempConfig.get(Remoting.CUSTOM_SOCKET_FACTORY);
            }
   
  -         if(hostName != null)
  -         {
  -            if(sf.hostName == null || ! hostName.equals(sf.hostName))
  +         if (sf == null)
               {
  -               return false;
  -            }
  -            else
  -            {
  -               return true;
  -            }
  +            sf = SocketFactory.getDefault();
  +            sf = AbstractInvoker.wrapSocketFactory(sf, tempConfig);
            }
   
  -         if(sf.hostName != null)
  -         {
  -            return false;
  -         }
  -         else
  -         {
  -            return true;
  +         socketFactories.put(this, sf);
            }
  +
  +      return sf;
         }
   
  -//      // This is for the version that uses a constructor
  -//      if (constructor != null)
  -//      {
  -//         if (sf.constructor == null ||
  -//             ! constructor.equals(sf.constructor) ||
  -//             hostPosition != sf.hostPosition ||
  -//             portPosition != sf.portPosition)
  -//            return false;
  -//
  -//         for (int i = 0; i < args.length; i++)
  -//         {
  -//            if (!args[i].equals(sf.args[i]))
  -//               return false;
  -//         }
  -//
  -//         return true;
  -//      }
   
  -      // This is for the plain vanilla version.
  -      if(sf.socketFactory != null)
  +   protected static class ComparableHolder
         {
  -         return false;
  -      }
  +      private String protocol;
  +      private String host;
  +      private int port;
  +      private int hashCode;
   
  -      if(hostName != null)
  -      {
  -         if(sf.hostName == null || ! hostName.equals(sf.hostName))
  +      public ComparableHolder(InvokerLocator invokerLocator)
            {
  -            return false;
  -         }
  -         else
  -         {
  -            return true;
  -         }
  +         protocol = invokerLocator.getProtocol().toLowerCase();
  +         host = invokerLocator.getHost();
  +         port = invokerLocator.getPort();
  +         hashCode = protocol.hashCode() * host.hashCode() * port;
         }
   
  -      if(sf.hostName != null)
  +      public boolean equals(Object obj)
         {
  +         if (obj == null || !(obj instanceof ComparableHolder))
            return false;
  -      }
  -      else
  -      {
  -         return true;
  -      }
  -   }
   
  +         ComparableHolder holder = (ComparableHolder) obj;
   
  -   /**
  -    * Overrides <code>hashCode()</code> method provided by the <code>Object</code> class.
  -    *
  -    * @return a hashcode for <code>this</code>
  -    */
  -   public int hashCode()
  -   {
  -      if(socketFactory != null)
  -      {
  -         if(hostName != null)
  -         {
  -            return socketFactory.hashCode() * hostName.hashCode();
  -         }
  -         else
  -         {
  -            return socketFactory.hashCode();
  -         }
  +         return protocol.equals(holder.protocol.toLowerCase())
  +                && host.equals(holder.host)
  +                && port == holder.port;
         }
   
  -//      if (constructor != null)
  -//      {
  -//         int hash = hostPosition * portPosition;
  -//         
  -//         for (int i = 0; i < args.length; i++)
  -//            hash *= args[i].hashCode();
  -//         
  -//         return hash;
  -//      }
  -
  -      if(hostName != null)
  +      public int hashCode()
         {
  -         return hostName.hashCode();
  +         return hashCode;
         }
  -
  -      return defaultHashCode;
      }
   }
  \ No newline at end of file
  
  
  



More information about the jboss-cvs-commits mailing list