Package org.elasticsearch.transport
Class ConnectionManager
- java.lang.Object
-
- org.elasticsearch.transport.ConnectionManager
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ConnectionManager extends java.lang.Object implements java.io.Closeable
This class manages node connections. The connection is opened by the underlying transport. Once the connection is opened, this class manages the connection. This includes keep-alive pings and closing the connection when the connection manager is closed.
-
-
Constructor Summary
Constructors Constructor Description ConnectionManager(Settings settings, Transport transport)
ConnectionManager(ConnectionProfile connectionProfile, Transport transport)
-
Method Summary
Modifier and Type Method Description void
addListener(TransportConnectionListener listener)
void
close()
void
connectToNode(DiscoveryNode node, ConnectionProfile connectionProfile, CheckedBiConsumer<Transport.Connection,ConnectionProfile,java.io.IOException> connectionValidator)
Connects to a node with the given connection profile.void
disconnectFromNode(DiscoveryNode node)
Disconnected from the given node, if not connected, will do nothing.Transport.Connection
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.Transport.Connection
openConnection(DiscoveryNode node, ConnectionProfile connectionProfile)
void
removeListener(TransportConnectionListener listener)
int
size()
Returns the number of nodes this manager is connected to.
-
-
-
Constructor Detail
-
ConnectionManager
public ConnectionManager(ConnectionProfile connectionProfile, Transport transport)
-
-
Method Detail
-
addListener
public void addListener(TransportConnectionListener listener)
-
removeListener
public void removeListener(TransportConnectionListener listener)
-
openConnection
public Transport.Connection openConnection(DiscoveryNode node, ConnectionProfile connectionProfile)
-
connectToNode
public void connectToNode(DiscoveryNode node, ConnectionProfile connectionProfile, CheckedBiConsumer<Transport.Connection,ConnectionProfile,java.io.IOException> connectionValidator) throws ConnectTransportException
Connects to a node with the given connection profile. If the node is already connected this method has no effect. Once a successful is established, it can be validated before being exposed.- Throws:
ConnectTransportException
-
getConnection
public Transport.Connection getConnection(DiscoveryNode node)
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- Throws:
NodeNotConnectedException
- if the node is not connected- See Also:
connectToNode(DiscoveryNode, ConnectionProfile, CheckedBiConsumer)
-
nodeConnected
public boolean nodeConnected(DiscoveryNode node)
Returnstrue
if the node is connected.
-
disconnectFromNode
public void disconnectFromNode(DiscoveryNode node)
Disconnected from the given node, if not connected, will do nothing.
-
size
public int size()
Returns the number of nodes this manager is connected to.
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-