java.io.Closeable
, java.lang.AutoCloseable
, LifecycleComponent
, Releasable
, Transport
public abstract class TcpTransport extends AbstractLifecycleComponent implements Transport
Modifier and Type | Class | 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 |
|
static class |
TcpTransport.ProfileSettings |
Representation of a transport profile settings for a transport.profiles.$profilename.*
|
class |
TcpTransport.ScheduledPing |
Transport.Connection
deprecationLogger, logger, settings
lifecycle
TRANSPORT_TCP_COMPRESS
Constructor | Description |
---|---|
TcpTransport(java.lang.String transportName,
Settings settings,
ThreadPool threadPool,
BigArrays bigArrays,
CircuitBreakerService circuitBreakerService,
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService) |
Modifier and Type | Method | Description |
---|---|---|
TransportAddress[] |
addressesFromString(java.lang.String address,
int perAddressLimit) |
Returns an address from its string representation.
|
protected abstract TcpChannel |
bind(java.lang.String name,
java.net.InetSocketAddress address) |
Binds to the given
InetSocketAddress |
protected void |
bindServer(TcpTransport.ProfileSettings profileSettings) |
|
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.
|
boolean |
canCompress(TransportRequest request) |
|
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,
TcpChannel 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() |
|
java.util.List<java.lang.String> |
getLocalAddresses() |
|
static java.util.Set<TcpTransport.ProfileSettings> |
getProfileSettings(Settings settings) |
Returns all profile settings for the given settings object
|
TransportStats |
getStats() |
|
protected java.lang.String |
handleRequest(TcpChannel channel,
java.lang.String profileName,
StreamInput stream,
long requestId,
int messageLengthBytes,
Version version,
java.net.InetSocketAddress remoteAddress,
byte status) |
|
protected abstract TcpChannel |
initiateChannel(DiscoveryNode node,
TimeValue connectTimeout,
ActionListener<java.lang.Void> connectListener) |
Initiate a single tcp socket channel to a node.
|
void |
messageReceived(BytesReference reference,
TcpChannel 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(TcpChannel 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
|
protected ConnectionProfile |
resolveConnectionProfile(ConnectionProfile connectionProfile) |
|
static int |
resolvePublishPort(TcpTransport.ProfileSettings profileSettings,
java.util.List<java.net.InetSocketAddress> boundAddresses,
java.net.InetAddress publishInetAddress) |
|
void |
sendErrorResponse(Version nodeVersion,
java.util.Set<java.lang.String> features,
TcpChannel channel,
java.lang.Exception error,
long requestId,
java.lang.String action) |
Sends back an error response to the caller via the given channel
|
void |
sendResponse(Version nodeVersion,
java.util.Set<java.lang.String> features,
TcpChannel channel,
TransportResponse response,
long requestId,
java.lang.String action,
TransportResponseOptions options) |
Sends the response to the given channel.
|
protected void |
serverAcceptedChannel(TcpChannel channel) |
|
void |
setTransportService(TransportService service) |
|
protected void |
stopInternal() |
Called to tear down internal resources
|
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) |
logDeprecatedSetting, logRemovedSetting, nodeName
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stop
addLifecycleListener, lifecycleState, removeLifecycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public static final java.lang.String TRANSPORT_SERVER_WORKER_THREAD_NAME_PREFIX
public static final java.lang.String TRANSPORT_CLIENT_BOSS_THREAD_NAME_PREFIX
public static final Setting<java.util.List<java.lang.String>> HOST
public static final Setting<java.util.List<java.lang.String>> BIND_HOST
public static final Setting<java.util.List<java.lang.String>> PUBLISH_HOST
public static final Setting<java.lang.String> PORT
public static final Setting<java.lang.Integer> PUBLISH_PORT
public static final java.lang.String DEFAULT_PROFILE
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<ByteSizeValue> TCP_SEND_BUFFER_SIZE
public static final Setting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE
public static final Setting.AffixSetting<java.lang.Boolean> TCP_NO_DELAY_PROFILE
public static final Setting.AffixSetting<java.lang.Boolean> TCP_KEEP_ALIVE_PROFILE
public static final Setting.AffixSetting<java.lang.Boolean> TCP_REUSE_ADDRESS_PROFILE
public static final Setting.AffixSetting<ByteSizeValue> TCP_SEND_BUFFER_SIZE_PROFILE
public static final Setting.AffixSetting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE_PROFILE
public static final Setting.AffixSetting<java.util.List<java.lang.String>> BIND_HOST_PROFILE
public static final Setting.AffixSetting<java.util.List<java.lang.String>> PUBLISH_HOST_PROFILE
public static final Setting.AffixSetting<java.lang.String> PORT_PROFILE
public static final Setting.AffixSetting<java.lang.Integer> PUBLISH_PORT_PROFILE
public static final int PING_DATA_SIZE
public static final java.lang.String FEATURE_PREFIX
protected final TcpTransport.ScheduledPing scheduledPing
protected final ThreadPool threadPool
protected final NetworkService networkService
protected final java.util.Set<TcpTransport.ProfileSettings> profileSettings
protected final boolean compress
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 AbstractLifecycleComponent
public CircuitBreaker getInFlightRequestBreaker()
getInFlightRequestBreaker
in interface Transport
public void setTransportService(TransportService service)
setTransportService
in interface Transport
public boolean nodeConnected(DiscoveryNode node)
Transport
nodeConnected
in interface Transport
public void connectToNode(DiscoveryNode node, ConnectionProfile connectionProfile, CheckedBiConsumer<Transport.Connection,ConnectionProfile,java.io.IOException> connectionValidator) throws ConnectTransportException
Transport
connectToNode
in interface Transport
ConnectTransportException
protected ConnectionProfile resolveConnectionProfile(ConnectionProfile connectionProfile)
public final TcpTransport.NodeChannels openConnection(DiscoveryNode node, ConnectionProfile connectionProfile)
Transport
Transport.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 Transport
public TcpTransport.NodeChannels getConnection(DiscoveryNode node)
Transport
getConnection
in interface Transport
Transport.connectToNode(DiscoveryNode, ConnectionProfile, CheckedBiConsumer)
public void disconnectFromNode(DiscoveryNode node)
Transport
disconnectFromNode
in interface Transport
protected Version getCurrentVersion()
public BoundTransportAddress boundAddress()
Transport
boundAddress
in interface Transport
public java.util.Map<java.lang.String,BoundTransportAddress> profileBoundAddresses()
Transport
profileBoundAddresses
in interface Transport
null
iff profiles are unsupported, otherwise a map with name of profile and its bound transport addresspublic java.util.List<java.lang.String> getLocalAddresses()
getLocalAddresses
in interface Transport
protected void bindServer(TcpTransport.ProfileSettings profileSettings)
protected java.net.InetSocketAddress bindToPort(java.lang.String name, java.net.InetAddress hostAddress, java.lang.String port)
public static int resolvePublishPort(TcpTransport.ProfileSettings 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
Transport
addressesFromString
in interface Transport
java.net.UnknownHostException
protected final void doClose()
doClose
in class AbstractLifecycleComponent
protected final void doStop()
doStop
in class AbstractLifecycleComponent
protected void onException(TcpChannel channel, java.lang.Exception e)
protected void serverAcceptedChannel(TcpChannel channel)
protected abstract TcpChannel bind(java.lang.String name, java.net.InetSocketAddress address) throws java.io.IOException
InetSocketAddress
name
- the profile nameaddress
- the address to bind tojava.io.IOException
protected abstract TcpChannel initiateChannel(DiscoveryNode node, TimeValue connectTimeout, ActionListener<java.lang.Void> connectListener) throws java.io.IOException
node
- the nodeconnectTimeout
- the connection timeoutconnectListener
- listener to be called when connection completejava.io.IOException
- if an I/O exception occurs while opening the channelprotected void stopInternal()
public boolean canCompress(TransportRequest request)
public void sendErrorResponse(Version nodeVersion, java.util.Set<java.lang.String> features, TcpChannel channel, java.lang.Exception error, long requestId, java.lang.String action) throws java.io.IOException
nodeVersion
- the caller node versionfeatures
- the caller featureschannel
- 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.IOException
public void sendResponse(Version nodeVersion, java.util.Set<java.lang.String> features, TcpChannel channel, TransportResponse response, long requestId, java.lang.String action, TransportResponseOptions options) throws java.io.IOException
TransportResponse
objects back to the caller.java.io.IOException
for sending back errors to the caller
public 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.IOException
public final void messageReceived(BytesReference reference, TcpChannel channel, java.lang.String profileName, java.net.InetSocketAddress remoteAddress, int messageLengthBytes) throws java.io.IOException
java.io.IOException
protected java.lang.String handleRequest(TcpChannel 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.IOException
protected void validateRequest(StreamInput stream, long requestId, java.lang.String action) throws java.io.IOException
java.io.IOException
protected Version executeHandshake(DiscoveryNode node, TcpChannel channel, TimeValue timeout) throws java.io.IOException, java.lang.InterruptedException
java.io.IOException
java.lang.InterruptedException
public long newRequestId()
Transport
Transport.Connection.sendRequest(long, String,
TransportRequest, TransportRequestOptions)
newRequestId
in interface Transport
protected final void ensureOpen()
java.lang.IllegalStateException
- if the transport is not started / openpublic final TransportStats getStats()
public static java.util.Set<TcpTransport.ProfileSettings> getProfileSettings(Settings settings)