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
-
Constructor Summary
ConstructorDescriptionAbstractRemoteConnection
(io.netty.channel.socket.SocketChannel channel, String name, EncryptionContext encryptionContext) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Helps to add all the required security handler's after negotiation for encryption is completed.boolean
blockOnNotWritable
(RpcOutcomeListener<?> listener) void
Called from the RpcBus's channel close handler to close all remaining resources associated with this connection.void
close()
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.Channel
int
getName()
int
abstract void
boolean
boolean
isActive()
boolean
void
recordRemoteFailure
(int coordinationId, UserBitShared.DrillPBError failure) Inform the local outcome listener that the remote operation could not be handled.void
setAutoRead
(boolean enableAutoRead) void
setEncryption
(boolean encrypted) void
setMaxWrappedSize
(int maxWrappedChunkSize) void
setWrapSizeLimit
(int wrapSizeLimit) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
inEventLoop
in interfaceRemoteConnection
-
getName
- Specified by:
getName
in interfaceRemoteConnection
-
getChannel
public final io.netty.channel.Channel getChannel()- Specified by:
getChannel
in interfaceRemoteConnection
-
blockOnNotWritable
- Specified by:
blockOnNotWritable
in interfaceRemoteConnection
-
setAutoRead
public void setAutoRead(boolean enableAutoRead) - Specified by:
setAutoRead
in interfaceConnectionThrottle
-
isActive
public boolean isActive()- Specified by:
isActive
in 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:
getAndRemoveRpcOutcome
in 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:
createNewRpcListener
in 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:
channelClosed
in interfaceRemoteConnection
- Parameters:
ex
- The exception that caused the channel to close.
-
getRemoteAddress
- Specified by:
getRemoteAddress
in 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:
close
in interfaceAutoCloseable
- Specified by:
close
in 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
org.apache.drill.exec.rpc.BasicClient.IdlePingHandler
OR - TIMEOUT_HANDLERBasicServer<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
org.apache.drill.exec.rpc.BasicClient.IdlePingHandler
OR - TIMEOUT_HANDLERBasicServer<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.wrapSizeLimit
bytes. This helps to make a generic encryption handler.- Specified by:
addSecurityHandlers
in interfaceRemoteConnection
- PROTOCOL_DECODER
-
incConnectionCounter
public abstract void incConnectionCounter() -
decConnectionCounter
public abstract void decConnectionCounter() -
setEncryption
public void setEncryption(boolean encrypted) - Specified by:
setEncryption
in interfaceEncryptionContext
-
isEncryptionEnabled
public boolean isEncryptionEnabled()- Specified by:
isEncryptionEnabled
in interfaceEncryptionContext
-
getEncryptionCtxtString
- Specified by:
getEncryptionCtxtString
in interfaceEncryptionContext
-
setMaxWrappedSize
public void setMaxWrappedSize(int maxWrappedChunkSize) - Specified by:
setMaxWrappedSize
in interfaceEncryptionContext
-
getMaxWrappedSize
public int getMaxWrappedSize()- Specified by:
getMaxWrappedSize
in interfaceEncryptionContext
-
setWrapSizeLimit
public void setWrapSizeLimit(int wrapSizeLimit) - Specified by:
setWrapSizeLimit
in interfaceEncryptionContext
-
getWrapSizeLimit
public int getWrapSizeLimit()- Specified by:
getWrapSizeLimit
in interfaceEncryptionContext
-