- All Implemented Interfaces:
Closeable
,AutoCloseable
,LifecycleComponent
,Releasable
,ReportingService<TransportInfo>
,TransportConnectionListener
,TransportMessageListener
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
This handler wrapper ensures that the response thread executes with the correct thread context.static class
Nested classes/interfaces inherited from interface org.elasticsearch.node.ReportingService
ReportingService.Info
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ClusterName
protected final ConnectionManager
static final String
Undocumented on purpose, may be removed at any time.static final String
static final TransportInterceptor
protected final TaskManager
protected final ThreadPool
protected final Transport
A set of all valid action prefixes.Fields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle
Fields inherited from interface org.elasticsearch.transport.TransportMessageListener
NOOP_LISTENER
-
Constructor Summary
ConstructorsConstructorDescriptionTransportService
(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor transportInterceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, ClusterSettings clusterSettings, Set<String> taskHeaders) TransportService
(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor transportInterceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, ClusterSettings clusterSettings, Set<String> taskHeaders, Tracer tracer) TransportService
(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor transportInterceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, ClusterSettings clusterSettings, TaskManager taskManager, Tracer tracer) Build the service.TransportService
(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor transportInterceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, ClusterSettings clusterSettings, ConnectionManager connectionManager, TaskManager taskManger, Tracer tracer) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Start accepting incoming requests.void
void
addMessageListener
(TransportMessageListener listener) addressesFromString
(String address) void
connectToNode
(DiscoveryNode node, ActionListener<Releasable> listener) Connect to the specified node with the given connection profile.void
connectToNode
(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Releasable> listener) Connect to the specified node with the given connection profile.void
protected void
doClose()
Close this component.protected void
doStart()
Start this component.protected void
doStop()
Stop this component.getConnection
(DiscoveryNode node) Returns either a real transport connection or a local node connection if we are using the local node optimization.RequestHandlerRegistry<? extends TransportRequest>
getRequestHandler
(String action) Returns the internal thread poolprotected void
handleInternalSendException
(String action, DiscoveryNode node, long requestId, org.elasticsearch.transport.TransportService.TimeoutHandler timeoutHandler, Exception failure) void
handshake
(Transport.Connection connection, TimeValue handshakeTimeout, Predicate<ClusterName> clusterNamePredicate, ActionListener<TransportService.HandshakeResponse> listener) Executes a high-level handshake using the given connection and returns the discovery node of the node the connection was established with.void
handshake
(Transport.Connection connection, TimeValue handshakeTimeout, ActionListener<DiscoveryNode> listener) Executes a high-level handshake using the given connection and returns the discovery node of the node the connection was established with.info()
static boolean
isDirectResponseChannel
(TransportChannel transportChannel) boolean
static boolean
isValidActionName
(String actionName) Returnstrue
iff the action name starts with a valid prefix.boolean
nodeConnected
(DiscoveryNode node) Returnstrue
iff the given node is already connected.void
onConnectionClosed
(Transport.Connection connection) Called once a connection ws closed.void
onRequestReceived
(long requestId, String action) called by theTransport
implementation when an incoming request arrives but before any parsing of it has happened (with the exception of the requestId and action)void
onRequestSent
(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions options) called by theTransport
implementation once a request has been sentvoid
onResponseReceived
(long requestId, Transport.ResponseContext holder) Called for every response receivedvoid
onResponseSent
(long requestId, String action, Exception e) called by theTransport
implementation after an exception was sent as a response to an incoming requestvoid
onResponseSent
(long requestId, String action, TransportResponse response) called by theTransport
implementation once a response was sent to calling nodevoid
openConnection
(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) Establishes a new connection to the given node.<Request extends TransportRequest>
voidregisterRequestHandler
(String action, Executor executor, boolean forceExecution, boolean canTripCircuitBreaker, Writeable.Reader<Request> requestReader, TransportRequestHandler<Request> handler) Registers a new request handler<Request extends TransportRequest>
voidregisterRequestHandler
(String action, Executor executor, Writeable.Reader<Request> requestReader, TransportRequestHandler<Request> handler) Registers a new request handlervoid
void
final <T extends TransportResponse>
voidsendChildRequest
(DiscoveryNode node, String action, TransportRequest request, Task parentTask, TransportRequestOptions options, TransportResponseHandler<T> handler) <T extends TransportResponse>
voidsendChildRequest
(Transport.Connection connection, String action, TransportRequest request, Task parentTask, TransportRequestOptions options, TransportResponseHandler<T> handler) <T extends TransportResponse>
voidsendChildRequest
(Transport.Connection connection, String action, TransportRequest request, Task parentTask, TransportResponseHandler<T> handler) final <T extends TransportResponse>
voidsendRequest
(DiscoveryNode node, String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler) <T extends TransportResponse>
voidsendRequest
(DiscoveryNode node, String action, TransportRequest request, TransportResponseHandler<T> handler) final <T extends TransportResponse>
voidsendRequest
(Transport.Connection connection, String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler) Sends a request on the specified connection.static boolean
shouldTraceAction
(String action, String[] include, String[] exclude) stats()
static Transport.Connection
unwrapConnection
(Transport.Connection connection) Unwraps and returns the actual underlying connection of the given connection.Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.elasticsearch.transport.TransportConnectionListener
onConnectionOpened, onNodeConnected, onNodeDisconnected
-
Field Details
-
DIRECT_RESPONSE_PROFILE
- See Also:
-
HANDSHAKE_ACTION_NAME
- See Also:
-
ENABLE_STACK_OVERFLOW_AVOIDANCE
Undocumented on purpose, may be removed at any time. Only use this if instructed to do so, can have other unintended consequences including deadlocks. -
transport
-
connectionManager
-
threadPool
-
clusterName
-
taskManager
-
NOOP_TRANSPORT_INTERCEPTOR
-
VALID_ACTION_PREFIXES
A set of all valid action prefixes.
-
-
Constructor Details
-
TransportService
public TransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor transportInterceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, @Nullable ClusterSettings clusterSettings, Set<String> taskHeaders) -
TransportService
public TransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor transportInterceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, @Nullable ClusterSettings clusterSettings, TaskManager taskManager, Tracer tracer) Build the service.- Parameters:
clusterSettings
- if non null, the TransportService will register with theClusterSettings
for settings updates forTransportSettings.TRACE_LOG_EXCLUDE_SETTING
andTransportSettings.TRACE_LOG_INCLUDE_SETTING
.
-
TransportService
public TransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor transportInterceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, @Nullable ClusterSettings clusterSettings, Set<String> taskHeaders, Tracer tracer) -
TransportService
public TransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor transportInterceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, @Nullable ClusterSettings clusterSettings, ConnectionManager connectionManager, TaskManager taskManger, Tracer tracer)
-
-
Method Details
-
getRemoteClusterService
-
getLocalNode
-
getLocalNodeConnection
-
getTaskManager
-
doStart
protected void doStart()Description copied from class:AbstractLifecycleComponent
Start this component. Typically that means doing things like launching background processes and registering listeners on other components. Other components have been initialized by this point, but may not yet be started.If this method throws an exception then the startup process will fail, but this component will not be stopped before it is closed.
This method is called while synchronized on
AbstractLifecycleComponent.lifecycle
. It is only called once in the lifetime of a component, although it may not be called at all if the startup process encountered some kind of fatal error, such as the failure of some other component to initialize or start.- Specified by:
doStart
in classAbstractLifecycleComponent
-
doStop
protected void doStop()Description copied from class:AbstractLifecycleComponent
Stop this component. Typically that means doing the reverse of whateverAbstractLifecycleComponent.doStart()
does.This method is called while synchronized on
AbstractLifecycleComponent.lifecycle
. It is only called once in the lifetime of a component, after callingAbstractLifecycleComponent.doStart()
, although it will not be called at all if this component did not successfully start.- Specified by:
doStop
in classAbstractLifecycleComponent
-
doClose
Description copied from class:AbstractLifecycleComponent
Close this component. Typically that means doing the reverse of whatever happened during initialization, such as releasing resources acquired there.This method is called while synchronized on
AbstractLifecycleComponent.lifecycle
. It is called once in the lifetime of a component. If the component was started then it will be stopped before it is closed, and once it is closed it will not be started or stopped.- Specified by:
doClose
in classAbstractLifecycleComponent
- Throws:
IOException
-
acceptIncomingRequests
public final void acceptIncomingRequests()Start accepting incoming requests. The transport service starts before it's ready to accept incoming requests because we need to know the address(es) to which we are bound, which means we have to actually bind to them and start accepting incoming connections. However until this method is called we reject any incoming requests, including handshakes, by closing the connection. -
info
- Specified by:
info
in interfaceReportingService<TransportInfo>
-
stats
-
isTransportSecure
public boolean isTransportSecure() -
boundAddress
-
boundRemoteAccessAddress
-
getDefaultSeedAddresses
-
nodeConnected
Returnstrue
iff the given node is already connected. -
connectToNode
public void connectToNode(DiscoveryNode node, ActionListener<Releasable> listener) throws ConnectTransportException Connect to the specified node with the given connection profile. The ActionListener will be called on the calling thread or the generic thread pool.- Parameters:
node
- the node to connect tolistener
- the action listener to notify- Throws:
ConnectTransportException
-
connectToNode
public void connectToNode(DiscoveryNode node, @Nullable ConnectionProfile connectionProfile, ActionListener<Releasable> listener) Connect to the specified node with the given connection profile. The ActionListener will be called on the calling thread or the generic thread pool.- Parameters:
node
- the node to connect toconnectionProfile
- the connection profile to use when connecting to this nodelistener
- the action listener to notify
-
connectionValidator
-
openConnection
public void openConnection(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) Establishes a new connection to the given node. The connection is NOT maintained by this service, it's the callers responsibility to close the connection once it goes out of scope. The ActionListener will be called on the calling thread or the generic thread pool.- Parameters:
node
- the node to connect toconnectionProfile
- the connection profile to uselistener
- the action listener to notify
-
handshake
public void handshake(Transport.Connection connection, TimeValue handshakeTimeout, ActionListener<DiscoveryNode> listener) Executes a high-level handshake using the given connection and returns the discovery node of the node the connection was established with. The handshake will fail if the cluster name on the target node mismatches the local cluster name. The ActionListener will be called on the calling thread or the generic thread pool.- Parameters:
connection
- the connection to a specific nodehandshakeTimeout
- handshake timeoutlistener
- action listener to notify- Throws:
ConnectTransportException
- if the connection failedIllegalStateException
- if the handshake failed
-
handshake
public void handshake(Transport.Connection connection, TimeValue handshakeTimeout, Predicate<ClusterName> clusterNamePredicate, ActionListener<TransportService.HandshakeResponse> listener) Executes a high-level handshake using the given connection and returns the discovery node of the node the connection was established with. The handshake will fail if the cluster name on the target node doesn't match the local cluster name. The ActionListener will be called on the calling thread or the generic thread pool.- Parameters:
connection
- the connection to a specific nodehandshakeTimeout
- handshake timeoutclusterNamePredicate
- cluster name validation predicatelistener
- action listener to notify- Throws:
IllegalStateException
- if the handshake failed
-
getConnectionManager
-
newNetworkBytesStream
-
disconnectFromNode
-
addMessageListener
-
removeMessageListener
-
addConnectionListener
-
removeConnectionListener
-
sendRequest
public <T extends TransportResponse> void sendRequest(DiscoveryNode node, String action, TransportRequest request, TransportResponseHandler<T> handler) -
sendRequest
public final <T extends TransportResponse> void sendRequest(DiscoveryNode node, String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler) -
unwrapConnection
Unwraps and returns the actual underlying connection of the given connection. -
sendRequest
public final <T extends TransportResponse> void sendRequest(Transport.Connection connection, String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler) Sends a request on the specified connection. If there is a failure sending the request, the specified handler is invoked.- Type Parameters:
T
- the type of the transport response- Parameters:
connection
- the connection to send the request onaction
- the name of the actionrequest
- the requestoptions
- the options for this requesthandler
- the response handler
-
getConnection
Returns either a real transport connection or a local node connection if we are using the local node optimization.- Throws:
NodeNotConnectedException
- if the given node is not connected
-
sendChildRequest
public final <T extends TransportResponse> void sendChildRequest(DiscoveryNode node, String action, TransportRequest request, Task parentTask, TransportRequestOptions options, TransportResponseHandler<T> handler) -
sendChildRequest
public <T extends TransportResponse> void sendChildRequest(Transport.Connection connection, String action, TransportRequest request, Task parentTask, TransportResponseHandler<T> handler) -
sendChildRequest
public <T extends TransportResponse> void sendChildRequest(Transport.Connection connection, String action, TransportRequest request, Task parentTask, TransportRequestOptions options, TransportResponseHandler<T> handler) -
handleInternalSendException
protected void handleInternalSendException(String action, DiscoveryNode node, long requestId, @Nullable org.elasticsearch.transport.TransportService.TimeoutHandler timeoutHandler, Exception failure) -
shouldTraceAction
-
addressesFromString
- Throws:
UnknownHostException
-
isValidActionName
Returnstrue
iff the action name starts with a valid prefix.- See Also:
-
registerRequestHandler
public <Request extends TransportRequest> void registerRequestHandler(String action, Executor executor, Writeable.Reader<Request> requestReader, TransportRequestHandler<Request> handler) Registers a new request handler- Parameters:
action
- The action the request handler is associated withrequestReader
- a callable to be used construct new instances for streamingexecutor
- The executor the request handling will be executed onhandler
- The handler itself that implements the request handling
-
registerRequestHandler
public <Request extends TransportRequest> void registerRequestHandler(String action, Executor executor, boolean forceExecution, boolean canTripCircuitBreaker, Writeable.Reader<Request> requestReader, TransportRequestHandler<Request> handler) Registers a new request handler- Parameters:
action
- The action the request handler is associated withrequestReader
- The request class that will be used to construct new instances for streamingexecutor
- The executor the request handling will be executed onforceExecution
- Force execution on the executor queue and never reject itcanTripCircuitBreaker
- Check the request size and raise an exception in case the limit is breached.handler
- The handler itself that implements the request handling
-
onRequestReceived
called by theTransport
implementation when an incoming request arrives but before any parsing of it has happened (with the exception of the requestId and action)- Specified by:
onRequestReceived
in interfaceTransportMessageListener
- Parameters:
requestId
- the internal request IDaction
- the request action
-
onRequestSent
public void onRequestSent(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions options) called by theTransport
implementation once a request has been sent- Specified by:
onRequestSent
in interfaceTransportMessageListener
- Parameters:
node
- the node the request was sent torequestId
- the internal request idaction
- the action namerequest
- the actual requestoptions
- the request options
-
onResponseReceived
Description copied from interface:TransportMessageListener
Called for every response received- Specified by:
onResponseReceived
in interfaceTransportMessageListener
- Parameters:
requestId
- the request id for this responseholder
- the response context or null if the context was already processed ie. due to a timeout.
-
onResponseSent
called by theTransport
implementation once a response was sent to calling node- Specified by:
onResponseSent
in interfaceTransportMessageListener
- Parameters:
requestId
- the request ID (unique per client)action
- the request actionresponse
- the response send
-
onResponseSent
called by theTransport
implementation after an exception was sent as a response to an incoming request- Specified by:
onResponseSent
in interfaceTransportMessageListener
- Parameters:
requestId
- the request ID (unique per client)action
- the request actione
- the error sent back to the caller
-
getRequestHandler
-
onConnectionClosed
Description copied from interface:TransportConnectionListener
Called once a connection ws closed.- Specified by:
onConnectionClosed
in interfaceTransportConnectionListener
- Parameters:
connection
- the closed connection
-
isDirectResponseChannel
-
getThreadPool
Returns the internal thread pool
-