Package org.elasticsearch.transport
Class TcpTransport
java.lang.Object
org.elasticsearch.common.component.AbstractLifecycleComponent
org.elasticsearch.transport.TcpTransport
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,LifecycleComponent,Releasable,Transport
public abstract class TcpTransport extends AbstractLifecycleComponent implements Transport
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTcpTransport.HttpRequestOnTransportExceptionA helper exception to mark an incoming connection as potentially being HTTP so an appropriate error code can be returnedclassTcpTransport.NodeChannelsstatic classTcpTransport.ProfileSettingsRepresentation of a transport profile settings for atransport.profiles.$profilename.*Nested classes/interfaces inherited from interface org.elasticsearch.transport.Transport
Transport.Connection, Transport.ResponseContext<T extends TransportResponse>, Transport.ResponseHandlers -
Field Summary
Fields Modifier and Type Field Description protected NetworkServicenetworkServiceprotected PageCacheRecyclerpageCacheRecyclerprotected java.util.Set<TcpTransport.ProfileSettings>profileSettingsprotected Settingssettingsprotected ThreadPoolthreadPoolstatic java.lang.StringTRANSPORT_WORKER_THREAD_NAME_PREFIX -
Constructor Summary
Constructors Constructor Description TcpTransport(Settings settings, Version version, ThreadPool threadPool, PageCacheRecycler pageCacheRecycler, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) -
Method Summary
Modifier and Type Method Description TransportAddress[]addressesFromString(java.lang.String address)Returns an address from its string representation.protected abstract TcpServerChannelbind(java.lang.String name, java.net.InetSocketAddress address)Binds to the givenInetSocketAddressprotected voidbindServer(TcpTransport.ProfileSettings profileSettings)BoundTransportAddressboundAddress()The address the transport is bound on.intconsumeNetworkReads(TcpChannel channel, BytesReference bytesReference)Consumes bytes that are available from network reads.protected voiddoClose()protected voiddoStart()protected voiddoStop()voidexecuteHandshake(DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, ActionListener<Version> listener)java.util.List<java.lang.String>getDefaultSeedAddresses()Returns a list of all local addresses for this transportstatic java.util.Set<TcpTransport.ProfileSettings>getProfileSettings(Settings settings)Returns all profile settings for the given settings objectRequestHandlerRegistry<? extends TransportRequest>getRequestHandler(java.lang.String action)Returns the registered request handler registry for the given action ornullif it's not registeredTransport.ResponseHandlersgetResponseHandlers()TransportStatsgetStats()voidinboundMessage(TcpChannel channel, BytesReference message)Handles inbound message that has been decoded.protected abstract TcpChannelinitiateChannel(DiscoveryNode node)Initiate a single tcp socket channel.protected ConnectionProfilemaybeOverrideConnectionProfile(ConnectionProfile connectionProfile)voidonException(TcpChannel channel, java.lang.Exception e)protected voidonServerException(TcpServerChannel channel, java.lang.Exception e)voidopenConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Transport.Connection> listener)Opens a new connection to the given node.java.util.Map<java.lang.String,BoundTransportAddress>profileBoundAddresses()Further profile bound addressesstatic intreadMessageLength(BytesReference networkBytes)Validates the first 6 bytes of the message header and returns the length of the message.<Request extends TransportRequest>
voidregisterRequestHandler(RequestHandlerRegistry<Request> reg)Registers a new request handlerprotected voidserverAcceptedChannel(TcpChannel channel)voidsetMessageListener(TransportMessageListener listener)protected abstract voidstopInternal()Called to tear down internal resourcesMethods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.elasticsearch.common.component.LifecycleComponent
addLifecycleListener, lifecycleState, removeLifecycleListener, start, stop
-
Field Details
-
TRANSPORT_WORKER_THREAD_NAME_PREFIX
public static final java.lang.String TRANSPORT_WORKER_THREAD_NAME_PREFIX- See Also:
- Constant Field Values
-
settings
-
threadPool
-
pageCacheRecycler
-
networkService
-
profileSettings
-
-
Constructor Details
-
TcpTransport
public TcpTransport(Settings settings, Version version, ThreadPool threadPool, PageCacheRecycler pageCacheRecycler, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService)
-
-
Method Details
-
doStart
protected void doStart()- Specified by:
doStartin classAbstractLifecycleComponent
-
setMessageListener
- Specified by:
setMessageListenerin interfaceTransport
-
registerRequestHandler
public <Request extends TransportRequest> void registerRequestHandler(RequestHandlerRegistry<Request> reg)Description copied from interface:TransportRegisters a new request handler- Specified by:
registerRequestHandlerin interfaceTransport
-
maybeOverrideConnectionProfile
-
openConnection
public void openConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Transport.Connection> listener)Description copied from interface:TransportOpens a new connection to the given node. When the connection is fully connected, the listener is called. The ActionListener will be called on the calling thread or the generic thread pool.- Specified by:
openConnectionin interfaceTransport
-
boundAddress
Description copied from interface:TransportThe address the transport is bound on.- Specified by:
boundAddressin interfaceTransport
-
profileBoundAddresses
Description copied from interface:TransportFurther profile bound addresses- Specified by:
profileBoundAddressesin interfaceTransport- Returns:
nulliff profiles are unsupported, otherwise a map with name of profile and its bound transport address
-
getDefaultSeedAddresses
public java.util.List<java.lang.String> getDefaultSeedAddresses()Description copied from interface:TransportReturns a list of all local addresses for this transport- Specified by:
getDefaultSeedAddressesin interfaceTransport
-
bindServer
-
addressesFromString
public TransportAddress[] addressesFromString(java.lang.String address) throws java.net.UnknownHostExceptionDescription copied from interface:TransportReturns an address from its string representation.- Specified by:
addressesFromStringin interfaceTransport- Throws:
java.net.UnknownHostException
-
doClose
protected final void doClose()- Specified by:
doClosein classAbstractLifecycleComponent
-
doStop
protected final void doStop()- Specified by:
doStopin classAbstractLifecycleComponent
-
onException
-
onServerException
-
serverAcceptedChannel
-
bind
protected abstract TcpServerChannel bind(java.lang.String name, java.net.InetSocketAddress address) throws java.io.IOExceptionBinds to the givenInetSocketAddress- Parameters:
name- the profile nameaddress- the address to bind to- Throws:
java.io.IOException
-
initiateChannel
Initiate a single tcp socket channel.- Parameters:
node- for the initiated connection- Returns:
- the pending connection
- Throws:
java.io.IOException- if an I/O exception occurs while opening the channel
-
stopInternal
protected abstract void stopInternal()Called to tear down internal resources -
inboundMessage
Handles inbound message that has been decoded.- Parameters:
channel- the channel the message is frommessage- the message
-
consumeNetworkReads
public int consumeNetworkReads(TcpChannel channel, BytesReference bytesReference) throws java.io.IOExceptionConsumes bytes that are available from network reads. This method returns the number of bytes consumed in this call.- Parameters:
channel- the channel read frombytesReference- the bytes available to consume- Returns:
- the number of bytes consumed
- Throws:
java.io.StreamCorruptedException- if the message header format is not recognizedTcpTransport.HttpRequestOnTransportException- if the message header appears to be an HTTP messagejava.lang.IllegalArgumentException- if the message length is greater that the maximum allowed frame size. This is dependent on the available memory.java.io.IOException
-
readMessageLength
Validates the first 6 bytes of the message header and returns the length of the message. If 6 bytes are not available, it returns -1.- Parameters:
networkBytes- the will be read- Returns:
- the length of the message
- Throws:
java.io.StreamCorruptedException- if the message header format is not recognizedTcpTransport.HttpRequestOnTransportException- if the message header appears to be an HTTP messagejava.lang.IllegalArgumentException- if the message length is greater that the maximum allowed frame size. This is dependent on the available memory.java.io.IOException
-
executeHandshake
public void executeHandshake(DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, ActionListener<Version> listener) -
getStats
-
getProfileSettings
Returns all profile settings for the given settings object -
getResponseHandlers
- Specified by:
getResponseHandlersin interfaceTransport
-
getRequestHandler
public final RequestHandlerRegistry<? extends TransportRequest> getRequestHandler(java.lang.String action)Description copied from interface:TransportReturns the registered request handler registry for the given action ornullif it's not registered- Specified by:
getRequestHandlerin interfaceTransport- Parameters:
action- the action to look up
-