Class PulsarService

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

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

    • ioEventLoopGroup

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

    • PulsarService

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

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

      public PulsarService(org.apache.pulsar.broker.ServiceConfiguration config, org.apache.pulsar.functions.worker.WorkerConfig workerConfig, Optional<org.apache.pulsar.functions.worker.WorkerService> functionWorkerService, Consumer<Integer> processTerminator)
  • Method Details

    • createConfigurationMetadataStore

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

      public void closeMetadataServiceSession() throws 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:
      Exception - if the close operation fails
    • close

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

      public CompletableFuture<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 Optional<org.apache.pulsar.functions.worker.WorkerConfig> getWorkerConfig()
      Get the current function worker service configuration.
      Returns:
      the current function worker service configuration.
    • getProtocolDataToAdvertise

      public Map<String,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(PulsarMetadataEventSynchronizer synchronizer) throws org.apache.pulsar.metadata.api.MetadataStoreException, org.apache.pulsar.broker.PulsarServerException
      Throws:
      org.apache.pulsar.metadata.api.MetadataStoreException
      org.apache.pulsar.broker.PulsarServerException
    • closeLocalMetadataStore

      protected void closeLocalMetadataStore() throws Exception
      Throws:
      Exception
    • startLeaderElectionService

      protected void startLeaderElectionService()
    • acquireSLANamespace

      protected void acquireSLANamespace()
    • waitUntilClosed

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

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

      public 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:
      Exception
    • getStatusFilePath

      public String getStatusFilePath()
    • getInternalConfigurationData

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

      public PulsarService.State getState()
      Get the current pulsar state.
    • isRunning

      public boolean isRunning()
      check the current pulsar service is running, including Started and Init state.
    • 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 Optional<org.apache.pulsar.functions.worker.WorkerService> getWorkerServiceOpt()
    • getWorkerService

      public org.apache.pulsar.functions.worker.WorkerService getWorkerService() throws UnsupportedOperationException
      Throws:
      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()
    • getManagedLedgerClientFactory

      public ManagedLedgerStorage getManagedLedgerClientFactory()
    • 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 ScheduledExecutorService getExecutor()
    • getCacheExecutor

      public ScheduledExecutorService getCacheExecutor()
    • getTransactionExecutorProvider

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

      public ScheduledExecutorService getLoadManagerExecutor()
    • getOrderedExecutor

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

      public BookKeeperClientFactory newBookKeeperClientFactory()
    • getBookKeeperClientFactory

      public BookKeeperClientFactory getBookKeeperClientFactory()
    • getCompactorExecutor

      protected 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
    • getMetricsGenerator

      public MetricsGenerator getMetricsGenerator()
    • getTransactionMetadataStoreService

      public TransactionMetadataStoreService getTransactionMetadataStoreService()
    • getTransactionBufferProvider

      public TransactionBufferProvider getTransactionBufferProvider()
    • getTransactionBufferClient

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

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

      public static String brokerUrl(String host, int port)
    • brokerUrlTls

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

      public static String brokerUrlTls(String host, int port)
    • webAddress

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

      public static String webAddress(String host, int port)
    • webAddressTls

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

      public static String webAddressTls(String host, int port)
    • getSafeWebServiceAddress

      public String getSafeWebServiceAddress()
    • getSafeBrokerServiceUrl

      @Deprecated public String getSafeBrokerServiceUrl()
      Deprecated.
    • getTopicPoliciesService

      public TopicPoliciesService getTopicPoliciesService()
    • getResourceUsageTransportManager

      public ResourceUsageTransportManager getResourceUsageTransportManager()
    • addPrometheusRawMetricsProvider

      public void addPrometheusRawMetricsProvider(org.apache.pulsar.broker.stats.prometheus.PrometheusRawMetricsProvider metricsProvider)
    • getPackagesManagement

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

      public Optional<Integer> getListenPortHTTP()
    • getListenPortHTTPS

      public Optional<Integer> getListenPortHTTPS()
    • getBrokerListenPort

      public Optional<Integer> getBrokerListenPort()
    • getBrokerListenPortTls

      public Optional<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, String workerConfigFile) throws IOException
      Throws:
      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
    • newBrokerService

      protected BrokerService newBrokerService(PulsarService pulsar) throws Exception
      Throws:
      Exception