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 (that is, the IP 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.
|
String |
getDseServerId()
Returns the value of the
server_id field in the peers system table for this node. |
VersionNumber |
getDseVersion()
The DSE version the host is running.
|
String |
getDseWorkload()
Deprecated.
This method returns only the first workload reported by the host;
use
getDseWorkloads() instead. |
Set<String> |
getDseWorkloads()
The DSE Workloads the host is running.
|
UUID |
getHostId()
Return the host id value for the host.
|
int |
getJmxPort()
Returns the JMX port used by this node.
|
InetAddress |
getListenAddress()
Returns the node listen address (that is, the IP the node uses to contact other peers in the cluster), if known.
|
int |
getNativeTransportPort()
Returns the port for the native transport connections on the DSE node.
|
int |
getNativeTransportPortSsl()
Returns the port for the encrypted native transport connections on the DSE node.
|
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.
|
int |
getStoragePort()
Returns the storage port used by the DSE node.
|
int |
getStoragePortSsl()
Returns the encrypted storage port used by the DSE node.
|
Set<Token> |
getTokens()
Returns the tokens that this host owns.
|
int |
hashCode() |
boolean |
isDseGraphEnabled()
Deprecated.
As of DSE 5.1, users should determine whether
this host has the graph workload enabled by inspecting the contents of
getDseWorkloads() instead. Note that this method will throw UnsupportedOperationException if the
system tables do not contain a "graph" column. |
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()
This corresponds to the broadcast_address
cassandra.yaml file setting and
is by default the same as getListenAddress()
, 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()
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.
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()
getDseWorkloads()
instead.
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 Set<String> getDseWorkloads()
This is based on the "workload" or "workloads" columns in system.local
and system.peers
.
Workload labels may vary depending on the DSE version in use;
e.g. DSE 5.1 may report two distinct workloads: Search
and
Analytics
, while DSE 5.0 would report a single
SearchAnalytics
workload instead.
It is up to users to deal with such discrepancies;
the driver simply returns the workload labels as reported by DSE, without
any form of pre-processing.
The returned set is immutable. It is also possible for this information to be unavailable. In that case this method returns an empty set, and the caller should always be aware of this possibility.
@Deprecated public boolean isDseGraphEnabled()
getDseWorkloads()
instead. Note that this method will throw UnsupportedOperationException
if the
system tables do not contain a "graph" column.
This is based on the "graph" column in system.local
and system.peers
.
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.
public String getDseServerId()
server_id
field in the peers
system table for this node.
The server_id
is the single identifier of the machine running a DSE instance.
If DSE has been configured with DSE Multi-Instance,
the server_id
helps identifying the single physical machine that runs the multiple
DSE instances. If DSE is not configured with DSE Multi-Instance, the server_id
will be automatically set and be unique for each host.
For more information on the server_id
see the documentation.
null
.public int getNativeTransportPort()
The native transport port is 9042
by default but can be changed on instances
requiring specific firewall configurations. This can be configured in the
cassandra.yaml
configuration file under the native_transport_port
property.
If a specific port is configured on a node, it will be exposed via this method.
null
.public int getNativeTransportPortSsl()
In most scenarios enabling client communications in DSE will result in using a single
port that will only accept encrypted connections (by default the port 9042
is reused since unencrypted connections are not allowed).
However, it is possible to configure DSE to use both encrypted and a non-encrypted
communication ports with clients. In that case the port accepting encrypted connections
will differ from the non-encrypted one (see getNativeTransportPort()
) and will be
exposed via this method.
null
.public int getStoragePort()
The storage port is used for internal communication between the DSE server nodes. This port is never used by the driver.
null
.public int getStoragePortSsl()
If inter-node encryption is enabled on the DSE cluster, nodes will communicate securely between each other via this port. This port is never used by the driver.
null
.public int getJmxPort()
The JMX port can be configured in the cassandra-env.sh
configuration file
separately on each node.
null
.Copyright © 2012–2018. All rights reserved.