Class PulsarService

  • All Implemented Interfaces:
    java.lang.AutoCloseable, org.apache.pulsar.broker.ShutdownService

    public class PulsarService
    extends java.lang.Object
    implements java.lang.AutoCloseable, org.apache.pulsar.broker.ShutdownService
    Main class for Pulsar broker service.
    • Field Detail

      • ioEventLoopGroup

        protected final io.netty.channel.EventLoopGroup ioEventLoopGroup
    • Constructor Detail

      • PulsarService

        public PulsarService​(org.apache.pulsar.broker.ServiceConfiguration config)
      • PulsarService

        public PulsarService​(org.apache.pulsar.broker.ServiceConfiguration config,
                             java.util.Optional<org.apache.pulsar.functions.worker.WorkerService> functionWorkerService,
                             java.util.function.Consumer<java.lang.Integer> processTerminator)
      • PulsarService

        public PulsarService​(org.apache.pulsar.broker.ServiceConfiguration config,
                             org.apache.pulsar.functions.worker.WorkerConfig workerConfig,
                             java.util.Optional<org.apache.pulsar.functions.worker.WorkerService> functionWorkerService,
                             java.util.function.Consumer<java.lang.Integer> processTerminator)
    • Method Detail

      • createConfigurationMetadataStore

        public org.apache.pulsar.metadata.api.MetadataStore createConfigurationMetadataStore()
                                                                                      throws org.apache.pulsar.metadata.api.MetadataStoreException
        Throws:
        org.apache.pulsar.metadata.api.MetadataStoreException
      • closeMetadataServiceSession

        public void closeMetadataServiceSession()
                                         throws java.lang.Exception
        Close the session to the metadata service. This will immediately release all the resource locks held by this broker on the coordination service.
        Throws:
        java.lang.Exception - if the close operation fails
      • close

        public void close()
                   throws org.apache.pulsar.broker.PulsarServerException
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • closeAsync

        public java.util.concurrent.CompletableFuture<java.lang.Void> closeAsync()
        Close the current pulsar service. All resources are released.
      • getConfiguration

        public org.apache.pulsar.broker.ServiceConfiguration getConfiguration()
        Get the current service configuration.
        Returns:
        the current service configuration
      • getWorkerConfig

        public java.util.Optional<org.apache.pulsar.functions.worker.WorkerConfig> getWorkerConfig()
        Get the current function worker service configuration.
        Returns:
        the current function worker service configuration.
      • getProtocolDataToAdvertise

        public java.util.Map<java.lang.String,​java.lang.String> getProtocolDataToAdvertise()
      • start

        public void start()
                   throws org.apache.pulsar.broker.PulsarServerException
        Start the pulsar service instance.
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • createLocalMetadataStore

        public org.apache.pulsar.metadata.api.extended.MetadataStoreExtended createLocalMetadataStore()
                                                                                               throws org.apache.pulsar.metadata.api.MetadataStoreException
        Throws:
        org.apache.pulsar.metadata.api.MetadataStoreException
      • startLeaderElectionService

        protected void startLeaderElectionService()
      • acquireSLANamespace

        protected void acquireSLANamespace()
      • waitUntilClosed

        public void waitUntilClosed()
                             throws java.lang.InterruptedException
        Block until the service is finally closed.
        Throws:
        java.lang.InterruptedException
      • startNamespaceService

        protected void startNamespaceService()
                                      throws org.apache.pulsar.broker.PulsarServerException
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • getNamespaceServiceProvider

        public java.util.function.Supplier<NamespaceService> getNamespaceServiceProvider()
                                                                                  throws org.apache.pulsar.broker.PulsarServerException
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • startLoadManagementService

        protected void startLoadManagementService()
                                           throws org.apache.pulsar.broker.PulsarServerException
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • loadNamespaceTopics

        public void loadNamespaceTopics​(NamespaceBundle bundle)
        Load all the topics contained in a namespace.
        Parameters:
        bundle - NamespaceBundle to identify the service unit
        Throws:
        java.lang.Exception
      • getStatusFilePath

        public java.lang.String getStatusFilePath()
      • getMetadataServiceUri

        public java.lang.String getMetadataServiceUri()
        Get default bookkeeper metadata service uri.
      • getInternalConfigurationData

        public org.apache.pulsar.common.conf.InternalConfigurationData getInternalConfigurationData()
      • getLeaderElectionService

        public LeaderElectionService getLeaderElectionService()
        Get a reference of the current LeaderElectionService instance associated with the current PulsarService instance.
        Returns:
        a reference of the current LeaderElectionService instance.
      • getNamespaceService

        public NamespaceService getNamespaceService()
        Get a reference of the current namespace service instance.
        Returns:
        a reference of the current namespace service instance.
      • getWorkerServiceOpt

        public java.util.Optional<org.apache.pulsar.functions.worker.WorkerService> getWorkerServiceOpt()
      • getWorkerService

        public org.apache.pulsar.functions.worker.WorkerService getWorkerService()
                                                                          throws java.lang.UnsupportedOperationException
        Throws:
        java.lang.UnsupportedOperationException
      • getBrokerService

        public BrokerService getBrokerService()
        Get a reference of the current BrokerService instance associated with the current PulsarService instance.
        Returns:
        a reference of the current BrokerService instance.
      • getBookKeeperClient

        public org.apache.bookkeeper.client.BookKeeper getBookKeeperClient()
      • getManagedLedgerFactory

        public org.apache.bookkeeper.mledger.ManagedLedgerFactory getManagedLedgerFactory()
      • getManagedLedgerOffloader

        public org.apache.bookkeeper.mledger.LedgerOffloader getManagedLedgerOffloader​(org.apache.pulsar.common.naming.NamespaceName namespaceName,
                                                                                       org.apache.pulsar.common.policies.data.OffloadPoliciesImpl offloadPolicies)
        First, get LedgerOffloader from local map cache, create new LedgerOffloader if not in cache or the OffloadPolicies changed, return the LedgerOffloader directly if exist in cache and the OffloadPolicies not changed.
        Parameters:
        namespaceName - NamespaceName
        offloadPolicies - the OffloadPolicies
        Returns:
        LedgerOffloader
      • createManagedLedgerOffloader

        public org.apache.bookkeeper.mledger.LedgerOffloader createManagedLedgerOffloader​(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl offloadPolicies)
                                                                                   throws org.apache.pulsar.broker.PulsarServerException
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • getExecutor

        public java.util.concurrent.ScheduledExecutorService getExecutor()
      • getCacheExecutor

        public java.util.concurrent.ScheduledExecutorService getCacheExecutor()
      • getTransactionExecutorProvider

        public org.apache.pulsar.client.util.ExecutorProvider getTransactionExecutorProvider()
      • getLoadManagerExecutor

        public java.util.concurrent.ScheduledExecutorService getLoadManagerExecutor()
      • getOrderedExecutor

        public org.apache.bookkeeper.common.util.OrderedExecutor getOrderedExecutor()
      • getZooKeeperClientFactory

        public org.apache.pulsar.zookeeper.ZooKeeperClientFactory getZooKeeperClientFactory()
      • getCompactorExecutor

        protected java.util.concurrent.ScheduledExecutorService getCompactorExecutor()
      • newCompactor

        public Compactor newCompactor()
                               throws org.apache.pulsar.broker.PulsarServerException
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • getCompactor

        public Compactor getCompactor()
                               throws org.apache.pulsar.broker.PulsarServerException
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • getNullableCompactor

        public Compactor getNullableCompactor()
      • getOffloaderScheduler

        protected org.apache.bookkeeper.common.util.OrderedScheduler getOffloaderScheduler​(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl offloadPolicies)
      • createClientImpl

        public org.apache.pulsar.client.impl.PulsarClientImpl createClientImpl​(org.apache.pulsar.client.impl.conf.ClientConfigurationData clientConf)
                                                                        throws org.apache.pulsar.client.api.PulsarClientException
        Throws:
        org.apache.pulsar.client.api.PulsarClientException
      • getClient

        public org.apache.pulsar.client.api.PulsarClient getClient()
                                                            throws org.apache.pulsar.broker.PulsarServerException
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • getAdminClient

        public org.apache.pulsar.client.admin.PulsarAdmin getAdminClient()
                                                                  throws org.apache.pulsar.broker.PulsarServerException
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • getTransactionBufferClient

        public org.apache.pulsar.client.api.transaction.TransactionBufferClient getTransactionBufferClient()
      • brokerUrl

        protected java.lang.String brokerUrl​(org.apache.pulsar.broker.ServiceConfiguration config)
        Gets the broker service URL (non-TLS) associated with the internal listener.
      • brokerUrl

        public static java.lang.String brokerUrl​(java.lang.String host,
                                                 int port)
      • brokerUrlTls

        public java.lang.String brokerUrlTls​(org.apache.pulsar.broker.ServiceConfiguration config)
        Gets the broker service URL (TLS) associated with the internal listener.
      • brokerUrlTls

        public static java.lang.String brokerUrlTls​(java.lang.String host,
                                                    int port)
      • webAddress

        public java.lang.String webAddress​(org.apache.pulsar.broker.ServiceConfiguration config)
      • webAddress

        public static java.lang.String webAddress​(java.lang.String host,
                                                  int port)
      • webAddressTls

        public java.lang.String webAddressTls​(org.apache.pulsar.broker.ServiceConfiguration config)
      • webAddressTls

        public static java.lang.String webAddressTls​(java.lang.String host,
                                                     int port)
      • getSafeWebServiceAddress

        public java.lang.String getSafeWebServiceAddress()
      • getSafeBrokerServiceUrl

        @Deprecated
        public java.lang.String getSafeBrokerServiceUrl()
        Deprecated.
      • bookieMetadataServiceUri

        public static java.lang.String bookieMetadataServiceUri​(org.apache.pulsar.broker.ServiceConfiguration config)
        Get bookkeeper metadata service uri.
        Parameters:
        config - broker configuration
        Returns:
        the metadata service uri that bookkeeper is used
      • getPackagesManagement

        public org.apache.pulsar.packages.management.core.PackagesManagement getPackagesManagement()
                                                                                            throws java.lang.UnsupportedOperationException
        Throws:
        java.lang.UnsupportedOperationException
      • getListenPortHTTP

        public java.util.Optional<java.lang.Integer> getListenPortHTTP()
      • getListenPortHTTPS

        public java.util.Optional<java.lang.Integer> getListenPortHTTPS()
      • getBrokerListenPort

        public java.util.Optional<java.lang.Integer> getBrokerListenPort()
      • getBrokerListenPortTls

        public java.util.Optional<java.lang.Integer> getBrokerListenPortTls()
      • getLocalMetadataStore

        public org.apache.pulsar.metadata.api.extended.MetadataStoreExtended getLocalMetadataStore()
      • getCoordinationService

        public org.apache.pulsar.metadata.api.coordination.CoordinationService getCoordinationService()
      • initializeWorkerConfigFromBrokerConfig

        public static org.apache.pulsar.functions.worker.WorkerConfig initializeWorkerConfigFromBrokerConfig​(org.apache.pulsar.broker.ServiceConfiguration brokerConfig,
                                                                                                             java.lang.String workerConfigFile)
                                                                                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • shutdownNow

        public void shutdownNow()
        Shutdown the broker immediately, without waiting for all resources to be released. This possibly is causing the JVM process to exit, depending on how th PulsarService was constructed.
        Specified by:
        shutdownNow in interface org.apache.pulsar.broker.ShutdownService
      • isTransactionSystemTopic

        public static boolean isTransactionSystemTopic​(org.apache.pulsar.common.naming.TopicName topicName)
      • isTransactionInternalName

        public static boolean isTransactionInternalName​(org.apache.pulsar.common.naming.TopicName topicName)
      • newBrokerService

        protected BrokerService newBrokerService​(PulsarService pulsar)
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception