@@ -44,12 +44,12 @@ public class Host {
4444 // We use that internally because
4545 // that's the 'peer' in the 'System.peers' table and avoids querying the full peers table in
4646 // ControlConnection.refreshNodeInfo.
47- private volatile InetAddress broadcastAddress ;
47+ private volatile InetSocketAddress broadcastSocketAddress ;
4848
4949 // The listen_address as known by Cassandra.
5050 // This is usually the same as broadcast_address unless
5151 // specified otherwise in cassandra.yaml file.
52- private volatile InetAddress listenAddress ;
52+ private volatile InetSocketAddress listenSocketAddress ;
5353
5454 private volatile UUID hostId ;
5555
@@ -118,12 +118,12 @@ void setVersion(String cassandraVersion) {
118118 this .cassandraVersion = versionNumber ;
119119 }
120120
121- void setBroadcastAddress ( InetAddress broadcastAddress ) {
122- this .broadcastAddress = broadcastAddress ;
121+ void setBroadcastSocketAddress ( InetSocketAddress broadcastAddress ) {
122+ this .broadcastSocketAddress = broadcastAddress ;
123123 }
124124
125- void setListenAddress ( InetAddress listenAddress ) {
126- this .listenAddress = listenAddress ;
125+ void setListenSocketAddress ( InetSocketAddress listenAddress ) {
126+ this .listenSocketAddress = listenAddress ;
127127 }
128128
129129 void setDseVersion (String dseVersion ) {
@@ -194,12 +194,30 @@ public InetSocketAddress getSocketAddress() {
194194 }
195195
196196 /**
197- * Returns the node broadcast address (that is, the IP by which it should be contacted by other
198- * peers in the cluster), if known.
197+ * Returns the node broadcast address, if known. Otherwise {@code null}.
198+ *
199+ * <p>This is a shortcut for {@code getBroadcastSocketAddress().getAddress()}.
200+ *
201+ * @return the node broadcast address, if known. Otherwise {@code null}.
202+ * @see #getBroadcastSocketAddress()
203+ * @see <a
204+ * href="https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html">The
205+ * cassandra.yaml configuration file</a>
206+ */
207+ public InetAddress getBroadcastAddress () {
208+ return broadcastSocketAddress != null ? broadcastSocketAddress .getAddress () : null ;
209+ }
210+
211+ /**
212+ * Returns the node broadcast address (that is, the address by which it should be contacted by
213+ * other peers in the cluster), if known. Otherwise {@code null}.
214+ *
215+ * <p>Note that the port of the returned address will be 0 for versions of Cassandra older than
216+ * 4.0.
199217 *
200218 * <p>This corresponds to the {@code broadcast_address} cassandra.yaml file setting and is by
201- * default the same as {@link #getListenAddress ()}, unless specified otherwise in cassandra.yaml.
202- * <em>This is NOT the address clients should use to contact this node</em>.
219+ * default the same as {@link #getListenSocketAddress ()}, unless specified otherwise in
220+ * cassandra.yaml. <em>This is NOT the address clients should use to contact this node</em>.
203221 *
204222 * <p>This information is always available for peer hosts. For the control host, it's only
205223 * available if CASSANDRA-9436 is fixed on the server side (Cassandra versions >= 2.0.16, 2.1.6,
@@ -212,13 +230,31 @@ public InetSocketAddress getSocketAddress() {
212230 * href="https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html">The
213231 * cassandra.yaml configuration file</a>
214232 */
215- public InetAddress getBroadcastAddress () {
216- return broadcastAddress ;
233+ public InetSocketAddress getBroadcastSocketAddress () {
234+ return broadcastSocketAddress ;
217235 }
218236
219237 /**
220- * Returns the node listen address (that is, the IP the node uses to contact other peers in the
221- * cluster), if known.
238+ * Returns the node listen address, if known. Otherwise {@code null}.
239+ *
240+ * <p>This is a shortcut for {@code getListenSocketAddress().getAddress()}.
241+ *
242+ * @return the node listen address, if known. Otherwise {@code null}.
243+ * @see #getListenSocketAddress()
244+ * @see <a
245+ * href="https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html">The
246+ * cassandra.yaml configuration file</a>
247+ */
248+ public InetAddress getListenAddress () {
249+ return listenSocketAddress != null ? listenSocketAddress .getAddress () : null ;
250+ }
251+
252+ /**
253+ * Returns the node listen address (that is, the address the node uses to contact other peers in
254+ * the cluster), if known. Otherwise {@code null}.
255+ *
256+ * <p>Note that the port of the returned address will be 0 for versions of Cassandra older than
257+ * 4.0.
222258 *
223259 * <p>This corresponds to the {@code listen_address} cassandra.yaml file setting. <em>This is NOT
224260 * the address clients should use to contact this node</em>.
@@ -234,8 +270,8 @@ public InetAddress getBroadcastAddress() {
234270 * href="https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html">The
235271 * cassandra.yaml configuration file</a>
236272 */
237- public InetAddress getListenAddress () {
238- return listenAddress ;
273+ public InetSocketAddress getListenSocketAddress () {
274+ return listenSocketAddress ;
239275 }
240276
241277 /**
0 commit comments