Package org.elasticsearch.transport
Interface TcpChannel
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
,Releasable
public interface TcpChannel extends Releasable
This is a tcp channel representing a single channel connection to another node. It is the base channel abstraction used by theTcpTransport
andTransportService
. All tcp transport implementations must return channels that adhere to the required method contracts.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addCloseListener(ActionListener<java.lang.Void> listener)
Adds a listener that will be executed when the channel is closed.static void
awaitConnected(DiscoveryNode discoveryNode, java.util.List<ActionFuture<java.lang.Void>> connectionFutures, TimeValue connectTimeout)
Awaits for all of the pending connections to complete.static void
blockOnFutures(java.util.List<ActionFuture<java.lang.Void>> futures)
void
close()
Closes the channel.static <C extends TcpChannel>
voidcloseChannel(C channel, boolean blocking)
Closes the channel.static <C extends TcpChannel>
voidcloseChannels(java.util.List<C> channels, boolean blocking)
Closes the channels.java.net.InetSocketAddress
getLocalAddress()
Returns the local address for this channel.boolean
isOpen()
Indicates whether a channel is currently openvoid
sendMessage(BytesReference reference, ActionListener<java.lang.Void> listener)
Sends a tcp message to the channel.void
setSoLinger(int value)
This sets the low level socket optionStandardSocketOptions
SO_LINGER on a channel.
-
-
-
Method Detail
-
close
void close()
Closes the channel. This might be an asynchronous process. There is notguarantee that the channel will be closed when this method returns. Use theaddCloseListener(ActionListener)
method to implement logic that depends on knowing when the channel is closed.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceReleasable
-
addCloseListener
void addCloseListener(ActionListener<java.lang.Void> listener)
Adds a listener that will be executed when the channel is closed. If the channel is still open when this listener is added, the listener will be executed by the thread that eventually closes the channel. If the channel is already closed when the listener is added the listener will immediately be executed by the thread that is attempting to add the listener.- Parameters:
listener
- to be executed
-
setSoLinger
void setSoLinger(int value) throws java.io.IOException
This sets the low level socket optionStandardSocketOptions
SO_LINGER on a channel.- Parameters:
value
- to set for SO_LINGER- Throws:
java.io.IOException
- that can be throw by the low level socket implementation
-
isOpen
boolean isOpen()
Indicates whether a channel is currently open- Returns:
- boolean indicating if channel is open
-
getLocalAddress
java.net.InetSocketAddress getLocalAddress()
Returns the local address for this channel.- Returns:
- the local address of this channel.
-
sendMessage
void sendMessage(BytesReference reference, ActionListener<java.lang.Void> listener)
Sends a tcp message to the channel. The listener will be executed once the send process has been completed.- Parameters:
reference
- to send to channellistener
- to execute upon send completion
-
closeChannel
static <C extends TcpChannel> void closeChannel(C channel, boolean blocking)
Closes the channel.- Parameters:
channel
- to closeblocking
- indicates if we should block on channel close
-
closeChannels
static <C extends TcpChannel> void closeChannels(java.util.List<C> channels, boolean blocking)
Closes the channels.- Parameters:
channels
- to closeblocking
- indicates if we should block on channel close
-
awaitConnected
static void awaitConnected(DiscoveryNode discoveryNode, java.util.List<ActionFuture<java.lang.Void>> connectionFutures, TimeValue connectTimeout) throws ConnectTransportException
Awaits for all of the pending connections to complete. Will throw an exception if at least one of the connections fails.- Parameters:
discoveryNode
- the node for the pending connectionsconnectionFutures
- representing the pending connectionsconnectTimeout
- to wait for a connection- Throws:
ConnectTransportException
- if one of the connections fails
-
blockOnFutures
static void blockOnFutures(java.util.List<ActionFuture<java.lang.Void>> futures)
-
-