java.lang.Object
org.elasticsearch.transport.ClusterConnectionManager
- All Implemented Interfaces:
Closeable,AutoCloseable,ConnectionManager
This class manages node connections within a cluster. The connection is opened by the underlying transport.
Once the connection is opened, this class manages the connection. This includes closing the connection when
the connection manager is closed.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.transport.ConnectionManager
ConnectionManager.ConnectionValidator, ConnectionManager.DelegatingNodeConnectionListener -
Constructor Summary
ConstructorsConstructorDescriptionClusterConnectionManager(Settings settings, Transport transport, ThreadContext threadContext) ClusterConnectionManager(ConnectionProfile connectionProfile, Transport transport, ThreadContext threadContext) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(TransportConnectionListener listener) voidclose()voidvoidconnectToNode(DiscoveryNode node, ConnectionProfile connectionProfile, ConnectionManager.ConnectionValidator connectionValidator, ActionListener<Releasable> listener) Connects to the given node, or acquires another reference to an existing connection to the given node if a connection already exists.voidDisconnected from the given node, if not connected, will do nothing.getConnection(DiscoveryNode node) Returns a connection for the given node if the node is connected.booleannodeConnected(DiscoveryNode node) Returnstrueif the node is connected.voidopenConnection(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) voidremoveListener(TransportConnectionListener listener) intsize()Returns the number of nodes this manager is connected to.
-
Constructor Details
-
ClusterConnectionManager
public ClusterConnectionManager(Settings settings, Transport transport, ThreadContext threadContext) -
ClusterConnectionManager
public ClusterConnectionManager(ConnectionProfile connectionProfile, Transport transport, ThreadContext threadContext)
-
-
Method Details
-
addListener
- Specified by:
addListenerin interfaceConnectionManager
-
removeListener
- Specified by:
removeListenerin interfaceConnectionManager
-
openConnection
public void openConnection(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) - Specified by:
openConnectionin interfaceConnectionManager
-
connectToNode
public void connectToNode(DiscoveryNode node, @Nullable ConnectionProfile connectionProfile, ConnectionManager.ConnectionValidator connectionValidator, ActionListener<Releasable> listener) throws ConnectTransportException Connects to the given node, or acquires another reference to an existing connection to the given node if a connection already exists.- Specified by:
connectToNodein interfaceConnectionManager- Parameters:
connectionProfile- the profile to use if opening a new connection. Only used in tests, this isnullin production.connectionValidator- a callback to validate the connection before it is exposed (e.g. tonodeConnected(org.elasticsearch.cluster.node.DiscoveryNode)).listener- completed on the calling thread or by theConnectionManager.ConnectionValidator; in production theConnectionManager.ConnectionValidatorwill complete the listener on the generic thread pool (seeTransportService.connectionValidator(org.elasticsearch.cluster.node.DiscoveryNode)). If successful, completed with aReleasablewhich will release this connection (and close it if no other references to it are held).- Throws:
ConnectTransportException
-
getConnection
Returns a connection for the given node if the node is connected. Connections returned from this method must not be closed. The lifecycle of this connection is maintained by this connection manager- Specified by:
getConnectionin interfaceConnectionManager- Throws:
NodeNotConnectedException- if the node is not connected- See Also:
-
nodeConnected
Returnstrueif the node is connected.- Specified by:
nodeConnectedin interfaceConnectionManager
-
disconnectFromNode
Disconnected from the given node, if not connected, will do nothing.- Specified by:
disconnectFromNodein interfaceConnectionManager
-
size
public int size()Returns the number of nodes this manager is connected to.- Specified by:
sizein interfaceConnectionManager
-
getAllConnectedNodes
- Specified by:
getAllConnectedNodesin interfaceConnectionManager
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceConnectionManager
-
closeNoBlock
public void closeNoBlock()- Specified by:
closeNoBlockin interfaceConnectionManager
-
getConnectionProfile
- Specified by:
getConnectionProfilein interfaceConnectionManager
-