Package org.apache.drill.exec.rpc
Class AbstractRemoteConnection
java.lang.Object
org.apache.drill.exec.rpc.AbstractRemoteConnection
- All Implemented Interfaces:
AutoCloseable,ConnectionThrottle,EncryptionContext,RemoteConnection
- Direct Known Subclasses:
AbstractClientConnection,AbstractServerConnection
public abstract class AbstractRemoteConnection
extends Object
implements RemoteConnection, EncryptionContext
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractRemoteConnection(io.netty.channel.socket.SocketChannel channel, String name, EncryptionContext encryptionContext) -
Method Summary
Modifier and TypeMethodDescriptionvoidHelps to add all the required security handler's after negotiation for encryption is completed.booleanblockOnNotWritable(RpcOutcomeListener<?> listener) voidCalled from the RpcBus's channel close handler to close all remaining resources associated with this connection.voidclose()Connection consumer wants to close connection.createNewRpcListener(RpcOutcomeListener<V> handler, Class<V> clazz) Create a new rpc listener that will be notified when the response is returned.abstract void<V> RpcOutcome<V> getAndRemoveRpcOutcome(int rpcType, int coordinationId, Class<V> clazz) For incoming messages, remove the outcome listener and return it.final io.netty.channel.ChannelintgetName()intabstract voidbooleanbooleanisActive()booleanvoidrecordRemoteFailure(int coordinationId, UserBitShared.DrillPBError failure) Inform the local outcome listener that the remote operation could not be handled.voidsetAutoRead(boolean enableAutoRead) voidsetEncryption(boolean encrypted) voidsetMaxWrappedSize(int maxWrappedChunkSize) voidsetWrapSizeLimit(int wrapSizeLimit) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.drill.exec.rpc.RemoteConnection
getAllocator
-
Field Details
-
saslCodec
-
-
Constructor Details
-
AbstractRemoteConnection
public AbstractRemoteConnection(io.netty.channel.socket.SocketChannel channel, String name, EncryptionContext encryptionContext)
-
-
Method Details
-
inEventLoop
public boolean inEventLoop()- Specified by:
inEventLoopin interfaceRemoteConnection
-
getName
- Specified by:
getNamein interfaceRemoteConnection
-
getChannel
public final io.netty.channel.Channel getChannel()- Specified by:
getChannelin interfaceRemoteConnection
-
blockOnNotWritable
- Specified by:
blockOnNotWritablein interfaceRemoteConnection
-
setAutoRead
public void setAutoRead(boolean enableAutoRead) - Specified by:
setAutoReadin interfaceConnectionThrottle
-
isActive
public boolean isActive()- Specified by:
isActivein interfaceRemoteConnection
-
getAndRemoveRpcOutcome
For incoming messages, remove the outcome listener and return it. Can only be done once per coordinationId creation. CoordinationId's are recycled so they will show up once we run through all 4B of them.- Specified by:
getAndRemoveRpcOutcomein interfaceRemoteConnection- Parameters:
rpcType- The rpc type associated with the coordination.coordinationId- The coordination id that was returned with the listener was created.clazz- The class that is expected in response.- Returns:
- An RpcOutcome associated with the provided coordinationId.
-
createNewRpcListener
public <V> ChannelListenerWithCoordinationId createNewRpcListener(RpcOutcomeListener<V> handler, Class<V> clazz) Create a new rpc listener that will be notified when the response is returned.- Specified by:
createNewRpcListenerin interfaceRemoteConnection- Parameters:
handler- The outcome handler to be notified when the response arrives.clazz- The Class associated with the response object.- Returns:
- The new listener. Also carries the coordination id for use in the rpc message.
-
channelClosed
Called from the RpcBus's channel close handler to close all remaining resources associated with this connection. Ensures that any pending back-pressure items are also unblocked so they can be thrown away.- Specified by:
channelClosedin interfaceRemoteConnection- Parameters:
ex- The exception that caused the channel to close.
-
getRemoteAddress
- Specified by:
getRemoteAddressin interfaceRemoteConnection
-
close
public void close()Connection consumer wants to close connection. Initiate connection close and complete. This is a blocking call that ensures that the connection is closed before returning. As part of this call, the channel close handler will be triggered which will call channelClosed() above. The latter will happen in a separate thread while this method is blocking.The check for isActive is not required here since channel can be in OPEN state without being active. We want to close in both the scenarios. A channel is in OPEN state when a socket is created for it before binding to an address.
- For connection oriented transport protocol channel moves to ACTIVE state when a connection is established using this channel. We need to have channel in ACTIVE state NOT OPEN before we can send any message to remote endpoint.
- For connectionless transport protocol a sender can send data as soon as channel moves to OPEN state.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceRemoteConnection
-
addSecurityHandlers
public void addSecurityHandlers()Helps to add all the required security handler's after negotiation for encryption is completed.Handler's before encryption is negotiated are:
- PROTOCOL_DECODER
ProtobufLengthDecoder - MESSAGE_DECODER
RpcDecoder - PROTOCOL_ENCODER
RpcEncoder - HANDSHAKE_HANDLER
BasicClient<T extends com.google.protobuf.Internal.EnumLite,ORCC extends ClientConnection, HS extends com.google.protobuf.MessageLite, HR extends com.google.protobuf.MessageLite>.org.apache.drill.exec.rpc.BasicClient.ClientHandshakeHandler BasicServer.ServerHandshakeHandler - optional - IDLE_STATE_HANDLER
OR - TIMEOUT_HANDLER
invalid reference
org.apache.drill.exec.rpc.BasicClient.IdlePingHandlerBasicServer<T extends com.google.protobuf.Internal.EnumLite,SC extends ServerConnection<SC>>.org.apache.drill.exec.rpc.BasicServer.LoggingReadTimeoutHandler - MESSAGE_HANDLER
RpcBus.InboundHandler - EXCEPTION_HANDLER
RpcExceptionHandler
Handler's after encryption is negotiated are:
- LENGTH_DECODER_HANDLER
LengthFieldBasedFrameDecoder - SASL_DECRYPTION_HANDLER
SaslDecryptionHandler - PROTOCOL_DECODER
ProtobufLengthDecoder - MESSAGE_DECODER
RpcDecoder - SASL_ENCRYPTION_HANDLER
SaslEncryptionHandler - CHUNK_CREATION_HANDLER
ChunkCreationHandler - PROTOCOL_ENCODER
RpcEncoder - HANDSHAKE_HANDLER
BasicClient<T extends com.google.protobuf.Internal.EnumLite,ORCC extends ClientConnection, HS extends com.google.protobuf.MessageLite, HR extends com.google.protobuf.MessageLite>.org.apache.drill.exec.rpc.BasicClient.ClientHandshakeHandler BasicServer.ServerHandshakeHandler - optional - IDLE_STATE_HANDLER
OR - TIMEOUT_HANDLER
invalid reference
org.apache.drill.exec.rpc.BasicClient.IdlePingHandlerBasicServer<T extends com.google.protobuf.Internal.EnumLite,SC extends ServerConnection<SC>>.org.apache.drill.exec.rpc.BasicServer.LoggingReadTimeoutHandler - MESSAGE_HANDLER
RpcBus.InboundHandler - EXCEPTION_HANDLER
RpcExceptionHandler
If encryption is enabled ChunkCreationHandler is always added to divide the Rpc message into chunks of negotiated
EncryptionContextImpl.wrapSizeLimitbytes. This helps to make a generic encryption handler.- Specified by:
addSecurityHandlersin interfaceRemoteConnection
- PROTOCOL_DECODER
-
incConnectionCounter
public abstract void incConnectionCounter() -
decConnectionCounter
public abstract void decConnectionCounter() -
setEncryption
public void setEncryption(boolean encrypted) - Specified by:
setEncryptionin interfaceEncryptionContext
-
isEncryptionEnabled
public boolean isEncryptionEnabled()- Specified by:
isEncryptionEnabledin interfaceEncryptionContext
-
getEncryptionCtxtString
- Specified by:
getEncryptionCtxtStringin interfaceEncryptionContext
-
setMaxWrappedSize
public void setMaxWrappedSize(int maxWrappedChunkSize) - Specified by:
setMaxWrappedSizein interfaceEncryptionContext
-
getMaxWrappedSize
public int getMaxWrappedSize()- Specified by:
getMaxWrappedSizein interfaceEncryptionContext
-
setWrapSizeLimit
public void setWrapSizeLimit(int wrapSizeLimit) - Specified by:
setWrapSizeLimitin interfaceEncryptionContext
-
getWrapSizeLimit
public int getWrapSizeLimit()- Specified by:
getWrapSizeLimitin interfaceEncryptionContext
-