Search in sources :

Example 1 with InternalCompletableFuture

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);
    }
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture)

Example 2 with InternalCompletableFuture

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;
}
Also used : Address(com.hazelcast.nio.Address) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ArrayList(java.util.ArrayList) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Member(com.hazelcast.core.Member) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with InternalCompletableFuture

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;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ArrayList(java.util.ArrayList) Operation(com.hazelcast.spi.Operation) NotifyRemoteExceptionOperation(com.hazelcast.mapreduce.impl.operation.NotifyRemoteExceptionOperation) RemoteMapReduceException(com.hazelcast.mapreduce.RemoteMapReduceException) TimeoutException(java.util.concurrent.TimeoutException) RemoteMapReduceException(com.hazelcast.mapreduce.RemoteMapReduceException) OperationService(com.hazelcast.spi.OperationService) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) Member(com.hazelcast.core.Member)

Example 4 with InternalCompletableFuture

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();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Operation(com.hazelcast.spi.Operation)

Example 5 with InternalCompletableFuture

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;
    }
}
Also used : CacheCreateConfigOperation(com.hazelcast.cache.impl.operation.CacheCreateConfigOperation) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) OperationService(com.hazelcast.spi.OperationService) CacheConfig(com.hazelcast.config.CacheConfig)

Aggregations

InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)17 Operation (com.hazelcast.spi.Operation)6 Data (com.hazelcast.nio.serialization.Data)5 ArrayList (java.util.ArrayList)5 ExecutionException (java.util.concurrent.ExecutionException)5 TimeoutException (java.util.concurrent.TimeoutException)5 Member (com.hazelcast.core.Member)4 Address (com.hazelcast.nio.Address)3 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)2 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)2 InvocationBuilder (com.hazelcast.spi.InvocationBuilder)2 OperationService (com.hazelcast.spi.OperationService)2 CacheCreateConfigOperation (com.hazelcast.cache.impl.operation.CacheCreateConfigOperation)1 AwaitOperation (com.hazelcast.concurrent.countdownlatch.operations.AwaitOperation)1 CountDownOperation (com.hazelcast.concurrent.countdownlatch.operations.CountDownOperation)1 GetCountOperation (com.hazelcast.concurrent.countdownlatch.operations.GetCountOperation)1 SetCountOperation (com.hazelcast.concurrent.countdownlatch.operations.SetCountOperation)1 BeforeAwaitOperation (com.hazelcast.concurrent.lock.operations.BeforeAwaitOperation)1 SignalOperation (com.hazelcast.concurrent.lock.operations.SignalOperation)1 AcquireOperation (com.hazelcast.concurrent.semaphore.operations.AcquireOperation)1