Skip to content

Commit 7f002f5

Browse files
committed
authenticatedChannelFactory use eventscheduler from application
Signed-off-by: Emelia Lei <[email protected]>
1 parent 5577693 commit 7f002f5

File tree

3 files changed

+21
-36
lines changed

3 files changed

+21
-36
lines changed

src/groups/bmq/bmqimp/bmqimp_application.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,12 @@ Application::Application(
606606
allocator)
607607
, d_authenticatedChannelFactory(
608608
AuthenticatedChannelFactoryConfig(&d_statChannelFactory,
609+
&d_scheduler,
609610
sessionOptions.authnCredentialCb(),
610611
sessionOptions.connectTimeout(),
611612
d_blobSpPool_sp.get(),
612-
allocator))
613+
allocator),
614+
allocator)
613615
, d_negotiatedChannelFactory(
614616
NegotiatedChannelFactoryConfig(&d_authenticatedChannelFactory,
615617
negotiationMessage,

src/groups/bmq/bmqimp/bmqimp_authenticatedchannelfactory.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,29 @@ enum RcEnum {
7373

7474
AuthenticatedChannelFactoryConfig::AuthenticatedChannelFactoryConfig(
7575
bmqio::ChannelFactory* base,
76+
bdlmt::EventScheduler* scheduler,
7677
AuthnCredentialCb authnCredentialCb,
7778
const bsls::TimeInterval& authenticationTimeout,
7879
BlobSpPool* blobSpPool_p,
7980
bslma::Allocator* basicAllocator)
8081
: d_baseFactory_p(base)
82+
, d_scheduler_p(scheduler)
8183
, d_authnCredentialCb(authnCredentialCb)
8284
, d_authenticationTimeout(authenticationTimeout)
8385
, d_blobSpPool_p(blobSpPool_p)
8486
, d_allocator_p(bslma::Default::allocator(basicAllocator))
8587
{
8688
// PRECONDITIONS
8789
BSLS_ASSERT(base);
90+
BSLS_ASSERT_SAFE(d_scheduler_p->clockType() ==
91+
bsls::SystemClockType::e_MONOTONIC);
8892
}
8993

9094
AuthenticatedChannelFactoryConfig::AuthenticatedChannelFactoryConfig(
9195
const AuthenticatedChannelFactoryConfig& original,
9296
bslma::Allocator* basicAllocator)
9397
: d_baseFactory_p(original.d_baseFactory_p)
98+
, d_scheduler_p(original.d_scheduler_p)
9499
, d_authnCredentialCb(original.d_authnCredentialCb)
95100
, d_authenticationTimeout(original.d_authenticationTimeout)
96101
, d_blobSpPool_p(original.d_blobSpPool_p)
@@ -342,8 +347,8 @@ void AuthenticatedChannelFactory::onBrokerAuthenticationResponse(
342347
const int intervalMs = bsl::min(intervalMsWithRatio,
343348
intervalMsWithBuffer);
344349

345-
d_scheduler.scheduleRecurringEvent(
346-
&d_authnEventHandle,
350+
// Pening events will be cancelled when Application stops.
351+
d_config.d_scheduler_p->scheduleRecurringEvent(
347352
bsls::TimeInterval(intervalMs),
348353
bdlf::BindUtil::bind(
349354
bmqu::WeakMemFnUtil::weakMemFn(
@@ -361,8 +366,6 @@ AuthenticatedChannelFactory::AuthenticatedChannelFactory(
361366
const Config& config,
362367
bslma::Allocator* basicAllocator)
363368
: d_config(config, basicAllocator)
364-
, d_scheduler(bsls::SystemClockType::e_MONOTONIC, basicAllocator)
365-
, d_authnEventHandle()
366369
, d_self(this) // use default allocator
367370
{
368371
// NOTHING
@@ -375,22 +378,6 @@ AuthenticatedChannelFactory::~AuthenticatedChannelFactory()
375378
d_self.invalidate();
376379
}
377380

378-
int AuthenticatedChannelFactory::start()
379-
{
380-
int rc = d_scheduler.start();
381-
if (rc != 0) {
382-
BALL_LOG_ERROR << "Failed to start event scheduler [rc: " << rc << "]";
383-
}
384-
return rc;
385-
}
386-
387-
void AuthenticatedChannelFactory::stop()
388-
{
389-
// Cancel any scheduled reauthentication events
390-
d_scheduler.cancelEvent(&d_authnEventHandle);
391-
d_scheduler.stop();
392-
}
393-
394381
// MANIPULATORS
395382
void AuthenticatedChannelFactory::listen(
396383
BSLA_UNUSED bmqio::Status* status,

src/groups/bmq/bmqimp/bmqimp_authenticatedchannelfactory.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ class AuthenticatedChannelFactoryConfig {
6767
private:
6868
// PRIVATE DATA
6969
bmqio::ChannelFactory* d_baseFactory_p;
70-
AuthnCredentialCb d_authnCredentialCb;
71-
bsls::TimeInterval d_authenticationTimeout;
72-
BlobSpPool* d_blobSpPool_p;
73-
bslma::Allocator* d_allocator_p;
70+
71+
/// Used to schedule events for sending reauthentication requests.
72+
/// Held, not owned.
73+
bdlmt::EventScheduler* d_scheduler_p;
74+
75+
AuthnCredentialCb d_authnCredentialCb;
76+
bsls::TimeInterval d_authenticationTimeout;
77+
BlobSpPool* d_blobSpPool_p;
78+
bslma::Allocator* d_allocator_p;
7479

7580
// FRIENDS
7681
friend class AuthenticatedChannelFactory;
@@ -83,6 +88,7 @@ class AuthenticatedChannelFactoryConfig {
8388
// CREATORS
8489
AuthenticatedChannelFactoryConfig(
8590
bmqio::ChannelFactory* base,
91+
bdlmt::EventScheduler* scheduler,
8692
AuthnCredentialCb authnCredentialCb,
8793
const bsls::TimeInterval& authenticationTimeout,
8894
BlobSpPool* blobSpPool_p,
@@ -118,13 +124,7 @@ class AuthenticatedChannelFactory : public bmqio::ChannelFactory {
118124
// PRIVATE DATA
119125
Config d_config;
120126

121-
// Used to schedule events for sending reauthentication requests.
122-
bdlmt::EventScheduler d_scheduler;
123-
124-
// Event handle for reauthentication events.
125-
EventHandle d_authnEventHandle;
126-
127-
// Used to make sure no callback is invoked on a destroyed object.
127+
/// Used to make sure no callback is invoked on a destroyed object.
128128
mutable bmqu::SharedResource<AuthenticatedChannelFactory> d_self;
129129

130130
// NOT IMPLEMENTED
@@ -176,10 +176,6 @@ class AuthenticatedChannelFactory : public bmqio::ChannelFactory {
176176

177177
public:
178178
// MANIPULATORS
179-
int start();
180-
181-
void stop();
182-
183179
void listen(bmqio::Status* status,
184180
bslma::ManagedPtr<OpHandle>* handle,
185181
const bmqio::ListenOptions& options,

0 commit comments

Comments
 (0)