Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt 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.remoting.transport.socket;
 
This class encapsulates all the required information for a client to establish a connection with the server.

It also attempts to provide a fast hash() function since this object is used as a key in a hashmap mainted by the ConnectionManager.

Author(s):
Hiram Chirino
Version:
$Revision: 3186 $
 
 public class ServerAddress implements Serializable
 {
   
The serialVersionUID

Since:
1.1.4.1
 
    private static final long serialVersionUID = -7206359745950445445L;

   
Address of host ot connect to
 
    public String address;

   
Port the service is listening on
 
    public int port;

   
If the TcpNoDelay option should be used on the socket.
 
    public boolean enableTcpNoDelay = false;

   
Timeout of setSoTimeout
 
    public int timeout = 60000;
   
   
Maximum size of connection pool
 
    public int maxPoolSize;

   
This object is used as a key in a hashmap, so we precompute the hascode for faster lookups.
 
    private transient int hashCode;
 
    public ServerAddress(String addressint port,
                         boolean enableTcpNoDelayint timeout,
                         int maxPoolSize)
    {
       this. = address;
       this. = port;
       this. = enableTcpNoDelay;
       this. = address.hashCode() + port;
       if (enableTcpNoDelay)
       {
          this. ++;
       }
       if(timeout >= 0)
       {
          this. = timeout;
       }
       this. = 7 * this. + timeout;
       this. = maxPoolSize;
       this. = 11 * this. + maxPoolSize;
    }
 
    public String toString()
    {
       return "ServerAddress[" +  + ":" +  +
         ( ? ", enableTcpNoDelay" : ", NO enableTcpNoDelay") +
         " timeout " +  + " ms" + ", maxPoolSize=" +  + "]";
   }
   public boolean equals(Object obj)
   {
      try
      {
         // Compare this to obj
         ServerAddress o = (ServerAddress)obj;
         if ( != o.port)
         {
            return false;
         }
         if (!.equals(o.address))
         {
            return false;
         }
         if ( != o.enableTcpNoDelay)
         {
            return false;
         }
         if ( != o.timeout)
         {
            return false;
         }
         
         if ( != o.maxPoolSize)
         {
            return false;
         }
         return true;
      }
      catch (Throwable e)
      {
         return false;
      }
   }
   public int hashCode()
   {
      return ;
   }

   
Create the transient hashCode

   private void readObject(java.io.ObjectInputStream in)
         throws IOExceptionClassNotFoundException
   {
      // Trigger default serialization
      in.defaultReadObject();
      // Build the hashCode
      this. = .hashCode() + ;
      if ()
      {
         this. ++;
      }
      this. = 7 * this. + ;
   }
New to GrepCode? Check out our FAQ X