Skip to content

Commit 5285efd

Browse files
committed
address comments
1 parent 1144c27 commit 5285efd

9 files changed

Lines changed: 25 additions & 24 deletions

File tree

include/pulsar/Client.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ class PULSAR_PUBLIC Client {
7878
* dynamically. For example, if it detects a primary Pulsar service is down, it can switch to a secondary
7979
* service and update the client with the new service information.
8080
*
81-
* When `close` is called, the client will call `ServiceInfoProvider::close` to guarantee the lifetime of
82-
* the provider is properly managed.
81+
* The Client instance takes ownership of the given ServiceInfoProvider. The provider will be destroyed
82+
* as part of the client's shutdown lifecycle, for example when `Client::close()` or
83+
* `Client::closeAsync()` is called, ensuring that its lifetime is properly managed.
8384
*/
8485
static Client create(std::unique_ptr<ServiceInfoProvider> serviceInfoProvider,
8586
const ClientConfiguration& clientConfiguration);

include/pulsar/ServiceInfoProvider.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#ifndef PULSAR_SERVICE_INFO_PROVIDER_H_
2020
#define PULSAR_SERVICE_INFO_PROVIDER_H_
2121

22-
#include <pulsar/ClientConfiguration.h>
2322
#include <pulsar/ServiceInfo.h>
2423

24+
#include <functional>
25+
2526
namespace pulsar {
2627

2728
class PULSAR_PUBLIC ServiceInfoProvider {
@@ -35,18 +36,23 @@ class PULSAR_PUBLIC ServiceInfoProvider {
3536
/**
3637
* Get the initial `ServiceInfo` connection for the client.
3738
* This method is called **only once** internally in `Client::create()` to get the initial `ServiceInfo`
38-
* for the client to connect to the Pulsar service. Since it's only called once, it's legal to return a
39-
* moved `ServiceInfo` object to avoid unnecessary copying.
39+
* for the client to connect to the Pulsar service, typically before {@link initialize} is invoked.
40+
* Since it's only called once, it's legal to return a moved `ServiceInfo` object to avoid unnecessary
41+
* copying.
4042
*/
4143
virtual ServiceInfo initialServiceInfo() = 0;
4244

4345
/**
4446
* Initialize the ServiceInfoProvider.
4547
*
46-
* @param onServiceInfoUpdate the callback to update `client` with the new `ServiceInfo`
48+
* After the client has obtained the initial `ServiceInfo` via {@link initialServiceInfo}, this method is
49+
* called to allow the provider to start any background work (for example, service discovery or watching
50+
* configuration changes) and to report subsequent updates to the service information.
51+
*
52+
* @param onServiceInfoUpdate the callback to deliver updated `ServiceInfo` values to the client after
53+
* the initial connection has been established
4754
*
48-
* Note: the implementation is responsible to invoke `onServiceInfoUpdate` at least once to provide the
49-
* initial `ServiceInfo` for the client.
55+
* Implementations may choose not to invoke `onServiceInfoUpdate` if the `ServiceInfo` never changes.
5056
*/
5157
virtual void initialize(std::function<void(ServiceInfo)> onServiceInfoUpdate) = 0;
5258
};

lib/ClientConnection.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ class PULSAR_PUBLIC ClientConnection : public std::enable_shared_from_this<Clien
157157
* Close the connection.
158158
*
159159
* @param result all pending futures will complete with this result
160-
* @param detach remove it from the pool if it's true
160+
* @param detach remove it from the pool if it's true. When false, the connection remains
161+
* associated with the pool but is logically closed; this is currently used when the
162+
* pool itself is being closed or when switching clusters.
161163
* @param switchCluster whether the close is triggered by cluster switching
162164
*
163165
* `detach` should only be false when the connection pool is closed.

lib/ClientImpl.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "Commands.h"
3535
#include "ConsumerImpl.h"
3636
#include "ConsumerInterceptors.h"
37-
#include "DefaultServiceUrlProvider.h"
37+
#include "DefaultServiceInfoProvider.h"
3838
#include "ExecutorService.h"
3939
#include "HTTPLookupService.h"
4040
#include "LogUtils.h"
@@ -97,8 +97,8 @@ ClientImpl::ClientImpl(const std::string& serviceUrl, const ClientConfiguration&
9797

9898
ClientImpl::ClientImpl(const std::string& serviceUrl, const ClientConfiguration& clientConfiguration,
9999
LookupServiceFactory&& lookupServiceFactory)
100-
: ClientImpl(std::make_unique<DefaultServiceUrlProvider>(std::cref(serviceUrl),
101-
std::cref(*clientConfiguration.impl_)),
100+
: ClientImpl(std::make_unique<DefaultServiceInfoProvider>(std::cref(serviceUrl),
101+
std::cref(*clientConfiguration.impl_)),
102102
clientConfiguration, std::move(lookupServiceFactory)) {}
103103

104104
ClientImpl::ClientImpl(std::unique_ptr<ServiceInfoProvider> serviceInfoProvider,

lib/ClientImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class ClientImpl : public std::enable_shared_from_this<ClientImpl> {
206206
const std::string& logicalAddress);
207207

208208
// This overload is only used for blue-green migration, where only the service URL is modified, the other
209-
// paramters remain the same
209+
// parameters remain the same
210210
LookupServicePtr createRedirectedLookup(const std::string& redirectedUrl) {
211211
auto serviceInfo = serviceInfo_.load();
212212
return createLookup(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
namespace pulsar {
2828

29-
class DefaultServiceUrlProvider : public ServiceInfoProvider {
29+
class DefaultServiceInfoProvider : public ServiceInfoProvider {
3030
public:
31-
DefaultServiceUrlProvider(const std::string& serviceUrl, const ClientConfigurationImpl& config)
31+
DefaultServiceInfoProvider(const std::string& serviceUrl, const ClientConfigurationImpl& config)
3232
: serviceInfo_(config.toServiceInfo(serviceUrl)) {}
3333

3434
ServiceInfo initialServiceInfo() override { return std::move(serviceInfo_); }

perf/PerfConsumer.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ static int64_t currentTimeMillis() {
5757
struct Arguments {
5858
std::string authParams;
5959
std::string authPlugin;
60-
bool isUseTls;
6160
bool isTlsAllowInsecureConnection;
6261
std::string tlsTrustCertsFilePath;
6362
std::string topic;
@@ -261,9 +260,6 @@ int main(int argc, char** argv) {
261260
("auth-plugin,a", po::value<std::string>(&args.authPlugin)->default_value(""),
262261
"Authentication plugin class library path") //
263262

264-
("use-tls,b", po::value<bool>(&args.isUseTls)->default_value(false),
265-
"Whether tls connection is used") //
266-
267263
("allow-insecure,d", po::value<bool>(&args.isTlsAllowInsecureConnection)->default_value(true),
268264
"Whether insecure tls connection is allowed") //
269265

perf/PerfProducer.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ typedef std::shared_ptr<pulsar::RateLimiter> RateLimiterPtr;
4747
struct Arguments {
4848
std::string authParams;
4949
std::string authPlugin;
50-
bool isUseTls;
5150
bool isTlsAllowInsecureConnection;
5251
std::string tlsTrustCertsFilePath;
5352
std::string topic;
@@ -223,9 +222,6 @@ int main(int argc, char** argv) {
223222
("auth-plugin,a", po::value<std::string>(&args.authPlugin)->default_value(""),
224223
"Authentication plugin class library path") //
225224

226-
("use-tls,b", po::value<bool>(&args.isUseTls)->default_value(false),
227-
"Whether tls connection is used") //
228-
229225
("allow-insecure,d", po::value<bool>(&args.isTlsAllowInsecureConnection)->default_value(true),
230226
"Whether insecure tls connection is allowed") //
231227

tests/ServiceInfoProviderTest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class TestServiceInfoProvider : public ServiceInfoProvider {
9494
};
9595

9696
TEST(ServiceInfoProviderTest, testSwitchCluster) {
97-
extern std::string getToken(); // from tests/AuthToken.cc
97+
extern std::string getToken(); // from tests/AuthTokenTest.cc
9898
// Access "private/auth" namespace in cluster 1
9999
ServiceInfo info1{"pulsar://localhost:6650", AuthToken::createWithToken(getToken())};
100100
// Access "private/auth" namespace in cluster 2

0 commit comments

Comments
 (0)