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 Details

  • 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 interface RemoteConnection
    • getName

      public String getName()
      Specified by:
      getName in interface RemoteConnection
    • getChannel

      public final io.netty.channel.Channel getChannel()
      Specified by:
      getChannel in interface RemoteConnection
    • blockOnNotWritable

      public boolean blockOnNotWritable(RpcOutcomeListener<?> listener)
      Specified by:
      blockOnNotWritable in interface RemoteConnection
    • setAutoRead

      public void setAutoRead(boolean enableAutoRead)
      Specified by:
      setAutoRead in interface ConnectionThrottle
    • isActive

      public boolean isActive()
      Specified by:
      isActive in interface RemoteConnection
    • getAndRemoveRpcOutcome

      public <V> RpcOutcome<V> getAndRemoveRpcOutcome(int rpcType, int coordinationId, Class<V> clazz)
      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 interface RemoteConnection
      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 interface RemoteConnection
      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.
    • recordRemoteFailure

      public void recordRemoteFailure(int coordinationId, UserBitShared.DrillPBError failure)
      Inform the local outcome listener that the remote operation could not be handled.
      Specified by:
      recordRemoteFailure in interface RemoteConnection
      Parameters:
      coordinationId - The id that failed.
      failure - The failure that occurred.
    • channelClosed

      public void channelClosed(RpcException ex)
      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 interface RemoteConnection
      Parameters:
      ex - The exception that caused the channel to close.
    • getRemoteAddress

      public SocketAddress getRemoteAddress()
      Specified by:
      getRemoteAddress in interface RemoteConnection
    • 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 interface AutoCloseable
      Specified by:
      close in interface RemoteConnection
    • 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:

      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,CC extends ClientConnection,HS extends com.google.protobuf.MessageLite,HR extends com.google.protobuf.MessageLite>.org.apache.drill.exec.rpc.BasicClient.ClientHandshakeHandler OR BasicServer.ServerHandshakeHandler
      • optional - IDLE_STATE_HANDLER org.apache.drill.exec.rpc.BasicClient.IdlePingHandler OR - TIMEOUT_HANDLER BasicServer<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 interface RemoteConnection
    • incConnectionCounter

      public abstract void incConnectionCounter()
    • decConnectionCounter

      public abstract void decConnectionCounter()
    • setEncryption

      public void setEncryption(boolean encrypted)
      Specified by:
      setEncryption in interface EncryptionContext
    • isEncryptionEnabled

      public boolean isEncryptionEnabled()
      Specified by:
      isEncryptionEnabled in interface EncryptionContext
    • getEncryptionCtxtString

      public String getEncryptionCtxtString()
      Specified by:
      getEncryptionCtxtString in interface EncryptionContext
    • setMaxWrappedSize

      public void setMaxWrappedSize(int maxWrappedChunkSize)
      Specified by:
      setMaxWrappedSize in interface EncryptionContext
    • getMaxWrappedSize

      public int getMaxWrappedSize()
      Specified by:
      getMaxWrappedSize in interface EncryptionContext
    • setWrapSizeLimit

      public void setWrapSizeLimit(int wrapSizeLimit)
      Specified by:
      setWrapSizeLimit in interface EncryptionContext
    • getWrapSizeLimit

      public int getWrapSizeLimit()
      Specified by:
      getWrapSizeLimit in interface EncryptionContext