Interface ProtocolHandler

  • All Superinterfaces:
    java.lang.AutoCloseable

    @LimitedPrivate
    @Evolving
    public interface ProtocolHandler
    extends java.lang.AutoCloseable
    The protocol handler interface for support additional protocols on Pulsar brokers.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean accept​(java.lang.String protocol)
      Verify if the protocol can speak the given protocol.
      void close()  
      java.lang.String getProtocolDataToAdvertise()
      Retrieve the protocol related data to advertise as part of LocalBrokerData.
      void initialize​(org.apache.pulsar.broker.ServiceConfiguration conf)
      Initialize the protocol handler when the protocol is constructed from reflection.
      java.util.Map<java.net.InetSocketAddress,​io.netty.channel.ChannelInitializer<io.netty.channel.socket.SocketChannel>> newChannelInitializers()
      Create the list of channel initializers for the ports that this protocol handler will listen on.
      java.lang.String protocolName()
      Returns the unique protocol name.
      void start​(BrokerService service)
      Start the protocol handler with the provided broker service.
    • Method Detail

      • protocolName

        java.lang.String protocolName()
        Returns the unique protocol name. For example, `kafka-v2` for protocol handler for Kafka v2 protocol.
      • accept

        boolean accept​(java.lang.String protocol)
        Verify if the protocol can speak the given protocol.
        Parameters:
        protocol - the protocol to verify
        Returns:
        true if the protocol handler can handle the given protocol, otherwise false.
      • initialize

        void initialize​(org.apache.pulsar.broker.ServiceConfiguration conf)
                 throws java.lang.Exception
        Initialize the protocol handler when the protocol is constructed from reflection.

        The initialize should initialize all the resources required for serving the protocol handler but don't start those resources until start(BrokerService) is called.

        Parameters:
        conf - broker service configuration
        Throws:
        java.lang.Exception - when fail to initialize the protocol handler.
      • getProtocolDataToAdvertise

        java.lang.String getProtocolDataToAdvertise()
        Retrieve the protocol related data to advertise as part of LocalBrokerData.

        For example, when implementing a Kafka protocol handler, you need to advertise corresponding Kafka listeners so that Pulsar brokers understand how to give back the listener information when handling metadata requests.

        NOTE: this method is called after initialize(ServiceConfiguration) and before start(BrokerService).

        Returns:
        the protocol related data to be advertised as part of LocalBrokerData.
      • start

        void start​(BrokerService service)
        Start the protocol handler with the provided broker service.

        The broker service provides the accesses to the Pulsar components such as load manager, namespace service, managed ledger and etc.

        Parameters:
        service - the broker service to start with.
      • newChannelInitializers

        java.util.Map<java.net.InetSocketAddress,​io.netty.channel.ChannelInitializer<io.netty.channel.socket.SocketChannel>> newChannelInitializers()
        Create the list of channel initializers for the ports that this protocol handler will listen on.

        NOTE: this method is called after start(BrokerService).

        Returns:
        the list of channel initializers for the ports that this protocol handler listens on.
      • close

        void close()
        Specified by:
        close in interface java.lang.AutoCloseable