Package org.apache.pulsar.broker
Class PulsarService
- java.lang.Object
-
- org.apache.pulsar.broker.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.ShutdownServiceMain class for Pulsar broker service.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPulsarService.State
-
Field Summary
Fields Modifier and Type Field Description protected io.netty.channel.EventLoopGroupioEventLoopGroup
-
Constructor Summary
Constructors Constructor Description PulsarService(org.apache.pulsar.broker.ServiceConfiguration config)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(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 Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidacquireSLANamespace()voidaddPrometheusRawMetricsProvider(org.apache.pulsar.broker.stats.prometheus.PrometheusRawMetricsProvider metricsProvider)static java.lang.StringbrokerUrl(java.lang.String host, int port)protected java.lang.StringbrokerUrl(org.apache.pulsar.broker.ServiceConfiguration config)Gets the broker service URL (non-TLS) associated with the internal listener.static java.lang.StringbrokerUrlTls(java.lang.String host, int port)java.lang.StringbrokerUrlTls(org.apache.pulsar.broker.ServiceConfiguration config)Gets the broker service URL (TLS) associated with the internal listener.voidclose()java.util.concurrent.CompletableFuture<java.lang.Void>closeAsync()Close the current pulsar service.protected voidcloseLocalMetadataStore()voidcloseMetadataServiceSession()Close the session to the metadata service.org.apache.pulsar.client.impl.PulsarClientImplcreateClientImpl(org.apache.pulsar.client.impl.conf.ClientConfigurationData clientConf)org.apache.pulsar.metadata.api.MetadataStorecreateConfigurationMetadataStore()org.apache.pulsar.metadata.api.extended.MetadataStoreExtendedcreateLocalMetadataStore()org.apache.bookkeeper.mledger.LedgerOffloadercreateManagedLedgerOffloader(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl offloadPolicies)org.apache.pulsar.client.admin.PulsarAdmingetAdminClient()org.apache.bookkeeper.client.BookKeepergetBookKeeperClient()BookKeeperClientFactorygetBookKeeperClientFactory()java.util.Optional<java.lang.Integer>getBrokerListenPort()java.util.Optional<java.lang.Integer>getBrokerListenPortTls()BrokerServicegetBrokerService()Get a reference of the currentBrokerServiceinstance associated with the currentPulsarServiceinstance.java.util.concurrent.ScheduledExecutorServicegetCacheExecutor()org.apache.pulsar.client.api.PulsarClientgetClient()CompactorgetCompactor()protected java.util.concurrent.ScheduledExecutorServicegetCompactorExecutor()org.apache.pulsar.broker.ServiceConfigurationgetConfiguration()Get the current service configuration.org.apache.pulsar.metadata.api.coordination.CoordinationServicegetCoordinationService()java.util.concurrent.ScheduledExecutorServicegetExecutor()org.apache.pulsar.common.conf.InternalConfigurationDatagetInternalConfigurationData()LeaderElectionServicegetLeaderElectionService()Get a reference of the currentLeaderElectionServiceinstance associated with the currentPulsarServiceinstance.java.util.Optional<java.lang.Integer>getListenPortHTTP()java.util.Optional<java.lang.Integer>getListenPortHTTPS()java.util.concurrent.ScheduledExecutorServicegetLoadManagerExecutor()org.apache.pulsar.metadata.api.extended.MetadataStoreExtendedgetLocalMetadataStore()ManagedLedgerStoragegetManagedLedgerClientFactory()org.apache.bookkeeper.mledger.ManagedLedgerFactorygetManagedLedgerFactory()org.apache.bookkeeper.mledger.LedgerOffloadergetManagedLedgerOffloader(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.policies.data.OffloadPoliciesImpl offloadPolicies)First, getLedgerOffloaderfrom local map cache, create newLedgerOffloaderif not in cache or theOffloadPolicieschanged, return theLedgerOffloaderdirectly if exist in cache and theOffloadPoliciesnot changed.MetricsGeneratorgetMetricsGenerator()NamespaceServicegetNamespaceService()Get a reference of the current namespace service instance.java.util.function.Supplier<NamespaceService>getNamespaceServiceProvider()CompactorgetNullableCompactor()protected org.apache.bookkeeper.common.util.OrderedSchedulergetOffloaderScheduler(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl offloadPolicies)org.apache.bookkeeper.common.util.OrderedExecutorgetOrderedExecutor()org.apache.pulsar.packages.management.core.PackagesManagementgetPackagesManagement()java.util.Map<java.lang.String,java.lang.String>getProtocolDataToAdvertise()ResourceUsageTransportManagergetResourceUsageTransportManager()java.lang.StringgetSafeBrokerServiceUrl()Deprecated.java.lang.StringgetSafeWebServiceAddress()PulsarService.StategetState()Get the current pulsar state.java.lang.StringgetStatusFilePath()TopicPoliciesServicegetTopicPoliciesService()org.apache.pulsar.client.api.transaction.TransactionBufferClientgetTransactionBufferClient()TransactionBufferProvidergetTransactionBufferProvider()org.apache.pulsar.client.util.ExecutorProvidergetTransactionExecutorProvider()TransactionMetadataStoreServicegetTransactionMetadataStoreService()java.util.Optional<org.apache.pulsar.functions.worker.WorkerConfig>getWorkerConfig()Get the current function worker service configuration.org.apache.pulsar.functions.worker.WorkerServicegetWorkerService()java.util.Optional<org.apache.pulsar.functions.worker.WorkerService>getWorkerServiceOpt()static org.apache.pulsar.functions.worker.WorkerConfiginitializeWorkerConfigFromBrokerConfig(org.apache.pulsar.broker.ServiceConfiguration brokerConfig, java.lang.String workerConfigFile)static booleanisTransactionInternalName(org.apache.pulsar.common.naming.TopicName topicName)static booleanisTransactionSystemTopic(org.apache.pulsar.common.naming.TopicName topicName)voidloadNamespaceTopics(NamespaceBundle bundle)Load all the topics contained in a namespace.BookKeeperClientFactorynewBookKeeperClientFactory()protected BrokerServicenewBrokerService(PulsarService pulsar)CompactornewCompactor()voidshutdownNow()Shutdown the broker immediately, without waiting for all resources to be released.voidstart()Start the pulsar service instance.protected voidstartLeaderElectionService()protected voidstartLoadManagementService()protected voidstartNamespaceService()voidwaitUntilClosed()Block until the service is finally closed.static java.lang.StringwebAddress(java.lang.String host, int port)java.lang.StringwebAddress(org.apache.pulsar.broker.ServiceConfiguration config)static java.lang.StringwebAddressTls(java.lang.String host, int port)java.lang.StringwebAddressTls(org.apache.pulsar.broker.ServiceConfiguration config)
-
-
-
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.ExceptionClose 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:
closein interfacejava.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.PulsarServerExceptionStart 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
-
closeLocalMetadataStore
protected void closeLocalMetadataStore() throws java.lang.Exception- Throws:
java.lang.Exception
-
startLeaderElectionService
protected void startLeaderElectionService()
-
acquireSLANamespace
protected void acquireSLANamespace()
-
waitUntilClosed
public void waitUntilClosed() throws java.lang.InterruptedExceptionBlock 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-NamespaceBundleto identify the service unit- Throws:
java.lang.Exception
-
getStatusFilePath
public java.lang.String getStatusFilePath()
-
getInternalConfigurationData
public org.apache.pulsar.common.conf.InternalConfigurationData getInternalConfigurationData()
-
getState
public PulsarService.State getState()
Get the current pulsar state.
-
getLeaderElectionService
public LeaderElectionService getLeaderElectionService()
Get a reference of the currentLeaderElectionServiceinstance associated with the currentPulsarServiceinstance.- Returns:
- a reference of the current
LeaderElectionServiceinstance.
-
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 currentBrokerServiceinstance associated with the currentPulsarServiceinstance.- Returns:
- a reference of the current
BrokerServiceinstance.
-
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, getLedgerOffloaderfrom local map cache, create newLedgerOffloaderif not in cache or theOffloadPolicieschanged, return theLedgerOffloaderdirectly if exist in cache and theOffloadPoliciesnot changed.- Parameters:
namespaceName- NamespaceNameoffloadPolicies- 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()
-
newBookKeeperClientFactory
public BookKeeperClientFactory newBookKeeperClientFactory()
-
getBookKeeperClientFactory
public BookKeeperClientFactory getBookKeeperClientFactory()
-
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
-
getMetricsGenerator
public MetricsGenerator getMetricsGenerator()
-
getTransactionMetadataStoreService
public TransactionMetadataStoreService getTransactionMetadataStoreService()
-
getTransactionBufferProvider
public TransactionBufferProvider getTransactionBufferProvider()
-
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.
-
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 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:
shutdownNowin interfaceorg.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
-
-