Package org.elasticsearch.transport
Class ClusterConnectionManager
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
ConstructorDescriptionClusterConnectionManager
(Settings settings, Transport transport) ClusterConnectionManager
(ConnectionProfile connectionProfile, Transport transport) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(TransportConnectionListener listener) void
close()
void
void
connectToNode
(DiscoveryNode node, ConnectionProfile connectionProfile, ConnectionManager.ConnectionValidator connectionValidator, ActionListener<org.elasticsearch.core.Releasable> listener) Connects to the given node, or acquires another reference to an existing connection to the given node if a connection already exists.void
Disconnected 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.boolean
nodeConnected
(DiscoveryNode node) Returnstrue
if the node is connected.void
openConnection
(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) void
removeListener
(TransportConnectionListener listener) int
size()
Returns the number of nodes this manager is connected to.
-
Constructor Details
-
ClusterConnectionManager
-
ClusterConnectionManager
-
-
Method Details
-
addListener
- Specified by:
addListener
in interfaceConnectionManager
-
removeListener
- Specified by:
removeListener
in interfaceConnectionManager
-
openConnection
public void openConnection(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) - Specified by:
openConnection
in interfaceConnectionManager
-
connectToNode
public void connectToNode(DiscoveryNode node, @Nullable ConnectionProfile connectionProfile, ConnectionManager.ConnectionValidator connectionValidator, ActionListener<org.elasticsearch.core.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:
connectToNode
in interfaceConnectionManager
- Parameters:
connectionProfile
- the profile to use if opening a new connection. Only used in tests, this isnull
in 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.ConnectionValidator
will complete the listener on the generic thread pool (seeTransportService.connectionValidator(org.elasticsearch.cluster.node.DiscoveryNode)
). If successful, completed with aReleasable
which 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:
getConnection
in interfaceConnectionManager
- Throws:
NodeNotConnectedException
- if the node is not connected- See Also:
-
nodeConnected
Returnstrue
if the node is connected.- Specified by:
nodeConnected
in interfaceConnectionManager
-
disconnectFromNode
Disconnected from the given node, if not connected, will do nothing.- Specified by:
disconnectFromNode
in interfaceConnectionManager
-
size
public int size()Returns the number of nodes this manager is connected to.- Specified by:
size
in interfaceConnectionManager
-
getAllConnectedNodes
- Specified by:
getAllConnectedNodes
in interfaceConnectionManager
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceConnectionManager
-
closeNoBlock
public void closeNoBlock()- Specified by:
closeNoBlock
in interfaceConnectionManager
-
getConnectionProfile
- Specified by:
getConnectionProfile
in interfaceConnectionManager
-