Class Host
- java.lang.Object
-
- com.datastax.driver.core.Host
-
public class Host extends Object
A Cassandra node.This class keeps the information the driver maintain on a given Cassandra node.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceHost.LifecycleAwareStateListenerAStateListenerthat tracks when it gets registered or unregistered with a cluster.static interfaceHost.StateListenerInterface for listeners that are interested in hosts added, up, down and removed events.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(Object other)InetAddressgetAddress()Deprecated.This is exposed mainly for historical reasons.InetAddressgetBroadcastAddress()Returns the node broadcast address, if known.InetSocketAddressgetBroadcastRpcAddress()Returns the broadcast RPC address, as reported by the node.InetSocketAddressgetBroadcastSocketAddress()Returns the node broadcast address (that is, the address by which it should be contacted by other peers in the cluster), if known.VersionNumbergetCassandraVersion()The Cassandra version the host is running.StringgetDatacenter()Returns the name of the datacenter this host is part of.VersionNumbergetDseVersion()Deprecated.Please use the Java Driver for DSE if you are connecting to a DataStax Enterprise (DSE) cluster.StringgetDseWorkload()Deprecated.Please use the Java Driver for DSE if you are connecting to a DataStax Enterprise (DSE) cluster.EndPointgetEndPoint()Returns information to connect to the node.UUIDgetHostId()Return the host id value for the host.InetAddressgetListenAddress()Returns the node listen address, if known.InetSocketAddressgetListenSocketAddress()Returns the node listen address (that is, the address the node uses to contact other peers in the cluster), if known.LwtInfogetLwtInfo()ProtocolFeatureStoregetProtocolFeatureStore()StringgetRack()Returns the name of the rack this host is part of.ListenableFuture<?>getReconnectionAttemptFuture()Returns aListenableFuturerepresenting the completion of the reconnection attempts scheduled after a host is markedDOWN.UUIDgetSchemaVersion()Return the current schema version for the host.ShardingInfogetShardingInfo()InetSocketAddressgetSocketAddress()Deprecated.This is exposed mainly for historical reasons.StringgetState()Returns a description of the host's state, as seen by the driver.Set<Token>getTokens()Returns the tokens that this host owns.inthashCode()booleanisDseGraphEnabled()Deprecated.Please use the Java Driver for DSE if you are connecting to a DataStax Enterprise (DSE) cluster.booleanisUp()Returns whether the host is considered up by the driver.voidsetLwtInfo(LwtInfo lwtInfo)Deprecated.lwtInfo should not be manipulated.protected voidsetProtocolFeatureStore(ProtocolFeatureStore protocolFeatureStore)voidsetShardingInfo(ShardingInfo shardingInfo)Deprecated.shardingInfo should not be manipulated.StringtoString()voidtryReconnectOnce()Triggers an asynchronous reconnection attempt to this host.
-
-
-
Method Detail
-
getEndPoint
public EndPoint getEndPoint()
Returns information to connect to the node.
-
getAddress
@Deprecated public InetAddress getAddress()
Deprecated.This is exposed mainly for historical reasons. Internally, the driver usesgetEndPoint()to establish connections. This is a shortcut forgetEndPoint().resolve().getAddress().Returns the address that the driver will use to connect to the node.
-
getSocketAddress
@Deprecated public InetSocketAddress getSocketAddress()
Deprecated.This is exposed mainly for historical reasons. Internally, the driver usesgetEndPoint()to establish connections. This is a shortcut forgetEndPoint().resolve().Returns the address and port that the driver will use to connect to the node.- See Also:
- The cassandra.yaml configuration file
-
getBroadcastRpcAddress
public InetSocketAddress getBroadcastRpcAddress()
Returns the broadcast RPC address, as reported by the node.This is address reported in
system.peers.rpc_address(Cassandra 3) orsystem.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
nullfor the control host. It will get updated if the control connection switches to another host.
-
getBroadcastAddress
public InetAddress getBroadcastAddress()
Returns the node broadcast address, if known. Otherwisenull.This is a shortcut for
getBroadcastSocketAddress().getAddress().- Returns:
- the node broadcast address, if known. Otherwise
null. - See Also:
getBroadcastSocketAddress(), The cassandra.yaml configuration file
-
getBroadcastSocketAddress
public 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. Otherwisenull.Note that the port of the returned address will be 0 for versions of Cassandra older than 4.0.
This corresponds to the
broadcast_addresscassandra.yaml file setting and is by default the same asgetListenSocketAddress(), 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.
- Returns:
- the node broadcast address, if known. Otherwise
null. - See Also:
- The cassandra.yaml configuration file
-
getListenAddress
public InetAddress getListenAddress()
Returns the node listen address, if known. Otherwisenull.This is a shortcut for
getListenSocketAddress().getAddress().- Returns:
- the node listen address, if known. Otherwise
null. - See Also:
getListenSocketAddress(), The cassandra.yaml configuration file
-
getListenSocketAddress
public InetSocketAddress getListenSocketAddress()
Returns the node listen address (that is, the address the node uses to contact other peers in the cluster), if known. Otherwisenull.Note that the port of the returned address will be 0 for versions of Cassandra older than 4.0.
This corresponds to the
listen_addresscassandra.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_addresscolumn insystem.peers; when a future Cassandra version adds it, it will be picked by the driver without any further change needed.- Returns:
- the node listen address, if known. Otherwise
null. - See Also:
- The cassandra.yaml configuration file
-
getDatacenter
public String getDatacenter()
Returns the name of the datacenter this host is part of.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.- Returns:
- the Cassandra datacenter name or null if datacenter is unavailable.
-
getRack
public String getRack()
Returns the name of the rack this host is part of.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.- Returns:
- the Cassandra rack name or null if the rack is unavailable
-
getCassandraVersion
public VersionNumber getCassandraVersion()
The Cassandra version the host is running.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.- Returns:
- the Cassandra version the host is running.
-
getDseVersion
@Deprecated public 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.The DSE version the host is running.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.- Returns:
- the DSE version the host is running.
-
getDseWorkload
@Deprecated public 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.The DSE Workload the host is running.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.- Returns:
- the DSE workload the host is running.
-
isDseGraphEnabled
@Deprecated public 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.Returns whether the host is running DSE Graph.- Returns:
- whether the node is running DSE Graph.
-
getHostId
public UUID getHostId()
Return the host id value for the host.The host id is the main identifier used by Cassandra on the server for internal communication (gossip). It is referenced as the column
host_idin thesystem.localorsystem.peerstable.- Returns:
- the node's host id value.
-
getSchemaVersion
public UUID getSchemaVersion()
Return the current schema version for the host.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()- Returns:
- the node's current schema version value.
-
getTokens
public Set<Token> getTokens()
Returns the tokens that this host owns.- Returns:
- the (immutable) set of tokens.
-
getProtocolFeatureStore
public ProtocolFeatureStore getProtocolFeatureStore()
-
setProtocolFeatureStore
protected void setProtocolFeatureStore(ProtocolFeatureStore protocolFeatureStore)
-
getShardingInfo
public ShardingInfo getShardingInfo()
-
setShardingInfo
@Deprecated public void setShardingInfo(ShardingInfo shardingInfo)
Deprecated.shardingInfo should not be manipulated.Does nothing. shardingInfo should not be manipulated.- Parameters:
shardingInfo- aShardingInfoinstance.
-
getLwtInfo
public LwtInfo getLwtInfo()
-
setLwtInfo
@Deprecated public void setLwtInfo(LwtInfo lwtInfo)
Deprecated.lwtInfo should not be manipulated.Does nothing, lwtInfo should not be manipulated.- Parameters:
lwtInfo- aLwtInfoinstance.
-
isUp
public boolean isUp()
Returns whether the host is considered up by the driver.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.distancemethod 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.- Returns:
- whether the node is considered up.
-
getState
public String getState()
Returns a description of the host's state, as seen by the driver.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.
- Returns:
- a description of the host's state.
-
getReconnectionAttemptFuture
public ListenableFuture<?> getReconnectionAttemptFuture()
Returns aListenableFuturerepresenting the completion of the reconnection attempts scheduled after a host is markedDOWN.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().- Returns:
- the future, or
nullif no reconnection attempt was in progress.
-
tryReconnectOnce
public void tryReconnectOnce()
Triggers an asynchronous reconnection attempt to this host.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 markedUP; otherwise, no further attempts will be scheduled. It has no effect if the node is alreadyUP, 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.
-
-