Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hazelcast/include/hazelcast/client/HazelcastClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ namespace hazelcast {

ClientConfig clientConfig;
ClientProperties clientProperties;
util::CountDownLatch shutdownLatch;
spi::ClientContext clientContext;
spi::LifecycleService lifecycleService;
serialization::pimpl::SerializationService serializationService;
Expand Down
5 changes: 3 additions & 2 deletions hazelcast/include/hazelcast/client/spi/LifecycleService.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ namespace hazelcast {
class HAZELCAST_API LifecycleService {
public:

LifecycleService(ClientContext &clientContext, const ClientConfig &clientConfig);
LifecycleService(ClientContext &clientContext, const ClientConfig &clientConfig,
util::CountDownLatch &shutdownLatch);

virtual ~LifecycleService();

Expand All @@ -68,7 +69,7 @@ namespace hazelcast {
std::set<LifecycleListener *> listeners;
util::Mutex listenerLock;
util::AtomicBoolean active;
util::CountDownLatch shutdownLatch;
util::CountDownLatch &shutdownLatch;
};

}
Expand Down
9 changes: 8 additions & 1 deletion hazelcast/src/hazelcast/client/HazelcastClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ namespace hazelcast {
HazelcastClient::HazelcastClient(ClientConfig &config)
: clientConfig(config)
, clientProperties(config)
, shutdownLatch(1)
, clientContext(*this)
, lifecycleService(clientContext, clientConfig)
, lifecycleService(clientContext, clientConfig, shutdownLatch)
, serializationService(config.getSerializationConfig())
, connectionManager(new connection::ConnectionManager(clientContext, clientConfig.isSmart()))
, nearCacheManager(serializationService)
Expand Down Expand Up @@ -65,6 +66,12 @@ namespace hazelcast {

HazelcastClient::~HazelcastClient() {
lifecycleService.shutdown();
/**
* We can not depend on the destruction order of the variables. lifecycleService may be destructed later
* than the clientContext which is accessed by different service threads, hence we need to explicitly wait
* for shutdown completion.
*/
shutdownLatch.await();
}


Expand Down
6 changes: 3 additions & 3 deletions hazelcast/src/hazelcast/client/spi/LifecycleService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ namespace hazelcast {
namespace client {
namespace spi {

LifecycleService::LifecycleService(ClientContext &clientContext, const ClientConfig &clientConfig)
LifecycleService::LifecycleService(ClientContext &clientContext, const ClientConfig &clientConfig,
util::CountDownLatch &shutdownLatch)
:clientContext(clientContext)
, active(true), shutdownLatch(1) {
, active(true), shutdownLatch(shutdownLatch) {
std::set<LifecycleListener *> const &lifecycleListeners = clientConfig.getLifecycleListeners();
listeners.insert(lifecycleListeners.begin(), lifecycleListeners.end());

}

bool LifecycleService::start() {
Expand Down