Search in sources :

Example 91 with Member

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

the class SPIAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Set<MemberGroup> memberGroups = new HashSet<MemberGroup>();
    for (Member member : allMembers) {
        try {
            if (member.localMember()) {
                DefaultDiscoveryService defaultDiscoveryService = (DefaultDiscoveryService) discoveryService;
                // If no discovery strategy is found fail-fast
                if (!defaultDiscoveryService.getDiscoveryStrategies().iterator().hasNext()) {
                    throw new RuntimeException("Could not load any Discovery Strategy, please " + "check service definitions under META_INF.services folder. ");
                } else {
                    for (DiscoveryStrategy discoveryStrategy : defaultDiscoveryService.getDiscoveryStrategies()) {
                        checkNotNull(discoveryStrategy.getPartitionGroupStrategy());
                        Iterable<MemberGroup> spiGroupsIterator = discoveryStrategy.getPartitionGroupStrategy().getMemberGroups();
                        for (MemberGroup group : spiGroupsIterator) {
                            memberGroups.add(group);
                        }
                        return memberGroups;
                    }
                }
            }
        } catch (Exception e) {
            if (e instanceof ValidationException) {
                throw new InvalidConfigurationException("Invalid configuration", e);
            } else {
                throw new RuntimeException("Failed to configure discovery strategies", e);
            }
        }
    }
    return memberGroups;
}
Also used : ValidationException(com.hazelcast.config.properties.ValidationException) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) Member(com.hazelcast.core.Member) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) ValidationException(com.hazelcast.config.properties.ValidationException) HashSet(java.util.HashSet) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 92 with Member

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

the class ClientExecutorServiceProxy method selectMembers.

private List<Member> selectMembers(MemberSelector memberSelector) {
    if (memberSelector == null) {
        throw new IllegalArgumentException("memberSelector must not be null");
    }
    List<Member> selected = new ArrayList<Member>();
    Collection<Member> members = getContext().getClusterService().getMemberList();
    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.core.Member) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 93 with Member

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

the class ClientExecutorServiceProxy method submitToMembers.

@Override
public <T> Map<Member, Future<T>> submitToMembers(Callable<T> task, Collection<Member> members) {
    Map<Member, Future<T>> futureMap = new HashMap<Member, Future<T>>(members.size());
    for (Member member : members) {
        final Address memberAddress = getMemberAddress(member);
        Future<T> f = submitToTargetInternal(task, memberAddress, null, true);
        futureMap.put(member, f);
    }
    return futureMap;
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) ClientAddressCancellableDelegatingFuture(com.hazelcast.client.util.ClientAddressCancellableDelegatingFuture) ClientPartitionCancellableDelegatingFuture(com.hazelcast.client.util.ClientPartitionCancellableDelegatingFuture) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) Future(java.util.concurrent.Future) CompletedFuture(com.hazelcast.util.executor.CompletedFuture) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) Member(com.hazelcast.core.Member)

Example 94 with Member

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

the class ClientExecutorServiceProxy method executeOnAllMembers.

@Override
public void executeOnAllMembers(Runnable command) {
    Callable<?> callable = createRunnableAdapter(command);
    final Collection<Member> memberList = getContext().getClusterService().getMemberList();
    for (Member member : memberList) {
        submitToMember(callable, member);
    }
}
Also used : Member(com.hazelcast.core.Member)

Example 95 with Member

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

the class ClientExecutorServiceProxy method submitToAllMembers.

@Override
public <T> Map<Member, Future<T>> submitToAllMembers(Callable<T> task) {
    final Collection<Member> memberList = getContext().getClusterService().getMemberList();
    Map<Member, Future<T>> futureMap = new HashMap<Member, Future<T>>(memberList.size());
    for (Member m : memberList) {
        Future<T> f = submitToTargetInternal(task, m.getAddress(), null, true);
        futureMap.put(m, f);
    }
    return futureMap;
}
Also used : HashMap(java.util.HashMap) ClientAddressCancellableDelegatingFuture(com.hazelcast.client.util.ClientAddressCancellableDelegatingFuture) ClientPartitionCancellableDelegatingFuture(com.hazelcast.client.util.ClientPartitionCancellableDelegatingFuture) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) Future(java.util.concurrent.Future) CompletedFuture(com.hazelcast.util.executor.CompletedFuture) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) Member(com.hazelcast.core.Member)

Aggregations

Member (com.hazelcast.core.Member)167 Test (org.junit.Test)43 Address (com.hazelcast.nio.Address)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)37 QuickTest (com.hazelcast.test.annotation.QuickTest)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)20 Config (com.hazelcast.config.Config)18 HashSet (java.util.HashSet)18 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)17 Future (java.util.concurrent.Future)17 Data (com.hazelcast.nio.serialization.Data)13 Operation (com.hazelcast.spi.Operation)13 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)13 CacheEventData (com.hazelcast.cache.impl.CacheEventData)12 HeapData (com.hazelcast.internal.serialization.impl.HeapData)12 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)12 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)12 OperationService (com.hazelcast.spi.OperationService)12