public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent implements Transport
| Modifier and Type | Class and Description |
|---|---|
static class |
TcpTransport.HttpOnTransportException
A helper exception to mark an incoming connection as potentially being HTTP
so an appropriate error code can be returned
|
class |
TcpTransport.NodeChannels |
class |
TcpTransport.ScheduledPing |
Transport.ConnectionlifecycledeprecationLogger, logger, settingsTRANSPORT_TCP_COMPRESS| Constructor and Description |
|---|
TcpTransport(java.lang.String transportName,
Settings settings,
ThreadPool threadPool,
BigArrays bigArrays,
CircuitBreakerService circuitBreakerService,
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService) |
| Modifier and Type | Method and Description |
|---|---|
TransportAddress[] |
addressesFromString(java.lang.String address,
int perAddressLimit)
Returns an address from its string representation.
|
boolean |
addressSupported(java.lang.Class<? extends TransportAddress> address)
Is the address type supported.
|
protected abstract Channel |
bind(java.lang.String name,
java.net.InetSocketAddress address)
Binds to the given
InetSocketAddress |
protected void |
bindServer(java.lang.String name,
Settings settings) |
protected java.net.InetSocketAddress |
bindToPort(java.lang.String name,
java.net.InetAddress hostAddress,
java.lang.String port) |
BoundTransportAddress |
boundAddress()
The address the transport is bound on.
|
protected java.util.Map<java.lang.String,Settings> |
buildProfileSettings() |
boolean |
canCompress(TransportRequest request) |
protected abstract void |
closeChannels(java.util.List<Channel> channels,
boolean blocking)
Closes all channels in this list.
|
protected void |
closeChannelWhileHandlingExceptions(Channel channel)
Disconnects from a node if a channel is found as part of that nodes channels.
|
protected abstract TcpTransport.NodeChannels |
connectToChannels(DiscoveryNode node,
ConnectionProfile connectionProfile,
java.util.function.Consumer<Channel> onChannelClose)
Connect to the node with channels as defined by the specified connection profile.
|
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.
|
protected void |
doClose() |
protected void |
doStart() |
protected void |
doStop() |
protected void |
ensureOpen()
Ensures this transport is still started / open
|
protected Version |
executeHandshake(DiscoveryNode node,
Channel channel,
TimeValue timeout) |
TcpTransport.NodeChannels |
getConnection(DiscoveryNode node)
Returns a connection for the given node if the node is connected.
|
protected Version |
getCurrentVersion() |
CircuitBreaker |
getInFlightRequestBreaker() |
protected abstract java.net.InetSocketAddress |
getLocalAddress(Channel channel)
Returns the channels local address
|
java.util.List<java.lang.String> |
getLocalAddresses() |
protected java.lang.String |
handleRequest(Channel channel,
java.lang.String profileName,
StreamInput stream,
long requestId,
int messageLengthBytes,
Version version,
java.net.InetSocketAddress remoteAddress,
byte status) |
protected abstract boolean |
isOpen(Channel channel) |
void |
messageReceived(BytesReference reference,
Channel channel,
java.lang.String profileName,
java.net.InetSocketAddress remoteAddress,
int messageLengthBytes)
This method handles the message receive part for both request and responses
|
long |
newRequestId()
Returns a new request ID to use when sending a message via
Transport.Connection.sendRequest(long, String,
TransportRequest, TransportRequestOptions) |
boolean |
nodeConnected(DiscoveryNode node)
Returns true if the node is connected.
|
protected void |
onException(Channel channel,
java.lang.Exception e) |
TcpTransport.NodeChannels |
openConnection(DiscoveryNode node,
ConnectionProfile connectionProfile)
Opens a new connection to the given node and returns it.
|
java.util.Map<java.lang.String,BoundTransportAddress> |
profileBoundAddresses()
Further profile bound addresses
|
static int |
resolvePublishPort(java.lang.String profileName,
Settings settings,
Settings profileSettings,
java.util.List<java.net.InetSocketAddress> boundAddresses,
java.net.InetAddress publishInetAddress) |
void |
sendErrorResponse(Version nodeVersion,
Channel channel,
java.lang.Exception error,
long requestId,
java.lang.String action)
Sends back an error response to the caller via the given channel
|
protected abstract void |
sendMessage(Channel channel,
BytesReference reference,
ActionListener<Channel> listener)
Sends message to channel.
|
void |
sendResponse(Version nodeVersion,
Channel channel,
TransportResponse response,
long requestId,
java.lang.String action,
TransportResponseOptions options)
Sends the response to the given channel.
|
protected void |
stopInternal()
Called to tear down internal resources
|
void |
transportServiceAdapter(TransportServiceAdapter service) |
static boolean |
validateMessageHeader(BytesReference buffer)
Validates the first N bytes of the message header and returns
false if the message is
a ping message and has no payload ie. |
protected void |
validateRequest(StreamInput stream,
long requestId,
java.lang.String action) |
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stoplogDeprecatedSetting, logRemovedSetting, nodeNameclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitserverOpenaddLifecycleListener, lifecycleState, removeLifecycleListener, start, stopclosepublic static final java.lang.String TRANSPORT_SERVER_WORKER_THREAD_NAME_PREFIX
public static final java.lang.String TRANSPORT_SERVER_BOSS_THREAD_NAME_PREFIX
public static final java.lang.String TRANSPORT_CLIENT_WORKER_THREAD_NAME_PREFIX
public static final java.lang.String TRANSPORT_CLIENT_BOSS_THREAD_NAME_PREFIX
public static final Setting<java.lang.Integer> CONNECTIONS_PER_NODE_RECOVERY
public static final Setting<java.lang.Integer> CONNECTIONS_PER_NODE_BULK
public static final Setting<java.lang.Integer> CONNECTIONS_PER_NODE_REG
public static final Setting<java.lang.Integer> CONNECTIONS_PER_NODE_STATE
public static final Setting<java.lang.Integer> CONNECTIONS_PER_NODE_PING
public static final Setting<java.lang.Boolean> TCP_NO_DELAY
public static final Setting<java.lang.Boolean> TCP_KEEP_ALIVE
public static final Setting<java.lang.Boolean> TCP_REUSE_ADDRESS
public static final Setting<java.lang.Boolean> TCP_BLOCKING_CLIENT
public static final Setting<java.lang.Boolean> TCP_BLOCKING_SERVER
public static final Setting<ByteSizeValue> TCP_SEND_BUFFER_SIZE
public static final Setting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE
public static final int PING_DATA_SIZE
protected final boolean blockingClient
protected final TcpTransport.ScheduledPing scheduledPing
protected final ThreadPool threadPool
protected final NetworkService networkService
protected volatile TransportServiceAdapter transportServiceAdapter
protected final java.util.concurrent.ConcurrentMap<DiscoveryNode,TcpTransport.NodeChannels> connectedNodes
protected final java.util.Map<java.lang.String,java.util.List<Channel>> serverChannels
protected final java.util.concurrent.ConcurrentMap<java.lang.String,BoundTransportAddress> profileBoundAddresses
protected final KeyedLock<java.lang.String> connectionLock
protected final java.util.concurrent.locks.ReadWriteLock closeLock
protected final boolean compress
protected volatile BoundTransportAddress boundAddress
protected final ConnectionProfile defaultConnectionProfile
public TcpTransport(java.lang.String transportName,
Settings settings,
ThreadPool threadPool,
BigArrays bigArrays,
CircuitBreakerService circuitBreakerService,
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService)
protected void doStart()
doStart in class AbstractLifecycleComponentpublic CircuitBreaker getInFlightRequestBreaker()
getInFlightRequestBreaker in interface Transportpublic void transportServiceAdapter(TransportServiceAdapter service)
transportServiceAdapter in interface Transportpublic boolean nodeConnected(DiscoveryNode node)
TransportnodeConnected in interface Transportpublic void connectToNode(DiscoveryNode node, ConnectionProfile connectionProfile, CheckedBiConsumer<Transport.Connection,ConnectionProfile,java.io.IOException> connectionValidator) throws ConnectTransportException
TransportconnectToNode in interface TransportConnectTransportExceptionpublic final TcpTransport.NodeChannels openConnection(DiscoveryNode node, ConnectionProfile connectionProfile) throws java.io.IOException
TransportTransport.connectToNode(DiscoveryNode, ConnectionProfile, CheckedBiConsumer) the returned connection is not managed by
the transport implementation. This connection must be closed once it's not needed anymore.
This connection type can be used to execute a handshake between two nodes before the node will be published via
Transport.connectToNode(DiscoveryNode, ConnectionProfile, CheckedBiConsumer).openConnection in interface Transportjava.io.IOExceptionprotected final void closeChannelWhileHandlingExceptions(Channel channel)
public TcpTransport.NodeChannels getConnection(DiscoveryNode node)
TransportgetConnection in interface TransportTransport.connectToNode(DiscoveryNode, ConnectionProfile, CheckedBiConsumer)public void disconnectFromNode(DiscoveryNode node)
TransportdisconnectFromNode in interface Transportprotected Version getCurrentVersion()
public boolean addressSupported(java.lang.Class<? extends TransportAddress> address)
TransportaddressSupported in interface Transportpublic BoundTransportAddress boundAddress()
TransportboundAddress in interface Transportpublic java.util.Map<java.lang.String,BoundTransportAddress> profileBoundAddresses()
TransportprofileBoundAddresses in interface Transportnull iff profiles are unsupported, otherwise a map with name of profile and its bound transport addressprotected java.util.Map<java.lang.String,Settings> buildProfileSettings()
public java.util.List<java.lang.String> getLocalAddresses()
getLocalAddresses in interface Transportprotected void bindServer(java.lang.String name,
Settings settings)
protected java.net.InetSocketAddress bindToPort(java.lang.String name,
java.net.InetAddress hostAddress,
java.lang.String port)
public static int resolvePublishPort(java.lang.String profileName,
Settings settings,
Settings profileSettings,
java.util.List<java.net.InetSocketAddress> boundAddresses,
java.net.InetAddress publishInetAddress)
public TransportAddress[] addressesFromString(java.lang.String address, int perAddressLimit) throws java.net.UnknownHostException
TransportaddressesFromString in interface Transportjava.net.UnknownHostExceptionprotected final void doClose()
doClose in class AbstractLifecycleComponentprotected final void doStop()
doStop in class AbstractLifecycleComponentprotected void onException(Channel channel, java.lang.Exception e)
protected abstract java.net.InetSocketAddress getLocalAddress(Channel channel)
protected abstract Channel bind(java.lang.String name, java.net.InetSocketAddress address) throws java.io.IOException
InetSocketAddressname - the profile nameaddress - the address to bind tojava.io.IOExceptionprotected abstract void closeChannels(java.util.List<Channel> channels, boolean blocking) throws java.io.IOException
channels - the channels to closeblocking - whether the channels should be closed synchronouslyjava.io.IOExceptionprotected abstract void sendMessage(Channel channel, BytesReference reference, ActionListener<Channel> listener)
channel - the destination channelreference - the byte reference for the messagelistener - the listener to call when the operation has completedprotected abstract TcpTransport.NodeChannels connectToChannels(DiscoveryNode node, ConnectionProfile connectionProfile, java.util.function.Consumer<Channel> onChannelClose) throws java.io.IOException
node - the node to connect toconnectionProfile - the connection profileonChannelClose - callback to invoke when a channel is closedjava.io.IOException - if an I/O exception occurs while opening channelsprotected void stopInternal()
public boolean canCompress(TransportRequest request)
public void sendErrorResponse(Version nodeVersion, Channel channel, java.lang.Exception error, long requestId, java.lang.String action) throws java.io.IOException
nodeVersion - the caller node versionchannel - the channel to send the response toerror - the error to returnrequestId - the request ID this response replies toaction - the action this response replies tojava.io.IOExceptionpublic void sendResponse(Version nodeVersion, Channel channel, TransportResponse response, long requestId, java.lang.String action, TransportResponseOptions options) throws java.io.IOException
TransportResponse objects back to the caller.java.io.IOExceptionfor sending back errors to the callerpublic static boolean validateMessageHeader(BytesReference buffer) throws java.io.IOException
false if the message is
a ping message and has no payload ie. isn't a real user level message.java.lang.IllegalStateException - if the message is too short, less than the header or less that the header plus the message sizeTcpTransport.HttpOnTransportException - if the message has no valid header and appears to be a HTTP messagejava.lang.IllegalArgumentException - if the message is greater that the maximum allowed frame size. This is dependent on the available
memory.java.io.IOExceptionprotected abstract boolean isOpen(Channel channel)
public final void messageReceived(BytesReference reference, Channel channel, java.lang.String profileName, java.net.InetSocketAddress remoteAddress, int messageLengthBytes) throws java.io.IOException
java.io.IOExceptionprotected java.lang.String handleRequest(Channel channel, java.lang.String profileName, StreamInput stream, long requestId, int messageLengthBytes, Version version, java.net.InetSocketAddress remoteAddress, byte status) throws java.io.IOException
java.io.IOExceptionprotected void validateRequest(StreamInput stream, long requestId, java.lang.String action) throws java.io.IOException
java.io.IOExceptionprotected Version executeHandshake(DiscoveryNode node, Channel channel, TimeValue timeout) throws java.io.IOException, java.lang.InterruptedException
java.io.IOExceptionjava.lang.InterruptedExceptionpublic long newRequestId()
TransportTransport.Connection.sendRequest(long, String,
TransportRequest, TransportRequestOptions)newRequestId in interface Transportprotected final void ensureOpen()
java.lang.IllegalStateException - if the transport is not started / open