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.
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.
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.
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.
23
package org.jboss.remoting.transport.socket;
25
import java.io.IOException;
26
import java.io.Serializable;
29
* This class encapsulates all the required information for a client to
30
* establish a connection with the server.
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.
35
* @author <a href="mailto:hiram.chirino@jboss.org">Hiram Chirino</a>
36
* @version $Revision: 3186 $
38
public class ServerAddress implements Serializable
41
* The serialVersionUID @since 1.1.4.1
43
private static final long serialVersionUID = -7206359745950445445L;
46
* Address of host ot connect to
48
public String address;
51
* Port the service is listening on
56
* If the TcpNoDelay option should be used on the socket.
58
public boolean enableTcpNoDelay = false;
61
* Timeout of setSoTimeout
63
public int timeout = 60000;
66
* Maximum size of connection pool
68
public int maxPoolSize;
71
* This object is used as a key in a hashmap,
72
* so we precompute the hascode for faster lookups.
74
private transient int hashCode;
76
public ServerAddress(String address, int port,
77
boolean enableTcpNoDelay, int timeout,
80
this.address = address;
82
this.enableTcpNoDelay = enableTcpNoDelay;
83
this.hashCode = address.hashCode() + port;
90
this.timeout = timeout;
92
this.hashCode = 7 * this.hashCode + timeout;
93
this.maxPoolSize = maxPoolSize;
94
this.hashCode = 11 * this.hashCode + maxPoolSize;
97
public String toString()
99
return "ServerAddress[" + address + ":" + port +
100
(enableTcpNoDelay ? ", enableTcpNoDelay" : ", NO enableTcpNoDelay") +
101
" timeout " + timeout + " ms" + ", maxPoolSize=" + maxPoolSize + "]";
104
public boolean equals(Object obj)
108
// Compare this to obj
109
ServerAddress o = (ServerAddress)obj;
116
if (!address.equals(o.address))
121
if (enableTcpNoDelay != o.enableTcpNoDelay)
126
if (timeout != o.timeout)
131
if (maxPoolSize != o.maxPoolSize)
144
public int hashCode()
150
* Create the transient hashCode
153
* @throws IOException
154
* @throws ClassNotFoundException
156
private void readObject(java.io.ObjectInputStream in)
157
throws IOException, ClassNotFoundException
159
// Trigger default serialization
160
in.defaultReadObject();
161
// Build the hashCode
162
this.hashCode = address.hashCode() + port;
163
if (enableTcpNoDelay)
167
this.hashCode = 7 * this.hashCode + timeout;