Package org.apache.pulsar.broker.service
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
-
-
Constructor Summary
Constructors Constructor Description ServerCnx(PulsarService pulsar)ServerCnx(PulsarService pulsar, java.lang.String listenerName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancelPublishBufferLimiting()voidcancelPublishRateLimiting()voidchannelActive(io.netty.channel.ChannelHandlerContext ctx)voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx)voidchannelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx)java.net.SocketAddressclientAddress()java.lang.StringclientSourceAddress()protected voidclose()It closes the connection with client which triggerschannelInactive()which clears all producers and consumers from connection-map.voidcloseConsumer(Consumer consumer)voidcloseProducer(Producer producer)voidcompletedSendOperation(boolean isNonPersistentTopic, int msgSize)io.netty.channel.ChannelHandlerContextctx()voiddisableCnxAutoRead()voidenableCnxAutoRead()booleanequals(java.lang.Object o)voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause)voidexecute(java.lang.Runnable runnable)protected org.apache.pulsar.broker.authentication.AuthenticationDataSourcegetAuthData()org.apache.pulsar.broker.authentication.AuthenticationDataSourcegetAuthenticationData()org.apache.pulsar.broker.authentication.AuthenticationProvidergetAuthenticationProvider()java.lang.StringgetAuthMethod()java.lang.StringgetAuthRole()The security role for this connection.org.apache.pulsar.broker.authentication.AuthenticationStategetAuthState()BrokerServicegetBrokerService()java.lang.StringgetClientVersion()PulsarCommandSendergetCommandSender()org.apache.pulsar.common.util.collections.ConcurrentLongHashMap<java.util.concurrent.CompletableFuture<Consumer>>getConsumers()io.netty.handler.codec.haproxy.HAProxyMessagegetHAProxyMessage()protected org.apache.pulsar.broker.authentication.AuthenticationDataSourcegetOriginalAuthData()protected org.apache.pulsar.broker.authentication.AuthenticationStategetOriginalAuthState()protected java.lang.StringgetOriginalPrincipal()java.lang.StringgetPrincipal()org.apache.pulsar.common.util.collections.ConcurrentLongHashMap<java.util.concurrent.CompletableFuture<Producer>>getProducers()java.net.SocketAddressgetRemoteAddress()java.lang.StringgetRole()org.apache.pulsar.broker.service.ServerCnx.StategetState()Helper method for testability.protected voidhandleAck(org.apache.pulsar.common.api.proto.CommandAck ack)protected voidhandleAddPartitionToTxn(org.apache.pulsar.common.api.proto.CommandAddPartitionToTxn command)protected voidhandleAddSubscriptionToTxn(org.apache.pulsar.common.api.proto.CommandAddSubscriptionToTxn command)protected voidhandleAuthResponse(org.apache.pulsar.common.api.proto.CommandAuthResponse authResponse)protected voidhandleCloseConsumer(org.apache.pulsar.common.api.proto.CommandCloseConsumer closeConsumer)protected voidhandleCloseProducer(org.apache.pulsar.common.api.proto.CommandCloseProducer closeProducer)protected voidhandleConnect(org.apache.pulsar.common.api.proto.CommandConnect connect)protected voidhandleConsumerStats(org.apache.pulsar.common.api.proto.CommandConsumerStats commandConsumerStats)protected voidhandleEndTxn(org.apache.pulsar.common.api.proto.CommandEndTxn command)protected voidhandleEndTxnOnPartition(org.apache.pulsar.common.api.proto.CommandEndTxnOnPartition command)protected voidhandleEndTxnOnSubscription(org.apache.pulsar.common.api.proto.CommandEndTxnOnSubscription command)protected voidhandleFlow(org.apache.pulsar.common.api.proto.CommandFlow flow)protected voidhandleGetLastMessageId(org.apache.pulsar.common.api.proto.CommandGetLastMessageId getLastMessageId)protected voidhandleGetOrCreateSchema(org.apache.pulsar.common.api.proto.CommandGetOrCreateSchema commandGetOrCreateSchema)protected voidhandleGetSchema(org.apache.pulsar.common.api.proto.CommandGetSchema commandGetSchema)protected voidhandleGetTopicsOfNamespace(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace commandGetTopicsOfNamespace)protected voidhandleLookup(org.apache.pulsar.common.api.proto.CommandLookupTopic lookup)protected voidhandleNewTxn(org.apache.pulsar.common.api.proto.CommandNewTxn command)protected voidhandlePartitionMetadataRequest(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadata partitionMetadata)protected voidhandleProducer(org.apache.pulsar.common.api.proto.CommandProducer cmdProducer)protected voidhandleRedeliverUnacknowledged(org.apache.pulsar.common.api.proto.CommandRedeliverUnacknowledgedMessages redeliver)protected voidhandleSeek(org.apache.pulsar.common.api.proto.CommandSeek seek)protected voidhandleSend(org.apache.pulsar.common.api.proto.CommandSend send, io.netty.buffer.ByteBuf headersAndPayload)protected voidhandleSubscribe(org.apache.pulsar.common.api.proto.CommandSubscribe subscribe)protected voidhandleTcClientConnectRequest(org.apache.pulsar.common.api.proto.CommandTcClientConnectRequest command)protected voidhandleUnsubscribe(org.apache.pulsar.common.api.proto.CommandUnsubscribe unsubscribe)booleanhasHAProxyMessage()inthashCode()booleanhasProducers()protected voidinterceptCommand(org.apache.pulsar.common.api.proto.BaseCommand command)booleanisActive()booleanisBatchMessageCompatibleVersion()protected booleanisHandshakeCompleted()booleanisPreciseDispatcherFlowControl()booleanisWritable()org.apache.pulsar.common.protocol.ByteBufPairnewMessageAndIntercept(long consumerId, long ledgerId, long entryId, int partition, int redeliveryCount, io.netty.buffer.ByteBuf metadataAndPayload, long[] ackSet, java.lang.String topic, long epoch)io.netty.util.concurrent.Promise<java.lang.Void>newPromise()voidremovedConsumer(Consumer consumer)voidremovedProducer(Producer producer)protected voidsetAuthRole(java.lang.String authRole)voidstartSendOperation(Producer producer, int msgSize, int numMessages)-
Methods inherited from class org.apache.pulsar.common.protocol.PulsarHandler
cancelKeepAliveTask, getRemoteEndpointProtocolVersion, handlePing, handlePong, messageReceived, setRemoteEndpointProtocolVersion
-
Methods inherited from class org.apache.pulsar.common.protocol.PulsarDecoder
channelRead, handleAckResponse, handleActiveConsumerChange, handleAddPartitionToTxnResponse, handleAddSubscriptionToTxnResponse, handleAuthChallenge, handleConnected, handleConsumerStatsResponse, handleEndTxnOnPartitionResponse, handleEndTxnOnSubscriptionResponse, handleEndTxnResponse, handleError, handleGetLastMessageIdSuccess, handleGetOrCreateSchemaResponse, handleGetSchemaResponse, handleGetTopicsOfNamespaceSuccess, handleLookupResponse, handleMessage, handleNewTxnResponse, handlePartitionResponse, handleProducerSuccess, handleReachedEndOfTopic, handleSendError, handleSendReceipt, handleSuccess, handleTcClientConnectResponse
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelReadComplete, channelRegistered, channelUnregistered, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
-
-
-
Constructor Detail
-
ServerCnx
public ServerCnx(PulsarService pulsar)
-
ServerCnx
public ServerCnx(PulsarService pulsar, java.lang.String listenerName)
-
-
Method Detail
-
channelActive
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception- Specified by:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classorg.apache.pulsar.common.protocol.PulsarHandler- Throws:
java.lang.Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classorg.apache.pulsar.common.protocol.PulsarHandler- Throws:
java.lang.Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception- Specified by:
channelWritabilityChangedin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelWritabilityChangedin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-
handleLookup
protected void handleLookup(org.apache.pulsar.common.api.proto.CommandLookupTopic lookup)
- Overrides:
handleLookupin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handlePartitionMetadataRequest
protected void handlePartitionMetadataRequest(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadata partitionMetadata)
- Overrides:
handlePartitionMetadataRequestin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleConsumerStats
protected void handleConsumerStats(org.apache.pulsar.common.api.proto.CommandConsumerStats commandConsumerStats)
- Overrides:
handleConsumerStatsin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleConnect
protected void handleConnect(org.apache.pulsar.common.api.proto.CommandConnect connect)
- Overrides:
handleConnectin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleAuthResponse
protected void handleAuthResponse(org.apache.pulsar.common.api.proto.CommandAuthResponse authResponse)
- Overrides:
handleAuthResponsein classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleSubscribe
protected void handleSubscribe(org.apache.pulsar.common.api.proto.CommandSubscribe subscribe)
- Overrides:
handleSubscribein classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleProducer
protected void handleProducer(org.apache.pulsar.common.api.proto.CommandProducer cmdProducer)
- Overrides:
handleProducerin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleSend
protected void handleSend(org.apache.pulsar.common.api.proto.CommandSend send, io.netty.buffer.ByteBuf headersAndPayload)- Overrides:
handleSendin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleAck
protected void handleAck(org.apache.pulsar.common.api.proto.CommandAck ack)
- Overrides:
handleAckin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleFlow
protected void handleFlow(org.apache.pulsar.common.api.proto.CommandFlow flow)
- Overrides:
handleFlowin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleRedeliverUnacknowledged
protected void handleRedeliverUnacknowledged(org.apache.pulsar.common.api.proto.CommandRedeliverUnacknowledgedMessages redeliver)
- Overrides:
handleRedeliverUnacknowledgedin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleUnsubscribe
protected void handleUnsubscribe(org.apache.pulsar.common.api.proto.CommandUnsubscribe unsubscribe)
- Overrides:
handleUnsubscribein classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleSeek
protected void handleSeek(org.apache.pulsar.common.api.proto.CommandSeek seek)
- Overrides:
handleSeekin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
handleCloseProducer
protected void handleCloseProducer(org.apache.pulsar.common.api.proto.CommandCloseProducer closeProducer)
- Overrides:
handleCloseProducerin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleCloseConsumer
protected void handleCloseConsumer(org.apache.pulsar.common.api.proto.CommandCloseConsumer closeConsumer)
- Overrides:
handleCloseConsumerin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleGetLastMessageId
protected void handleGetLastMessageId(org.apache.pulsar.common.api.proto.CommandGetLastMessageId getLastMessageId)
- Overrides:
handleGetLastMessageIdin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleGetTopicsOfNamespace
protected void handleGetTopicsOfNamespace(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace commandGetTopicsOfNamespace)
- Overrides:
handleGetTopicsOfNamespacein classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleGetSchema
protected void handleGetSchema(org.apache.pulsar.common.api.proto.CommandGetSchema commandGetSchema)
- Overrides:
handleGetSchemain classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleGetOrCreateSchema
protected void handleGetOrCreateSchema(org.apache.pulsar.common.api.proto.CommandGetOrCreateSchema commandGetOrCreateSchema)
- Overrides:
handleGetOrCreateSchemain classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleTcClientConnectRequest
protected void handleTcClientConnectRequest(org.apache.pulsar.common.api.proto.CommandTcClientConnectRequest command)
- Overrides:
handleTcClientConnectRequestin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleNewTxn
protected void handleNewTxn(org.apache.pulsar.common.api.proto.CommandNewTxn command)
- Overrides:
handleNewTxnin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleAddPartitionToTxn
protected void handleAddPartitionToTxn(org.apache.pulsar.common.api.proto.CommandAddPartitionToTxn command)
- Overrides:
handleAddPartitionToTxnin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleEndTxn
protected void handleEndTxn(org.apache.pulsar.common.api.proto.CommandEndTxn command)
- Overrides:
handleEndTxnin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleEndTxnOnPartition
protected void handleEndTxnOnPartition(org.apache.pulsar.common.api.proto.CommandEndTxnOnPartition command)
- Overrides:
handleEndTxnOnPartitionin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleEndTxnOnSubscription
protected void handleEndTxnOnSubscription(org.apache.pulsar.common.api.proto.CommandEndTxnOnSubscription command)
- Overrides:
handleEndTxnOnSubscriptionin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
handleAddSubscriptionToTxn
protected void handleAddSubscriptionToTxn(org.apache.pulsar.common.api.proto.CommandAddSubscriptionToTxn command)
- Overrides:
handleAddSubscriptionToTxnin classorg.apache.pulsar.common.protocol.PulsarDecoder
-
isHandshakeCompleted
protected boolean isHandshakeCompleted()
- Specified by:
isHandshakeCompletedin classorg.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:
interceptCommandin classorg.apache.pulsar.common.protocol.PulsarDecoder- Throws:
org.apache.pulsar.common.intercept.InterceptException
-
closeProducer
public void closeProducer(Producer producer)
- Specified by:
closeProducerin interfaceTransportCnx
-
closeConsumer
public void closeConsumer(Consumer consumer)
- Specified by:
closeConsumerin interfaceTransportCnx
-
close
protected void close()
It closes the connection with client which triggerschannelInactive()which clears all producers and consumers from connection-map.
-
clientAddress
public java.net.SocketAddress clientAddress()
- Specified by:
clientAddressin interfaceTransportCnx
-
removedConsumer
public void removedConsumer(Consumer consumer)
- Specified by:
removedConsumerin interfaceTransportCnx
-
removedProducer
public void removedProducer(Producer producer)
- Specified by:
removedProducerin interfaceTransportCnx
-
isActive
public boolean isActive()
- Specified by:
isActivein interfaceTransportCnx
-
isWritable
public boolean isWritable()
- Specified by:
isWritablein interfaceTransportCnx
-
startSendOperation
public void startSendOperation(Producer producer, int msgSize, int numMessages)
-
completedSendOperation
public void completedSendOperation(boolean isNonPersistentTopic, int msgSize)- Specified by:
completedSendOperationin interfaceTransportCnx
-
enableCnxAutoRead
public void enableCnxAutoRead()
- Specified by:
enableCnxAutoReadin interfaceTransportCnx
-
disableCnxAutoRead
public void disableCnxAutoRead()
- Specified by:
disableCnxAutoReadin interfaceTransportCnx
-
cancelPublishRateLimiting
public void cancelPublishRateLimiting()
- Specified by:
cancelPublishRateLimitingin interfaceTransportCnx
-
cancelPublishBufferLimiting
public void cancelPublishBufferLimiting()
- Specified by:
cancelPublishBufferLimitingin interfaceTransportCnx
-
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, java.lang.String topic, long epoch)
-
getState
public org.apache.pulsar.broker.service.ServerCnx.State getState()
Helper method for testability.- Returns:
- the connection state
-
getRemoteAddress
public java.net.SocketAddress getRemoteAddress()
-
getBrokerService
public BrokerService getBrokerService()
- Specified by:
getBrokerServicein interfaceTransportCnx
-
getRole
public java.lang.String getRole()
-
newPromise
public io.netty.util.concurrent.Promise<java.lang.Void> newPromise()
- Specified by:
newPromisein interfaceTransportCnx
-
getHAProxyMessage
public io.netty.handler.codec.haproxy.HAProxyMessage getHAProxyMessage()
- Specified by:
getHAProxyMessagein interfaceTransportCnx
-
hasHAProxyMessage
public boolean hasHAProxyMessage()
- Specified by:
hasHAProxyMessagein interfaceTransportCnx
-
isBatchMessageCompatibleVersion
public boolean isBatchMessageCompatibleVersion()
- Specified by:
isBatchMessageCompatibleVersionin interfaceTransportCnx
-
getClientVersion
public java.lang.String getClientVersion()
- Specified by:
getClientVersionin interfaceTransportCnx
-
isPreciseDispatcherFlowControl
public boolean isPreciseDispatcherFlowControl()
- Specified by:
isPreciseDispatcherFlowControlin interfaceTransportCnx
-
getAuthState
public org.apache.pulsar.broker.authentication.AuthenticationState getAuthState()
-
getAuthenticationData
public org.apache.pulsar.broker.authentication.AuthenticationDataSource getAuthenticationData()
- Specified by:
getAuthenticationDatain interfaceTransportCnx
-
getPrincipal
public java.lang.String getPrincipal()
-
getAuthenticationProvider
public org.apache.pulsar.broker.authentication.AuthenticationProvider getAuthenticationProvider()
-
getAuthRole
public java.lang.String getAuthRole()
Description copied from interface:TransportCnxThe security role for this connection.- Specified by:
getAuthRolein interfaceTransportCnx- Returns:
- the role
-
getAuthMethod
public java.lang.String getAuthMethod()
-
getConsumers
public org.apache.pulsar.common.util.collections.ConcurrentLongHashMap<java.util.concurrent.CompletableFuture<Consumer>> getConsumers()
-
getProducers
public org.apache.pulsar.common.util.collections.ConcurrentLongHashMap<java.util.concurrent.CompletableFuture<Producer>> getProducers()
-
getCommandSender
public PulsarCommandSender getCommandSender()
- Specified by:
getCommandSenderin interfaceTransportCnx
-
execute
public void execute(java.lang.Runnable runnable)
- Specified by:
executein interfaceTransportCnx
-
clientSourceAddress
public java.lang.String clientSourceAddress()
- Specified by:
clientSourceAddressin interfaceTransportCnx
-
hasProducers
public boolean hasProducers()
-
getOriginalPrincipal
protected java.lang.String getOriginalPrincipal()
-
getAuthData
protected org.apache.pulsar.broker.authentication.AuthenticationDataSource getAuthData()
-
getOriginalAuthData
protected org.apache.pulsar.broker.authentication.AuthenticationDataSource getOriginalAuthData()
-
getOriginalAuthState
protected org.apache.pulsar.broker.authentication.AuthenticationState getOriginalAuthState()
-
setAuthRole
protected void setAuthRole(java.lang.String authRole)
-
-