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 theTcpTransportandTransportService. 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 voidaddCloseListener(ActionListener<java.lang.Void> listener)Adds a listener that will be executed when the channel is closed.static voidawaitConnected(DiscoveryNode discoveryNode, java.util.List<ActionFuture<java.lang.Void>> connectionFutures, TimeValue connectTimeout)Awaits for all of the pending connections to complete.static voidblockOnFutures(java.util.List<ActionFuture<java.lang.Void>> futures)voidclose()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.InetSocketAddressgetLocalAddress()Returns the local address for this channel.booleanisOpen()Indicates whether a channel is currently openvoidsendMessage(BytesReference reference, ActionListener<java.lang.Void> listener)Sends a tcp message to the channel.voidsetSoLinger(int value)This sets the low level socket optionStandardSocketOptionsSO_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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein 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.IOExceptionThis sets the low level socket optionStandardSocketOptionsSO_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)
-
-