Skip to content

Commit 310c322

Browse files
authored
1114 reliabletopic terminate test failure [AP-1893] (#1122)
* ReliableTopic lifecycle is checked in `cancel()`
1 parent 3bab28c commit 310c322

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

hazelcast/include/hazelcast/client/reliable_topic.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ namespace client {
4949
* process m1, m2, m3...mn in order.
5050
*
5151
*/
52-
class HAZELCAST_API reliable_topic : public proxy::ProxyImpl
52+
class HAZELCAST_API reliable_topic
53+
: public proxy::ProxyImpl
54+
, public std::enable_shared_from_this<reliable_topic>
5355
{
5456
friend class spi::ProxyManager;
5557
friend class hazelcast_client;
@@ -106,7 +108,7 @@ class HAZELCAST_API reliable_topic : public proxy::ProxyImpl
106108
logger_,
107109
execution_service_,
108110
executor_,
109-
runners_map_));
111+
shared_from_this()));
110112
runners_map_.put(id, runner);
111113
runner->next();
112114
return std::to_string(id);
@@ -149,10 +151,9 @@ class HAZELCAST_API reliable_topic : public proxy::ProxyImpl
149151
int batch_size,
150152
logger& lg,
151153
std::shared_ptr<spi::impl::ClientExecutionServiceImpl>
152-
execution_service,
154+
execution_service,
153155
util::hz_thread_pool& executor,
154-
util::SynchronizedMap<int, util::concurrent::Cancellable>&
155-
runners_map)
156+
std::weak_ptr<reliable_topic> topic)
156157
: listener_(listener)
157158
, id_(id)
158159
, ringbuffer_(rb)
@@ -163,7 +164,7 @@ class HAZELCAST_API reliable_topic : public proxy::ProxyImpl
163164
, executor_(executor)
164165
, serialization_service_(service)
165166
, batch_size_(batch_size)
166-
, runners_map_(runners_map)
167+
, topic_(std::move(topic))
167168
{
168169
// we are going to listen to next publication. We don't care about
169170
// what already has been published.
@@ -334,7 +335,10 @@ class HAZELCAST_API reliable_topic : public proxy::ProxyImpl
334335
bool cancel() override
335336
{
336337
cancelled_.store(true);
337-
runners_map_.remove(id_);
338+
auto topic_ptr = topic_.lock();
339+
if (topic_ptr) {
340+
topic_ptr->runners_map_.remove(id_);
341+
}
338342
return true;
339343
}
340344

@@ -414,7 +418,7 @@ class HAZELCAST_API reliable_topic : public proxy::ProxyImpl
414418
util::hz_thread_pool& executor_;
415419
serialization::pimpl::SerializationService& serialization_service_;
416420
int batch_size_;
417-
util::SynchronizedMap<int, util::concurrent::Cancellable>& runners_map_;
421+
std::weak_ptr<reliable_topic> topic_;
418422
};
419423

420424
util::SynchronizedMap<int, util::concurrent::Cancellable> runners_map_;

0 commit comments

Comments
 (0)