Search in sources :

Example 36 with Member

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

the class HazelcastTestSupport method randomNameOwnedBy.

public static String randomNameOwnedBy(HazelcastInstance instance, String prefix) {
    Member localMember = instance.getCluster().getLocalMember();
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        String id = prefix + randomString();
        Partition partition = partitionService.getPartition(id);
        if (comparePartitionOwnership(true, localMember, partition)) {
            return id;
        }
    }
}
Also used : Partition(com.hazelcast.core.Partition) IPartition(com.hazelcast.spi.partition.IPartition) PartitionService(com.hazelcast.core.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Member(com.hazelcast.core.Member)

Example 37 with Member

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

the class HazelcastTestSupport method generateKeyForPartition.

public static String generateKeyForPartition(HazelcastInstance instance, int partitionId) {
    Cluster cluster = instance.getCluster();
    checkPartitionCountGreaterOrEqualMemberCount(instance);
    Member localMember = cluster.getLocalMember();
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        String id = randomString();
        Partition partition = partitionService.getPartition(id);
        if (partition.getPartitionId() == partitionId) {
            return id;
        }
    }
}
Also used : Partition(com.hazelcast.core.Partition) IPartition(com.hazelcast.spi.partition.IPartition) Cluster(com.hazelcast.core.Cluster) PartitionService(com.hazelcast.core.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Member(com.hazelcast.core.Member)

Example 38 with Member

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

the class ClientConsoleApp method doExecute.

private void doExecute(boolean onKey, boolean onMember, String[] args) {
    // executeOnKey <echo-string> <key>
    try {
        IExecutorService executorService = hazelcast.getExecutorService("default");
        Echo callable = new Echo(args[1]);
        Future<String> future;
        if (onKey) {
            String key = args[2];
            future = executorService.submitToKeyOwner(callable, key);
        } else if (onMember) {
            int memberIndex = Integer.parseInt(args[2]);
            List<Member> members = new LinkedList(hazelcast.getCluster().getMembers());
            if (memberIndex >= members.size()) {
                throw new IndexOutOfBoundsException("Member index: " + memberIndex + " must be smaller than " + members.size());
            }
            Member member = members.get(memberIndex);
            future = executorService.submitToMember(callable, member);
        } else {
            future = executorService.submit(callable);
        }
        println("Result: " + future.get());
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : Echo(com.hazelcast.console.Echo) List(java.util.List) IList(com.hazelcast.core.IList) LinkedList(java.util.LinkedList) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Example 39 with Member

use of com.hazelcast.core.Member 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 40 with Member

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

the class ClientExecutorServiceProxy method submitToMembers.

@Override
public <T> void submitToMembers(Callable<T> task, Collection<Member> members, MultiExecutionCallback callback) {
    MultiExecutionCallbackWrapper multiExecutionCallbackWrapper = new MultiExecutionCallbackWrapper(members.size(), callback);
    for (Member member : members) {
        final ExecutionCallbackWrapper<T> executionCallback = new ExecutionCallbackWrapper<T>(multiExecutionCallbackWrapper, member);
        submitToMember(task, member, executionCallback);
    }
}
Also used : Member(com.hazelcast.core.Member)

Aggregations

Member (com.hazelcast.core.Member)330 Test (org.junit.Test)134 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)113 HazelcastInstance (com.hazelcast.core.HazelcastInstance)99 Address (com.hazelcast.nio.Address)60 IExecutorService (com.hazelcast.core.IExecutorService)57 Future (java.util.concurrent.Future)47 ArrayList (java.util.ArrayList)45 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)41 CountDownLatch (java.util.concurrent.CountDownLatch)37 Config (com.hazelcast.config.Config)35 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)26 HashMap (java.util.HashMap)26 IMap (com.hazelcast.core.IMap)24 HashSet (java.util.HashSet)21 LinkedList (java.util.LinkedList)20 OperationService (com.hazelcast.spi.OperationService)19 AssertTask (com.hazelcast.test.AssertTask)19 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)18