com.datastax.driver.core

## Class 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 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.
• ### Method Summary

All Methods
Modifier and Type Method and Description
boolean equals(Object other)
InetAddress getAddress()
VersionNumber getCassandraVersion()
The Cassandra version the host is running.
String getDatacenter()
Returns the name of the datacenter this host is part of.
ListenableFuture<?> getInitialReconnectionAttemptFuture()
Deprecated.
the suspicion mechanism has been disabled. This will always return a completed future.
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.
InetSocketAddress getSocketAddress()
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 isUp()
Returns whether the host is considered up by the driver.
String toString()
void tryReconnectOnce()
Triggers an asynchronous reconnection attempt to this host.
• ### Methods inherited from class java.lang.Object

clone, finalize, getClass, notify, notifyAll, wait, wait, wait
• ### Method Detail

public InetAddress getAddress()

This is a shortcut for getSocketAddress().getAddress().

Returns:
the node InetAddress.

public InetSocketAddress getSocketAddress()
Returns:
the node InetSocketAddress.
• #### 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 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.

As for other host information fetch from Cassandra above, the returned version can theoretically be null if the information is unavailable.

Returns:
the Cassandra version the host is running.
• #### getTokens

public Set<Token> getTokens()
Returns the tokens that this host owns.
Returns:
the (immutable) set of tokens.
• #### 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.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.

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.
• #### getInitialReconnectionAttemptFuture

@Deprecated
public ListenableFuture<?> getInitialReconnectionAttemptFuture()
Deprecated. the suspicion mechanism has been disabled. This will always return a completed future.
Returns a ListenableFuture representing the completion of the first reconnection attempt after a node has been suspected.

This is useful in load balancing policies when there are no more live nodes and we are trying suspected nodes.

Returns:
the future.
• #### getReconnectionAttemptFuture

public ListenableFuture<?> getReconnectionAttemptFuture()
Returns a 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().

Returns:
the future, or null if 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 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.

• #### equals

public boolean equals(Object other)
Overrides:
equals in class Object
• #### hashCode

public int hashCode()
Overrides:
hashCode in class Object
• #### toString

public String toString()
Overrides:
toString in class Object