Class ServerCnx

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
org.apache.pulsar.common.protocol.PulsarDecoder
org.apache.pulsar.common.protocol.PulsarHandler
org.apache.pulsar.broker.service.ServerCnx
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, TransportCnx

public class ServerCnx extends org.apache.pulsar.common.protocol.PulsarHandler implements TransportCnx
Channel handler for the Pulsar broker.

Please see PulsarDecoder javadoc for important details about handle* method parameter instance lifecycle.

  • Constructor Details

  • Method Details

    • channelActive

      public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class org.apache.pulsar.common.protocol.PulsarHandler
      Throws:
      Exception
    • channelInactive

      public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelInactive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class org.apache.pulsar.common.protocol.PulsarHandler
      Throws:
      Exception
    • channelWritabilityChanged

      public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelWritabilityChanged in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelWritabilityChanged in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • handleLookup

      protected void handleLookup(org.apache.pulsar.common.api.proto.CommandLookupTopic lookup)
      Overrides:
      handleLookup in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handlePartitionMetadataRequest

      protected void handlePartitionMetadataRequest(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadata partitionMetadata)
      Overrides:
      handlePartitionMetadataRequest in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleConsumerStats

      protected void handleConsumerStats(org.apache.pulsar.common.api.proto.CommandConsumerStats commandConsumerStats)
      Overrides:
      handleConsumerStats in class org.apache.pulsar.common.protocol.PulsarDecoder
    • authChallengeSuccessCallback

      public void authChallengeSuccessCallback(org.apache.pulsar.common.api.AuthData authChallenge, boolean useOriginalAuthState, String authRole, int clientProtocolVersion, String clientVersion)
    • handleConnect

      protected void handleConnect(org.apache.pulsar.common.api.proto.CommandConnect connect)
      Overrides:
      handleConnect in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleAuthResponse

      protected void handleAuthResponse(org.apache.pulsar.common.api.proto.CommandAuthResponse authResponse)
      Overrides:
      handleAuthResponse in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleSubscribe

      protected void handleSubscribe(org.apache.pulsar.common.api.proto.CommandSubscribe subscribe)
      Overrides:
      handleSubscribe in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleProducer

      protected void handleProducer(org.apache.pulsar.common.api.proto.CommandProducer cmdProducer)
      Overrides:
      handleProducer in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleSend

      protected void handleSend(org.apache.pulsar.common.api.proto.CommandSend send, io.netty.buffer.ByteBuf headersAndPayload)
      Overrides:
      handleSend in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleAck

      protected void handleAck(org.apache.pulsar.common.api.proto.CommandAck ack)
      Overrides:
      handleAck in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleFlow

      protected void handleFlow(org.apache.pulsar.common.api.proto.CommandFlow flow)
      Overrides:
      handleFlow in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleRedeliverUnacknowledged

      protected void handleRedeliverUnacknowledged(org.apache.pulsar.common.api.proto.CommandRedeliverUnacknowledgedMessages redeliver)
      Overrides:
      handleRedeliverUnacknowledged in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleUnsubscribe

      protected void handleUnsubscribe(org.apache.pulsar.common.api.proto.CommandUnsubscribe unsubscribe)
      Overrides:
      handleUnsubscribe in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleSeek

      protected void handleSeek(org.apache.pulsar.common.api.proto.CommandSeek seek)
      Overrides:
      handleSeek in class org.apache.pulsar.common.protocol.PulsarDecoder
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • handleCloseProducer

      protected void handleCloseProducer(org.apache.pulsar.common.api.proto.CommandCloseProducer closeProducer)
      Overrides:
      handleCloseProducer in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleCloseConsumer

      protected void handleCloseConsumer(org.apache.pulsar.common.api.proto.CommandCloseConsumer closeConsumer)
      Overrides:
      handleCloseConsumer in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleGetLastMessageId

      protected void handleGetLastMessageId(org.apache.pulsar.common.api.proto.CommandGetLastMessageId getLastMessageId)
      Overrides:
      handleGetLastMessageId in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleGetTopicsOfNamespace

      protected void handleGetTopicsOfNamespace(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace commandGetTopicsOfNamespace)
      Overrides:
      handleGetTopicsOfNamespace in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleGetSchema

      protected void handleGetSchema(org.apache.pulsar.common.api.proto.CommandGetSchema commandGetSchema)
      Overrides:
      handleGetSchema in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleGetOrCreateSchema

      protected void handleGetOrCreateSchema(org.apache.pulsar.common.api.proto.CommandGetOrCreateSchema commandGetOrCreateSchema)
      Overrides:
      handleGetOrCreateSchema in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleTcClientConnectRequest

      protected void handleTcClientConnectRequest(org.apache.pulsar.common.api.proto.CommandTcClientConnectRequest command)
      Overrides:
      handleTcClientConnectRequest in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleNewTxn

      protected void handleNewTxn(org.apache.pulsar.common.api.proto.CommandNewTxn command)
      Overrides:
      handleNewTxn in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleAddPartitionToTxn

      protected void handleAddPartitionToTxn(org.apache.pulsar.common.api.proto.CommandAddPartitionToTxn command)
      Overrides:
      handleAddPartitionToTxn in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleEndTxn

      protected void handleEndTxn(org.apache.pulsar.common.api.proto.CommandEndTxn command)
      Overrides:
      handleEndTxn in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleEndTxnOnPartition

      protected void handleEndTxnOnPartition(org.apache.pulsar.common.api.proto.CommandEndTxnOnPartition command)
      Overrides:
      handleEndTxnOnPartition in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleEndTxnOnSubscription

      protected void handleEndTxnOnSubscription(org.apache.pulsar.common.api.proto.CommandEndTxnOnSubscription command)
      Overrides:
      handleEndTxnOnSubscription in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleAddSubscriptionToTxn

      protected void handleAddSubscriptionToTxn(org.apache.pulsar.common.api.proto.CommandAddSubscriptionToTxn command)
      Overrides:
      handleAddSubscriptionToTxn in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleCommandWatchTopicList

      protected void handleCommandWatchTopicList(org.apache.pulsar.common.api.proto.CommandWatchTopicList commandWatchTopicList)
      Overrides:
      handleCommandWatchTopicList in class org.apache.pulsar.common.protocol.PulsarDecoder
    • handleCommandWatchTopicListClose

      protected void handleCommandWatchTopicListClose(org.apache.pulsar.common.api.proto.CommandWatchTopicListClose commandWatchTopicListClose)
      Overrides:
      handleCommandWatchTopicListClose in class org.apache.pulsar.common.protocol.PulsarDecoder
    • isHandshakeCompleted

      protected boolean isHandshakeCompleted()
      Specified by:
      isHandshakeCompleted in class org.apache.pulsar.common.protocol.PulsarHandler
    • ctx

      public io.netty.channel.ChannelHandlerContext ctx()
    • interceptCommand

      protected void interceptCommand(org.apache.pulsar.common.api.proto.BaseCommand command) throws org.apache.pulsar.common.intercept.InterceptException
      Overrides:
      interceptCommand in class org.apache.pulsar.common.protocol.PulsarDecoder
      Throws:
      org.apache.pulsar.common.intercept.InterceptException
    • closeProducer

      public void closeProducer(Producer producer)
      Specified by:
      closeProducer in interface TransportCnx
    • closeProducer

      public void closeProducer(Producer producer, Optional<BrokerLookupData> assignedBrokerLookupData)
      Specified by:
      closeProducer in interface TransportCnx
    • closeConsumer

      public void closeConsumer(Consumer consumer, Optional<BrokerLookupData> assignedBrokerLookupData)
      Specified by:
      closeConsumer in interface TransportCnx
    • close

      protected void close()
      It closes the connection with client which triggers channelInactive() which clears all producers and consumers from connection-map.
    • clientAddress

      public SocketAddress clientAddress()
      Specified by:
      clientAddress in interface TransportCnx
    • removedConsumer

      public void removedConsumer(Consumer consumer)
      Specified by:
      removedConsumer in interface TransportCnx
    • removedProducer

      public void removedProducer(Producer producer)
      Specified by:
      removedProducer in interface TransportCnx
    • isActive

      public boolean isActive()
      Specified by:
      isActive in interface TransportCnx
    • isWritable

      public boolean isWritable()
      Specified by:
      isWritable in interface TransportCnx
    • completedSendOperation

      public void completedSendOperation(boolean isNonPersistentTopic, int msgSize)
      Specified by:
      completedSendOperation in interface TransportCnx
    • newMessageAndIntercept

      public org.apache.pulsar.common.protocol.ByteBufPair newMessageAndIntercept(long consumerId, long ledgerId, long entryId, int partition, int redeliveryCount, io.netty.buffer.ByteBuf metadataAndPayload, long[] ackSet, String topic, long epoch)
    • getState

      public org.apache.pulsar.broker.service.ServerCnx.State getState()
      Helper method for testability.
      Returns:
      the connection state
    • getRemoteAddress

      public SocketAddress getRemoteAddress()
    • toString

      public String toString()
      Demo: [id: 0x2561bcd1, L:/10.0.136.103:6650 ! R:/240.240.0.5:58038] [SR:/240.240.0.5:58038]. L: local Address. R: remote address. SR: source remote address. It is the source address when enabled "haProxyProtocolEnabled".
      Overrides:
      toString in class org.apache.pulsar.common.protocol.PulsarHandler
    • getBrokerService

      public BrokerService getBrokerService()
      Specified by:
      getBrokerService in interface TransportCnx
    • getRole

      public String getRole()
    • newPromise

      public io.netty.util.concurrent.Promise<Void> newPromise()
      Specified by:
      newPromise in interface TransportCnx
    • getHAProxyMessage

      public io.netty.handler.codec.haproxy.HAProxyMessage getHAProxyMessage()
      Specified by:
      getHAProxyMessage in interface TransportCnx
    • hasHAProxyMessage

      public boolean hasHAProxyMessage()
      Specified by:
      hasHAProxyMessage in interface TransportCnx
    • isBatchMessageCompatibleVersion

      public boolean isBatchMessageCompatibleVersion()
      Specified by:
      isBatchMessageCompatibleVersion in interface TransportCnx
    • getClientVersion

      public String getClientVersion()
      Specified by:
      getClientVersion in interface TransportCnx
    • getProxyVersion

      public String getProxyVersion()
      Specified by:
      getProxyVersion in interface TransportCnx
    • isPreciseDispatcherFlowControl

      public boolean isPreciseDispatcherFlowControl()
      Specified by:
      isPreciseDispatcherFlowControl in interface TransportCnx
    • getAuthState

      public AuthenticationState getAuthState()
    • getAuthenticationData

      public AuthenticationDataSource getAuthenticationData()
      Specified by:
      getAuthenticationData in interface TransportCnx
    • getPrincipal

      public String getPrincipal()
    • getAuthenticationProvider

      public AuthenticationProvider getAuthenticationProvider()
    • getAuthRole

      public String getAuthRole()
      Description copied from interface: TransportCnx
      The security role for this connection.
      Specified by:
      getAuthRole in interface TransportCnx
      Returns:
      the role
    • getAuthMethod

      public String getAuthMethod()
    • getConsumers

      public org.apache.pulsar.common.util.collections.ConcurrentLongHashMap<CompletableFuture<Consumer>> getConsumers()
    • getProducers

      public org.apache.pulsar.common.util.collections.ConcurrentLongHashMap<CompletableFuture<Producer>> getProducers()
    • getCommandSender

      public PulsarCommandSender getCommandSender()
      Specified by:
      getCommandSender in interface TransportCnx
    • execute

      public void execute(Runnable runnable)
      Specified by:
      execute in interface TransportCnx
    • clientSourceAddress

      public String clientSourceAddress()
      Specified by:
      clientSourceAddress in interface TransportCnx
    • clientSourceAddressAndPort

      public String clientSourceAddressAndPort()
      Specified by:
      clientSourceAddressAndPort in interface TransportCnx
    • checkConnectionLiveness

      public CompletableFuture<Optional<Boolean>> checkConnectionLiveness()
      Description copied from interface: TransportCnx
      Check if the connection is still alive by actively sending a Ping message to the client.
      Specified by:
      checkConnectionLiveness in interface TransportCnx
      Returns:
      a completable future where the result is true if the connection is alive, false otherwise. The result is empty if the connection liveness check is disabled.
    • messageReceived

      protected void messageReceived()
      Overrides:
      messageReceived in class org.apache.pulsar.common.protocol.PulsarHandler
    • hasProducers

      public boolean hasProducers()
    • getOriginalPrincipal

      protected String getOriginalPrincipal()
    • getAuthData

      protected AuthenticationDataSource getAuthData()
    • getOriginalAuthData

      protected AuthenticationDataSource getOriginalAuthData()
    • getOriginalAuthState

      protected AuthenticationState getOriginalAuthState()
    • setAuthRole

      protected void setAuthRole(String authRole)
    • incrementThrottleCount

      public void incrementThrottleCount()
      Increments the counter that controls the throttling of the connection by pausing reads. The connection will be throttled while the counter is greater than 0.

      The caller is responsible for decrementing the counter by calling TransportCnx.decrementThrottleCount() when the connection should no longer be throttled.

      Specified by:
      incrementThrottleCount in interface TransportCnx
    • decrementThrottleCount

      public void decrementThrottleCount()
      Decrements the counter that controls the throttling of the connection by pausing reads. The connection will be throttled while the counter is greater than 0.

      This method should be called when the connection should no longer be throttled. However, the caller should have previously called TransportCnx.incrementThrottleCount().

      Specified by:
      decrementThrottleCount in interface TransportCnx