Skip to content

Commit eda576d

Browse files
committed
Merge pull request #62 from ihsandemir/revertPartitionRefreshThread
Revert the thread usage for partition refreshing
2 parents 9beb682 + 7272797 commit eda576d

File tree

3 files changed

+28
-51
lines changed

3 files changed

+28
-51
lines changed

hazelcast/include/hazelcast/client/spi/PartitionService.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ namespace hazelcast {
4848

4949
namespace serialization {
5050
namespace pimpl {
51-
class SerializationService;
52-
5351
class Data;
5452
}
5553
}
@@ -72,11 +70,6 @@ namespace hazelcast {
7270

7371
int getPartitionId(const serialization::pimpl::Data &key);
7472

75-
/**
76-
* @return The total number of partitions in the cluster.
77-
*/
78-
int getPartitionCount();
79-
8073
/**
8174
* Refreshes the partition
8275
*/
@@ -100,17 +93,13 @@ namespace hazelcast {
10093

10194
void runListener(util::Thread* currentThread);
10295

103-
void runRefresher();
104-
10596
std::auto_ptr<protocol::ClientMessage> getPartitionsFrom(const Address &address);
10697

10798
std::auto_ptr<protocol::ClientMessage> getPartitionsFrom();
10899

109100
bool processPartitionResponse(protocol::ClientMessage &response);
110101

111102
bool getInitialPartitions();
112-
113-
static void refreshTask(util::ThreadArgs &args);
114103
};
115104
}
116105
}

hazelcast/src/hazelcast/client/spi/PartitionService.cpp

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,13 @@ namespace hazelcast {
8888
if (!clientContext.getLifecycleService().isRunning()) {
8989
break;
9090
}
91-
runRefresher();
91+
refreshPartitions();
9292
} catch (exception::IException& e) {
9393
util::ILogger::getLogger().warning(std::string("PartitionService::runListener") + e.what());
9494
}
9595
}
9696
}
9797

98-
void PartitionService::runRefresher() {
99-
100-
if (updating.compareAndSet(false, true)) {
101-
try {
102-
std::auto_ptr<protocol::ClientMessage> partitionResponse;
103-
std::auto_ptr<Address> ptr = clientContext.getClusterService().getMasterAddress();
104-
if (ptr.get() == NULL) {
105-
partitionResponse = getPartitionsFrom();
106-
} else {
107-
partitionResponse = getPartitionsFrom(*ptr.get());
108-
}
109-
if (partitionResponse.get() != NULL) {
110-
processPartitionResponse(*partitionResponse);
111-
}
112-
} catch (hazelcast::client::exception::IException& e) {
113-
util::ILogger::getLogger().finest(std::string("Exception partitionService::runRefresher ") + e.what());
114-
} catch (...) {
115-
util::ILogger::getLogger().finest(std::string("Unkown exception partitionService::runRefresher "));
116-
throw;
117-
}
118-
updating = false;
119-
}
120-
121-
}
122-
12398
std::auto_ptr<protocol::ClientMessage> PartitionService::getPartitionsFrom(const Address& address) {
12499
std::auto_ptr<protocol::ClientMessage> responseMessage;
125100
try {
@@ -165,7 +140,7 @@ namespace hazelcast {
165140
}
166141
}
167142

168-
int newPartionCount = newPartitions->size();
143+
int newPartionCount = (int)newPartitions->size();
169144
if (newPartionCount > 0) {
170145
util::LockGuard lg(lock);
171146

@@ -204,19 +179,28 @@ namespace hazelcast {
204179
return result;
205180
}
206181

207-
208-
int PartitionService::getPartitionCount() {
209-
return partitionCount;
210-
}
211-
212-
// TODO: Implement using executor as done in java
182+
// TODO: Implement using executor as done in java (especially when the separate owner connection implementation is changed)
213183
void PartitionService::refreshPartitions() {
214-
util::Thread t(refreshTask, this);
215-
}
216-
217-
void PartitionService::refreshTask(util::ThreadArgs &args) {
218-
PartitionService *partitionSrv = (PartitionService *)args.arg0;
219-
partitionSrv->runRefresher();
184+
if (updating.compareAndSet(false, true)) {
185+
try {
186+
std::auto_ptr<protocol::ClientMessage> partitionResponse;
187+
std::auto_ptr<Address> ptr = clientContext.getClusterService().getMasterAddress();
188+
if (ptr.get() == NULL) {
189+
partitionResponse = getPartitionsFrom();
190+
} else {
191+
partitionResponse = getPartitionsFrom(*ptr.get());
192+
}
193+
if (partitionResponse.get() != NULL) {
194+
processPartitionResponse(*partitionResponse);
195+
}
196+
} catch (hazelcast::client::exception::IException& e) {
197+
util::ILogger::getLogger().finest(std::string("Exception in partitionService::refreshPartitions ") + e.what());
198+
} catch (...) {
199+
util::ILogger::getLogger().finest(std::string("Unkown exception in partitionService::refreshPartitions "));
200+
throw;
201+
}
202+
updating = false;
203+
}
220204
}
221205
}
222206
}

java/src/main/resources/hazelcast.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646
<multicast-port>54327</multicast-port>
4747
</multicast>
4848
<tcp-ip enabled="true">
49-
<interface>127.0.0.1</interface>
49+
<interface>127.0.0.1:5701</interface>
50+
<interface>127.0.0.1:5702</interface>
51+
<interface>127.0.0.1:5703</interface>
52+
<interface>127.0.0.1:5704</interface>
53+
<interface>127.0.0.1:5705</interface>
5054
</tcp-ip>
5155
<aws enabled="false">
5256
<access-key>my-access-key</access-key>

0 commit comments

Comments
 (0)