use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.
the class MetaDataFetcher method fetchMetadata.
public final void fetchMetadata(ConcurrentMap<String, RepairingHandler> handlers) {
if (handlers.isEmpty()) {
return;
}
List<String> mapNames = getNames(handlers);
List<InternalCompletableFuture> futures = scanMembers(mapNames);
for (InternalCompletableFuture future : futures) {
process(future, handlers);
}
}
use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.
the class ClientCacheMetaDataFetcher method scanMembers.
@Override
protected List<InternalCompletableFuture> scanMembers(List<String> names) {
Collection<Member> members = clusterService.getMembers(DATA_MEMBER_SELECTOR);
List<InternalCompletableFuture> futures = new ArrayList<InternalCompletableFuture>(members.size());
for (Member member : members) {
Address address = member.getAddress();
ClientMessage message = encodeRequest(names, address);
ClientInvocation invocation = new ClientInvocation(clientImpl, message, address);
try {
futures.add(invocation.invoke());
} catch (Exception e) {
if (logger.isWarningEnabled()) {
logger.warning("Cant fetch invalidation meta-data from address + " + address + " + [" + e.getMessage() + "]");
}
}
}
return futures;
}
use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.
the class MapReduceUtil method executeOperation.
public static <V> List<V> executeOperation(Collection<Member> members, OperationFactory operationFactory, MapReduceService mapReduceService, NodeEngine nodeEngine) {
final OperationService operationService = nodeEngine.getOperationService();
final List<InternalCompletableFuture<V>> futures = new ArrayList<InternalCompletableFuture<V>>();
final List<V> results = new ArrayList<V>();
final List<Exception> exceptions = new ArrayList<Exception>(members.size());
for (Member member : members) {
try {
Operation operation = operationFactory.createOperation();
if (nodeEngine.getThisAddress().equals(member.getAddress())) {
// Locally we can call the operation directly
operation.setNodeEngine(nodeEngine);
operation.setCallerUuid(nodeEngine.getLocalMember().getUuid());
operation.setService(mapReduceService);
operation.run();
V response = (V) operation.getResponse();
if (response != null) {
results.add(response);
}
} else {
InvocationBuilder ib = operationService.createInvocationBuilder(SERVICE_NAME, operation, member.getAddress());
final InternalCompletableFuture<V> future = ib.invoke();
futures.add(future);
}
} catch (Exception e) {
exceptions.add(e);
}
}
for (InternalCompletableFuture<V> future : futures) {
try {
V response = future.join();
if (response != null) {
results.add(response);
}
} catch (Exception e) {
exceptions.add(e);
}
}
if (exceptions.size() > 0) {
throw new RemoteMapReduceException("Exception on mapreduce operation", exceptions);
}
return results;
}
use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.
the class TotalOrderedTopicProxy method publish.
@Override
public void publish(Object message) {
Operation operation = new PublishOperation(getName(), toData(message)).setPartitionId(partitionId);
InternalCompletableFuture f = invokeOnPartition(operation);
f.join();
}
use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.
the class HazelcastServerCacheManager method createCacheConfig.
@Override
protected <K, V> CacheConfig<K, V> createCacheConfig(String cacheName, CacheConfig<K, V> config, boolean createAlsoOnOthers, boolean syncCreate) {
CacheConfig<K, V> currentCacheConfig = cacheService.getCacheConfig(cacheName);
OperationService operationService = nodeEngine.getOperationService();
// Create cache config on all nodes.
CacheCreateConfigOperation op = new CacheCreateConfigOperation(config, createAlsoOnOthers);
// Run "CacheCreateConfigOperation" on this node. Its itself handles interaction with other nodes.
// This operation doesn't block operation thread even "syncCreate" is specified.
// In that case, scheduled thread is used, not operation thread.
InternalCompletableFuture future = operationService.invokeOnTarget(CacheService.SERVICE_NAME, op, nodeEngine.getThisAddress());
if (syncCreate) {
return (CacheConfig<K, V>) future.join();
} else {
return currentCacheConfig;
}
}
Aggregations