public interface Node
This object is mutable, all of its properties may be updated at runtime to reflect the latest state of the node.
Note that the default implementation returned by the driver uses reference equality. A
Session
will always return the same instance for a given host id
.
However, instances coming from different sessions will not be equal, even if they refer to the
same host id.
Modifier and Type | Method and Description |
---|---|
Optional<InetSocketAddress> |
getBroadcastAddress()
The node's broadcast address.
|
Optional<InetSocketAddress> |
getBroadcastRpcAddress()
The node's broadcast RPC address.
|
Version |
getCassandraVersion()
The Cassandra version of the server.
|
String |
getDatacenter()
The datacenter that this node belongs to (according to the server-side snitch).
|
NodeDistance |
getDistance()
The distance assigned to this node by the
LoadBalancingPolicy , that controls certain
aspects of connection management. |
EndPoint |
getEndPoint()
The information that the driver uses to connect to the node.
|
Map<String,Object> |
getExtras()
An additional map of free-form properties.
|
UUID |
getHostId()
The host ID that is assigned to this node by Cassandra.
|
Optional<InetSocketAddress> |
getListenAddress()
The node's listen address.
|
int |
getOpenConnections()
The total number of active connections currently open by this driver instance to the node.
|
String |
getRack()
The rack that this node belongs to (according to the server-side snitch).
|
UUID |
getSchemaVersion()
The current version that is associated with the node's schema.
|
NodeState |
getState() |
long |
getUpSinceMillis()
The last time that this node transitioned to the UP state, in milliseconds since the epoch, or
-1 if it's not up at the moment.
|
boolean |
isReconnecting()
Whether the driver is currently trying to reconnect to this node.
|
@NonNull EndPoint getEndPoint()
In default deployments, the endpoint address is usually derived from the node's broadcast RPC address for peers hosts. For the control host however, the driver doesn't rely on that value because it may be wrong (see CASSANDRA-11181); instead, it simply uses the control connection's own endpoint.
When behind a proxy, the endpoint reported here usually refers to the proxy itself, and is unrelated to the node's broadcast RPC address.
@NonNull Optional<InetSocketAddress> getBroadcastRpcAddress()
This is computed from values reported in system.local.rpc_address
and system.peers.rpc_address
(Cassandra 3), or system.local.rpc_address
, system.local.rpc_port
, system.peers_v2.native_address
and system.peers_v2.native_port
(Cassandra 4+).
However, the address reported here might not be what the driver uses directly; to know which
address the driver is really using to connect to this node, check getEndPoint()
.
This may not be known at all times. In particular, some Cassandra versions (less than
2.0.16, 2.1.6 or 2.2.0-rc1) don't store it in the system.local
table, so this will be
unknown for the control node, until the control connection reconnects to another node.
@NonNull Optional<InetSocketAddress> getBroadcastAddress()
This is computed from values reported in system.local.broadcast_address
and system.peers.peer
(Cassandra 3), or system.local.broadcast_address
, system.local.broadcast_port
, system.peers_v2.peer
and system.peers_v2.peer_port
(Cassandra 4+). If the port is set to 0 it is unknown.
This may not be known at all times. In particular, some Cassandra versions (less than
2.0.16, 2.1.6 or 2.2.0-rc1) don't store it in the system.local
table, so this will be
unknown for the control node, until the control connection reconnects to another node.
@NonNull Optional<InetSocketAddress> getListenAddress()
This is computed from values reported in system.local.listen_address
(Cassandra 3),
or system.local.listen_address
and system.local.listen_port
(Cassandra 4+). If
the port is set to 0 it is unknown.
This may not be known at all times. In particular, current Cassandra versions (up to 3.11)
only store it in system.local
, so this will be known only for the control node.
@Nullable String getDatacenter()
This should be non-null in a healthy deployment, but the driver will still function, and
report null
here, if the server metadata was corrupted.
@Nullable String getRack()
This should be non-null in a healthy deployment, but the driver will still function, and
report null
here, if the server metadata was corrupted.
@Nullable Version getCassandraVersion()
This should be non-null in a healthy deployment, but the driver will still function, and
report null
here, if the server metadata was corrupted or the reported version could
not be parsed.
@NonNull Map<String,Object> getExtras()
This is intended for future evolution or custom driver extensions. The contents of this map are unspecified and may change at any point in time, always check for the existence of a key before using it.
Note that the returned map is immutable: if the properties change, this is reflected by publishing a new map instance, therefore you must call this method again to see the changes.
@NonNull NodeState getState()
long getUpSinceMillis()
int getOpenConnections()
boolean isReconnecting()
@NonNull NodeDistance getDistance()
LoadBalancingPolicy
, that controls certain
aspects of connection management.
This is exposed here for information only. Distance events are handled internally by the driver.
@Nullable UUID getHostId()
This information is always present once the session has initialized. However, there is a
narrow corner case where a driver client can observe a null value: if a NodeStateListener
is registered, the very first onUp
call will reference a node
that has a null id (that node is the initial contact point, and the driver hasn't read host ids
from system.local
and system.peers
yet). Beyond that point — including
any other onUp
call — the host id will always be present.
CqlSession session = CqlSession.builder() .withNodeStateListener( new NodeStateListenerBase() { @Override public void onUp(@NonNull Node node) { // node.getHostId() == null for the first invocation only } }) .build();
@Nullable UUID getSchemaVersion()
This should be non-null in a healthy deployment, but the driver will still function, and
report null
here, if the server metadata was corrupted.
Copyright © 2017–2024. All rights reserved.