public interface NodeStateListener extends AutoCloseable
An implementation of this interface can be registered in the configuration, or with
Note that the methods defined by this interface will be executed by internal driver threads, and are therefore expected to have short execution times. If you need to perform long computations or blocking calls in response to schema change events, it is strongly recommended to schedule them asynchronously on a separate thread provided by your application code.
If you implement this interface but don't need to implement all the methods, extend
|Modifier and Type||Method and Description|
Invoked when a node is first added to the cluster.
Invoked when a node leaves the cluster.
Invoked when the session is ready to process user requests.
Invoked when a node's state switches to
void onAdd(@NonNull Node node)
The node is not up yet at this point.
onUp(Node) will be notified later if the
driver successfully connects to the node (provided that a session is opened and the node is not
ignored), or receives a topology event for it.
This method is not invoked for the contact points provided at initialization. It is however for new nodes discovered during the full node list refresh after the first connection.
void onDown(@NonNull Node node)
void onRemove(@NonNull Node node)
This can be triggered by a topology event, or during a full node list refresh if the node is absent from the new list.
default void onSessionReady(@NonNull Session session)
This corresponds to the moment when
SessionBuilder.build() returns, or the future
SessionBuilder.buildAsync() completes. If the session initialization fails,
this method will not get called.
Listener methods are invoked from different threads; if you store the session in a field, make it at least volatile to guarantee proper publication.
Note that this method will not be the first one invoked on the listener; the driver emits node events before that, during the initialization of the session:
onDown(Node)is invoked; for the one that eventually succeeds,
onUp(Node)is invoked and that node becomes the control node (if none succeeds, the session initialization fails and the process stops here).
system.peerstable is inspected to discover the remaining nodes in the cluster. For any node that wasn't already a contact point,
onAdd(Node)is invoked; for any contact point that doesn't have a corresponding entry in the table,
onUp(Node)is invoked; otherwise,
onDown(Node)is invoked (no additional event is emitted for the control node, it is considered up since we already have a connection to it).
This method's default implementation is empty.
Copyright © 2017–2020. All rights reserved.