Search in sources :

Example 11 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class AbstractMapQueryMessageTask method createInvocations.

private List<Future> createInvocations(Collection<Member> members, Predicate predicate) {
    List<Future> futures = new ArrayList<>(members.size());
    final OperationServiceImpl operationService = nodeEngine.getOperationService();
    final Query query = buildQuery(predicate);
    MapService mapService = nodeEngine.getService(getServiceName());
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    for (Member member : members) {
        try {
            Future future = operationService.createInvocationBuilder(SERVICE_NAME, createQueryOperation(query, mapServiceContext), member.getAddress()).invoke();
            futures.add(future);
        } catch (Throwable t) {
            if (!(t instanceof HazelcastException)) {
                // these are programmatic errors that needs to be visible
                throw rethrow(t);
            } else if (t.getCause() instanceof QueryResultSizeExceededException) {
                throw rethrow(t);
            } else {
                // the missing partition IDs will be queried anyway, so it's not a terminal failure
                if (logger.isFineEnabled()) {
                    logger.fine("Query invocation failed on member " + member, t);
                }
            }
        }
    }
    return futures;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Query(com.hazelcast.map.impl.query.Query) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) MapService(com.hazelcast.map.impl.MapService) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException) Member(com.hazelcast.cluster.Member) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 12 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class ExecutionCallbackAdapterFactory method triggerOnComplete.

private void triggerOnComplete() {
    if (members.size() != responses.size() || !setDone()) {
        return;
    }
    Map<Member, Object> realResponses = createHashMap(members.size());
    for (Map.Entry<Member, ValueWrapper> entry : responses.entrySet()) {
        Member key = entry.getKey();
        Object value = entry.getValue().value;
        realResponses.put(key, value);
    }
    multiExecutionCallback.onComplete(realResponses);
}
Also used : Member(com.hazelcast.cluster.Member) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) MapUtil.createConcurrentHashMap(com.hazelcast.internal.util.MapUtil.createConcurrentHashMap) Map(java.util.Map)

Example 13 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class ExecutorServiceProxy method selectMembers.

private List<Member> selectMembers(@Nonnull MemberSelector memberSelector) {
    checkNotNull(memberSelector, "memberSelector must not be null");
    List<Member> selected = new ArrayList<>();
    Collection<Member> members = getNodeEngine().getClusterService().getMembers();
    for (Member member : members) {
        if (memberSelector.select(member)) {
            selected.add(member);
        }
    }
    if (selected.isEmpty()) {
        throw new RejectedExecutionException("No member selected with memberSelector[" + memberSelector + "]");
    }
    return selected;
}
Also used : ArrayList(java.util.ArrayList) Member(com.hazelcast.cluster.Member) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 14 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToMembers.

@Override
public <T> Map<Member, Future<T>> submitToMembers(@Nonnull Callable<T> task, @Nonnull Collection<Member> members) {
    checkNotNull(task, "task must not be null");
    checkNotNull(members, "members must not be null");
    checkNotShutdown();
    Data taskData = getNodeEngine().toData(task);
    Map<Member, Future<T>> futures = createHashMap(members.size());
    for (Member member : members) {
        futures.put(member, submitToMember(taskData, member));
    }
    return futures;
}
Also used : InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) Data(com.hazelcast.internal.serialization.Data) Member(com.hazelcast.cluster.Member)

Example 15 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class DurableExecutorServiceProxy method shutdown.

@Override
public void shutdown() {
    NodeEngine nodeEngine = getNodeEngine();
    Collection<Member> members = nodeEngine.getClusterService().getMembers();
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Future> calls = new LinkedList<>();
    for (Member member : members) {
        ShutdownOperation op = new ShutdownOperation(name);
        Future f = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
        calls.add(f);
    }
    waitWithDeadline(calls, 3, TimeUnit.SECONDS, shutdownExceptionHandler);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) DurableExecutorServiceFuture(com.hazelcast.durableexecutor.DurableExecutorServiceFuture) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) DelegatingCompletableFuture(com.hazelcast.spi.impl.DelegatingCompletableFuture) ShutdownOperation(com.hazelcast.durableexecutor.impl.operations.ShutdownOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Member(com.hazelcast.cluster.Member) LinkedList(java.util.LinkedList)

Aggregations

Member (com.hazelcast.cluster.Member)429 Test (org.junit.Test)210 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)164 HazelcastInstance (com.hazelcast.core.HazelcastInstance)116 IExecutorService (com.hazelcast.core.IExecutorService)73 Address (com.hazelcast.cluster.Address)62 ArrayList (java.util.ArrayList)55 Future (java.util.concurrent.Future)53 UUID (java.util.UUID)43 Config (com.hazelcast.config.Config)42 CountDownLatch (java.util.concurrent.CountDownLatch)38 Map (java.util.Map)33 HashMap (java.util.HashMap)31 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)28 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)25 List (java.util.List)25 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)24 Operation (com.hazelcast.spi.impl.operationservice.Operation)24 IMap (com.hazelcast.map.IMap)23