KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > mcast > InetServerAddress


1 package org.sapia.ubik.mcast;
2
3 import org.sapia.ubik.net.ServerAddress;
4
5 import java.net.InetAddress JavaDoc;
6
7
8 /**
9  * Implement a <code>ServerAddress</code> around a
10  * an <code>InetAddress</code> and a port.
11  *
12  * @author Yanick Duchesne
13  * <dl>
14  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
15  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
16  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
17  * </dl>
18  */

19 public class InetServerAddress implements ServerAddress {
20   private String JavaDoc _transportType = "udp/event/address";
21   private InetAddress JavaDoc _addr;
22   private int _port;
23   private int _hashCode;
24
25   /**
26    * Constructor for InetServerAddress.
27    *
28    * @param addr the <code>InetAddress</code> of the server
29    * to which this instance corresponds.
30    *
31    * @param port the port of the server
32    * to which this instance corresponds.
33    */

34   public InetServerAddress(InetAddress JavaDoc addr, int port) {
35     _addr = addr;
36     _port = port;
37     _hashCode = (addr.toString() + port).hashCode();
38   }
39
40   /**
41    * Returns this instance's <code>InetAddress</code>.
42    *
43    * @return an <code>InetAddess</code>.
44    */

45   public InetAddress JavaDoc getInetAddress() {
46     return _addr;
47   }
48
49   /**
50    * Returns this instance's port.
51    *
52    * @return a port.
53    */

54   public int getPort() {
55     return _port;
56   }
57
58   /**
59    * @see Object#equals(java.lang.Object)
60    */

61   public boolean equals(Object JavaDoc other) {
62     try {
63       InetServerAddress addr = (InetServerAddress) other;
64
65       return addr._addr.equals(_addr) && (addr._port == _port);
66     } catch (ClassCastException JavaDoc e) {
67       return false;
68     }
69   }
70
71   /**
72    * @see ServerAddress#getTransportType()
73    */

74   public String JavaDoc getTransportType() {
75     return _transportType;
76   }
77
78   /**
79    * @see Object#hashCode()
80    */

81   public int hashCode() {
82     return _hashCode;
83   }
84   
85   public String JavaDoc toString(){
86     return new StringBuffer JavaDoc("[")
87       .append("address=").append(_addr)
88       .append(" ,port=").append(_port)
89       .append("]").toString();
90   }
91 }
92
Popular Tags