~ubuntu-branches/ubuntu/wily/libjboss-remoting-java/wily

« back to all changes in this revision

Viewing changes to src/org/jboss/remoting/transport/socket/ServerAddress.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
* JBoss, Home of Professional Open Source
3
 
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
 
* by the @authors tag. See the copyright.txt in the distribution for a
5
 
* full listing of individual contributors.
6
 
*
7
 
* This is free software; you can redistribute it and/or modify it
8
 
* under the terms of the GNU Lesser General Public License as
9
 
* published by the Free Software Foundation; either version 2.1 of
10
 
* the License, or (at your option) any later version.
11
 
*
12
 
* This software is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
 
* Lesser General Public License for more details.
16
 
*
17
 
* You should have received a copy of the GNU Lesser General Public
18
 
* License along with this software; if not, write to the Free
19
 
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
 
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21
 
*/
22
 
 
23
 
package org.jboss.remoting.transport.socket;
24
 
 
25
 
import java.io.IOException;
26
 
import java.io.Serializable;
27
 
 
28
 
/**
29
 
 * This class encapsulates all the required information for a client to
30
 
 * establish a connection with the server.
31
 
 * <p/>
32
 
 * It also attempts to provide a fast hash() function since this object
33
 
 * is used as a key in a hashmap mainted by the ConnectionManager.
34
 
 *
35
 
 * @author <a href="mailto:hiram.chirino@jboss.org">Hiram Chirino</a>
36
 
 * @version $Revision: 3186 $
37
 
 */
38
 
public class ServerAddress implements Serializable
39
 
{
40
 
   /**
41
 
    * The serialVersionUID @since 1.1.4.1
42
 
    */
43
 
   private static final long serialVersionUID = -7206359745950445445L;
44
 
 
45
 
   /**
46
 
    * Address of host ot connect to
47
 
    */
48
 
   public String address;
49
 
 
50
 
   /**
51
 
    * Port the service is listening on
52
 
    */
53
 
   public int port;
54
 
 
55
 
   /**
56
 
    * If the TcpNoDelay option should be used on the socket.
57
 
    */
58
 
   public boolean enableTcpNoDelay = false;
59
 
 
60
 
   /**
61
 
    * Timeout of setSoTimeout
62
 
    */
63
 
   public int timeout = 60000;
64
 
   
65
 
   /**
66
 
    * Maximum size of connection pool
67
 
    */
68
 
   public int maxPoolSize;
69
 
 
70
 
   /**
71
 
    * This object is used as a key in a hashmap,
72
 
    * so we precompute the hascode for faster lookups.
73
 
    */
74
 
   private transient int hashCode;
75
 
 
76
 
   public ServerAddress(String address, int port,
77
 
                        boolean enableTcpNoDelay, int timeout,
78
 
                        int maxPoolSize)
79
 
   {
80
 
      this.address = address;
81
 
      this.port = port;
82
 
      this.enableTcpNoDelay = enableTcpNoDelay;
83
 
      this.hashCode = address.hashCode() + port;
84
 
      if (enableTcpNoDelay)
85
 
      {
86
 
         this.hashCode ++;
87
 
      }
88
 
      if(timeout >= 0)
89
 
      {
90
 
         this.timeout = timeout;
91
 
      }
92
 
      this.hashCode = 7 * this.hashCode + timeout;
93
 
      this.maxPoolSize = maxPoolSize;
94
 
      this.hashCode = 11 * this.hashCode + maxPoolSize;
95
 
   }
96
 
 
97
 
   public String toString()
98
 
   {
99
 
      return "ServerAddress[" + address + ":" + port +
100
 
         (enableTcpNoDelay ? ", enableTcpNoDelay" : ", NO enableTcpNoDelay") +
101
 
         " timeout " + timeout + " ms" + ", maxPoolSize=" + maxPoolSize + "]";
102
 
   }
103
 
 
104
 
   public boolean equals(Object obj)
105
 
   {
106
 
      try
107
 
      {
108
 
         // Compare this to obj
109
 
         ServerAddress o = (ServerAddress)obj;
110
 
 
111
 
         if (port != o.port)
112
 
         {
113
 
            return false;
114
 
         }
115
 
 
116
 
         if (!address.equals(o.address))
117
 
         {
118
 
            return false;
119
 
         }
120
 
 
121
 
         if (enableTcpNoDelay != o.enableTcpNoDelay)
122
 
         {
123
 
            return false;
124
 
         }
125
 
 
126
 
         if (timeout != o.timeout)
127
 
         {
128
 
            return false;
129
 
         }
130
 
         
131
 
         if (maxPoolSize != o.maxPoolSize)
132
 
         {
133
 
            return false;
134
 
         }
135
 
 
136
 
         return true;
137
 
      }
138
 
      catch (Throwable e)
139
 
      {
140
 
         return false;
141
 
      }
142
 
   }
143
 
 
144
 
   public int hashCode()
145
 
   {
146
 
      return hashCode;
147
 
   }
148
 
 
149
 
   /**
150
 
    * Create the transient hashCode
151
 
    *
152
 
    * @param in
153
 
    * @throws IOException
154
 
    * @throws ClassNotFoundException
155
 
    */
156
 
   private void readObject(java.io.ObjectInputStream in)
157
 
         throws IOException, ClassNotFoundException
158
 
   {
159
 
      // Trigger default serialization
160
 
      in.defaultReadObject();
161
 
      // Build the hashCode
162
 
      this.hashCode = address.hashCode() + port;
163
 
      if (enableTcpNoDelay)
164
 
      {
165
 
         this.hashCode ++;
166
 
      }
167
 
      this.hashCode = 7 * this.hashCode + timeout;
168
 
   }
169
 
 
170
 
 
171
 
}