public class Host extends Object
This class keeps the information the driver maintain on a given Cassandra node.
Modifier and Type | Class and Description |
---|---|
static interface |
Host.LifecycleAwareStateListener
A
StateListener that tracks when it gets registered or unregistered with a cluster. |
static interface |
Host.StateListener
Interface for listeners that are interested in hosts added, up, down and removed events.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
InetAddress |
getAddress()
Deprecated.
This is exposed mainly for historical reasons. Internally, the driver uses
getEndPoint() to establish connections. This is a shortcut for getEndPoint().resolve().getAddress() . |
InetAddress |
getBroadcastAddress()
Returns the node broadcast address, if known.
|
InetSocketAddress |
getBroadcastRpcAddress()
Returns the broadcast RPC address, as reported by the node.
|
InetSocketAddress |
getBroadcastSocketAddress()
Returns the node broadcast address (that is, the address by which it should be contacted by
other peers in the cluster), if known.
|
VersionNumber |
getCassandraVersion()
The Cassandra version the host is running.
|
String |
getDatacenter()
Returns the name of the datacenter this host is part of.
|
VersionNumber |
getDseVersion()
Deprecated.
Please use the Java driver
for DSE if you are connecting to a DataStax Enterprise (DSE) cluster. This method might
not function properly with future versions of DSE.
|
String |
getDseWorkload()
Deprecated.
Please use the Java driver
for DSE if you are connecting to a DataStax Enterprise (DSE) cluster. This method might
not function properly with future versions of DSE.
|
EndPoint |
getEndPoint()
Returns information to connect to the node.
|
UUID |
getHostId()
Return the host id value for the host.
|
InetAddress |
getListenAddress()
Returns the node listen address, if known.
|
InetSocketAddress |
getListenSocketAddress()
Returns the node listen address (that is, the address the node uses to contact other peers in
the cluster), if known.
|
LwtInfo |
getLwtInfo() |
String |
getRack()
Returns the name of the rack this host is part of.
|
ListenableFuture<?> |
getReconnectionAttemptFuture()
Returns a
ListenableFuture representing the completion of the reconnection attempts
scheduled after a host is marked DOWN . |
UUID |
getSchemaVersion()
Return the current schema version for the host.
|
ShardingInfo |
getShardingInfo() |
InetSocketAddress |
getSocketAddress()
Deprecated.
This is exposed mainly for historical reasons. Internally, the driver uses
getEndPoint() to establish connections. This is a shortcut for getEndPoint().resolve() . |
String |
getState()
Returns a description of the host's state, as seen by the driver.
|
Set<Token> |
getTokens()
Returns the tokens that this host owns.
|
int |
hashCode() |
boolean |
isDseGraphEnabled()
Deprecated.
Please use the Java driver
for DSE if you are connecting to a DataStax Enterprise (DSE) cluster. This method might
not function properly with future versions of DSE.
|
boolean |
isUp()
Returns whether the host is considered up by the driver.
|
void |
setEndPoint(EndPoint endPoint) |
void |
setLwtInfo(LwtInfo lwtInfo) |
void |
setShardingInfo(ShardingInfo shardingInfo) |
String |
toString() |
void |
tryReconnectOnce()
Triggers an asynchronous reconnection attempt to this host.
|
public EndPoint getEndPoint()
public void setEndPoint(EndPoint endPoint)
@Deprecated public InetAddress getAddress()
getEndPoint()
to establish connections. This is a shortcut for getEndPoint().resolve().getAddress()
.@Deprecated public InetSocketAddress getSocketAddress()
getEndPoint()
to establish connections. This is a shortcut for getEndPoint().resolve()
.public InetSocketAddress getBroadcastRpcAddress()
This is address reported in system.peers.rpc_address
(Cassandra 3) or system.peers_v2.native_address/native_port
(Cassandra 4+).
Note that this is not necessarily the address that the driver will use to connect: if the
node is accessed through a proxy, a translation might be necessary; this is handled by getEndPoint()
.
For versions of Cassandra less than 2.0.16, 2.1.6 or 2.2.0-rc1, this will be null
for the control host. It will get updated if the control connection switches to another host.
public InetAddress getBroadcastAddress()
null
.
This is a shortcut for getBroadcastSocketAddress().getAddress()
.
null
.getBroadcastSocketAddress()
,
The
cassandra.yaml configuration filepublic InetSocketAddress getBroadcastSocketAddress()
null
.
Note that the port of the returned address will be 0 for versions of Cassandra older than 4.0.
This corresponds to the broadcast_address
cassandra.yaml file setting and is by
default the same as getListenSocketAddress()
, unless specified otherwise in
cassandra.yaml. This is NOT the address clients should use to contact this node.
This information is always available for peer hosts. For the control host, it's only available if CASSANDRA-9436 is fixed on the server side (Cassandra versions >= 2.0.16, 2.1.6, 2.2.0 rc1). For older versions, note that if the driver loses the control connection and reconnects to a different control host, the old control host becomes a peer, and therefore its broadcast address is updated.
null
.public InetAddress getListenAddress()
null
.
This is a shortcut for getListenSocketAddress().getAddress()
.
null
.getListenSocketAddress()
,
The
cassandra.yaml configuration filepublic InetSocketAddress getListenSocketAddress()
null
.
Note that the port of the returned address will be 0 for versions of Cassandra older than 4.0.
This corresponds to the listen_address
cassandra.yaml file setting. This is NOT
the address clients should use to contact this node.
This information is available for the control host if CASSANDRA-9603 is fixed on the server
side (Cassandra versions >= 2.0.17, 2.1.8, 2.2.0 rc2). It's currently not available for peer
hosts. Note that the current driver code already tries to read a listen_address
column
in system.peers
; when a future Cassandra version adds it, it will be picked by the
driver without any further change needed.
null
.public String getDatacenter()
The returned datacenter name is the one as known by Cassandra. It is also possible for this
information to be unavailable. In that case this method returns null
, and the caller
should always be aware of this possibility.
public String getRack()
The returned rack name is the one as known by Cassandra. It is also possible for this
information to be unavailable. In that case this method returns null
, and the caller
should always be aware of this possibility.
public VersionNumber getCassandraVersion()
It is also possible for this information to be unavailable. In that case this method returns
null
, and the caller should always be aware of this possibility.
@Deprecated public VersionNumber getDseVersion()
It is also possible for this information to be unavailable. In that case this method returns
null
, and the caller should always be aware of this possibility.
@Deprecated public String getDseWorkload()
It is also possible for this information to be unavailable. In that case this method returns
null
, and the caller should always be aware of this possibility.
@Deprecated public boolean isDseGraphEnabled()
public UUID getHostId()
The host id is the main identifier used by Cassandra on the server for internal
communication (gossip). It is referenced as the column host_id
in the system.local
or system.peers
table.
public UUID getSchemaVersion()
Schema versions in Cassandra are used to ensure all the nodes agree on the current Cassandra
schema when it is modified. For more information see ExecutionInfo.isSchemaInAgreement()
public Set<Token> getTokens()
public ShardingInfo getShardingInfo()
public void setShardingInfo(ShardingInfo shardingInfo)
public LwtInfo getLwtInfo()
public void setLwtInfo(LwtInfo lwtInfo)
public boolean isUp()
Please note that this is only the view of the driver and may not reflect reality. In
particular a node can be down but the driver hasn't detected it yet, or it can have been
restarted and the driver hasn't detected it yet (in particular, for hosts to which the driver
does not connect (because the LoadBalancingPolicy.distance
method says so), this
information may be durably inaccurate). This information should thus only be considered as best
effort and should not be relied upon too strongly.
public String getState()
This is exposed for debugging purposes only; the format of this string might change between driver versions, so clients should not make any assumptions about it.
public ListenableFuture<?> getReconnectionAttemptFuture()
ListenableFuture
representing the completion of the reconnection attempts
scheduled after a host is marked DOWN
.
If the caller cancels this future, the driver will not try to reconnect to this host
until it receives an UP event for it. Note that this could mean never, if the node was marked
down because of a driver-side error (e.g. read timeout) but no failure was detected by
Cassandra. The caller might decide to trigger an explicit reconnection attempt at a later point
with tryReconnectOnce()
.
null
if no reconnection attempt was in progress.public void tryReconnectOnce()
This method is intended for load balancing policies that mark hosts as IGNORED
, but still need a way to periodically check these hosts' states
(UP / DOWN).
For a host that is at distance IGNORED
, this method will try to reconnect exactly
once: if reconnection succeeds, the host is marked UP
; otherwise, no further attempts
will be scheduled. It has no effect if the node is already UP
, or if a reconnection
attempt is already in progress.
Note that if the host is not a distance IGNORED
, this method will
trigger a periodic reconnection attempt if the reconnection fails.
Copyright © 2012–2024. All rights reserved.