Search in sources :

Example 6 with Partition

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

the class HazelcastTestSupport method generateKeyOwnedBy.

/**
     * Generates a key according to given reference instance by checking partition ownership for it.
     *
     * @param instance         reference instance for key generation.
     * @param generateOwnedKey {@code true} if we want a key which is owned by the given instance, otherwise
     *                         set to {@code false} which means generated key will not be owned by the given instance.
     * @return generated string.
     */
public static String generateKeyOwnedBy(HazelcastInstance instance, boolean generateOwnedKey) {
    Cluster cluster = instance.getCluster();
    checkMemberCount(generateOwnedKey, cluster);
    checkPartitionCountGreaterOrEqualMemberCount(instance);
    Member localMember = cluster.getLocalMember();
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        String id = randomString();
        Partition partition = partitionService.getPartition(id);
        if (comparePartitionOwnership(generateOwnedKey, localMember, partition)) {
            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 7 with Partition

use of com.hazelcast.core.Partition 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 8 with Partition

use of com.hazelcast.core.Partition 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 9 with Partition

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

the class ClientConsoleApp method handlePartitions.

protected void handlePartitions(String[] args) {
    Set<Partition> partitions = hazelcast.getPartitionService().getPartitions();
    Map<Member, Integer> partitionCounts = new HashMap<Member, Integer>();
    for (Partition partition : partitions) {
        Member owner = partition.getOwner();
        if (owner != null) {
            Integer count = partitionCounts.get(owner);
            int newCount = 1;
            if (count != null) {
                newCount = count + 1;
            }
            partitionCounts.put(owner, newCount);
        }
        println(partition);
    }
    Set<Entry<Member, Integer>> entries = partitionCounts.entrySet();
    for (Entry<Member, Integer> entry : entries) {
        println(entry.getKey() + ":" + entry.getValue());
    }
}
Also used : Partition(com.hazelcast.core.Partition) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member)

Example 10 with Partition

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

the class PartitionServiceProxy method getPartitions.

@Override
public Set<Partition> getPartitions() {
    final int partitionCount = partitionService.getPartitionCount();
    Set<Partition> partitions = new LinkedHashSet<Partition>(partitionCount);
    for (int i = 0; i < partitionCount; i++) {
        final Partition partition = partitionService.getPartition(i);
        partitions.add(partition);
    }
    return partitions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Partition(com.hazelcast.core.Partition)

Aggregations

Partition (com.hazelcast.core.Partition)18 Member (com.hazelcast.core.Member)13 PartitionService (com.hazelcast.core.PartitionService)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)4 IPartition (com.hazelcast.spi.partition.IPartition)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Cluster (com.hazelcast.core.Cluster)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Entry (java.util.Map.Entry)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 InternalLockNamespace (com.hazelcast.concurrent.lock.InternalLockNamespace)1 LockServiceImpl (com.hazelcast.concurrent.lock.LockServiceImpl)1 LockStore (com.hazelcast.concurrent.lock.LockStore)1 ILock (com.hazelcast.core.ILock)1 IMap (com.hazelcast.core.IMap)1 MultiMap (com.hazelcast.core.MultiMap)1