KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > transport > socket > ServerAddress


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

9 package org.jboss.remoting.transport.socket;
10
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * This class encapsulates all the required information for a client to
15  * establish a connection with the server.
16  * <p/>
17  * It also attempts to provide a fast hash() function since this object
18  * is used as a key in a hashmap mainted by the ConnectionManager.
19  *
20  * @author <a HREF="mailto:hiram.chirino@jboss.org">Hiram Chirino</a>
21  * @version $Revision: 1.1.1.1 $
22  */

23 public class ServerAddress implements Serializable JavaDoc
24 {
25    /**
26     * The serialVersionUID @since 1.1.4.1
27     */

28    private static final long serialVersionUID = -7206359745950445445L;
29
30    /**
31     * Address of host ot connect to
32     */

33    public String JavaDoc address;
34
35    /**
36     * Port the service is listening on
37     */

38    public int port;
39
40    /**
41     * If the TcpNoDelay option should be used on the socket.
42     */

43    public boolean enableTcpNoDelay = false;
44
45    /**
46     * Timeout of setSoTimeout
47     */

48    public int timeout = 60000;
49
50    /**
51     * This object is used as a key in a hashmap,
52     * so we precompute the hascode for faster lookups.
53     */

54    private transient int hashCode;
55
56    public ServerAddress(String JavaDoc address, int port, boolean enableTcpNoDelay, int timeout)
57    {
58       this.address = address;
59       this.port = port;
60       this.enableTcpNoDelay = enableTcpNoDelay;
61       this.hashCode = address.hashCode() + port;
62       this.timeout = timeout;
63    }
64
65    public String JavaDoc toString()
66    {
67       return "[address:" + address + ",port:" + port + ",enableTcpNoDelay:" + enableTcpNoDelay + "]";
68    }
69
70    public boolean equals(Object JavaDoc obj)
71    {
72       try
73       {
74          ServerAddress o = (ServerAddress) obj;
75          if(o.hashCode != hashCode)
76          {
77             return false;
78          }
79          if(port != port)
80          {
81             return false;
82          }
83          if(!o.address.equals(address))
84          {
85             return false;
86          }
87          if(o.enableTcpNoDelay != enableTcpNoDelay)
88          {
89             return false;
90          }
91          return true;
92       }
93       catch(Throwable JavaDoc e)
94       {
95          return false;
96       }
97    }
98
99    public int hashCode()
100    {
101       return hashCode;
102    }
103
104 }
105
Popular Tags