use of com.hazelcast.replicatedmap.impl.operation.GetOperation in project hazelcast by hazelcast.
the class TablesStorage method awaitMappingOnAllMembers.
/**
* Temporary measure to ensure schema is propagated to all the members.
*/
@SuppressWarnings("BusyWait")
private void awaitMappingOnAllMembers(String name, IdentifiedDataSerializable metadata) {
Data keyData = nodeEngine.getSerializationService().toData(name);
int keyPartitionId = nodeEngine.getPartitionService().getPartitionId(keyData);
OperationService operationService = nodeEngine.getOperationService();
Collection<Address> memberAddresses = getMemberAddresses();
for (int i = 0; i < MAX_CHECK_ATTEMPTS && !memberAddresses.isEmpty(); i++) {
List<CompletableFuture<Address>> futures = memberAddresses.stream().map(memberAddress -> {
Operation operation = new GetOperation(CATALOG_MAP_NAME, keyData).setPartitionId(keyPartitionId).setValidateTarget(false);
return operationService.createInvocationBuilder(ReplicatedMapService.SERVICE_NAME, operation, memberAddress).setTryCount(1).invoke().toCompletableFuture().thenApply(result -> Objects.equals(metadata, result) ? memberAddress : null);
}).collect(toList());
for (CompletableFuture<Address> future : futures) {
try {
memberAddresses.remove(future.join());
} catch (Exception e) {
logger.warning("Error occurred while trying to fetch mapping: " + e.getMessage(), e);
}
}
if (!memberAddresses.isEmpty()) {
try {
Thread.sleep(SLEEP_MILLIS);
} catch (InterruptedException e) {
break;
}
}
}
}
Aggregations