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()
Returns the address that the driver will use to connect to the node.
|
InetAddress |
getBroadcastAddress()
Returns the node broadcast address, if known.
|
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.
|
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.
|
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.
|
InetSocketAddress |
getSocketAddress()
Returns the address and port that the driver will use to connect to the node.
|
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.
|
String |
toString() |
void |
tryReconnectOnce()
Triggers an asynchronous reconnection attempt to this host.
|
public InetAddress getAddress()
This is a shortcut for getSocketAddress().getAddress()
.
getSocketAddress()
public InetSocketAddress getSocketAddress()
This is the node's broadcast RPC address, possibly translated if an AddressTranslator
has been configured for this cluster.
The broadcast RPC address is inferred from the following cassandra.yaml file settings:
rpc_address
, rpc_interface
or broadcast_rpc_address
native_transport_port
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 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–2019. All rights reserved.