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.
|
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.
|
EndPoint |
getEndPoint()
Returns information to connect to the node.
|
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, 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.
|
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()
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.
|
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 EndPoint getEndPoint()
@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.
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–2019. All rights reserved.