Interface ProtocolHandler

All Superinterfaces:
AutoCloseable

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

    Modifier and Type
    Method
    Description
    boolean
    accept(String protocol)
    Verify if the protocol can speak the given protocol.
    void
     
    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.
    Map<InetSocketAddress,io.netty.channel.ChannelInitializer<io.netty.channel.socket.SocketChannel>>
    Create the list of channel initializers for the ports that this protocol handler will listen on.
    Returns the unique protocol name.
    void
    Start the protocol handler with the provided broker service.
  • Method Details

    • protocolName

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

      boolean accept(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 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:
      Exception - when fail to initialize the protocol handler.
    • getProtocolDataToAdvertise

      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

      Map<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 AutoCloseable