Search in sources :

Example 1 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 2 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)

Example 3 with Partition

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

the class ClientHeartbeatTest method testInvocation_whenHeartbeatStopped.

@Test
public void testInvocation_whenHeartbeatStopped() throws InterruptedException {
    hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
    final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    // Make sure that the partitions are updated as expected with the new member
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Member instance2Member = instance2.getCluster().getLocalMember();
            Set<Partition> partitions = client.getPartitionService().getPartitions();
            boolean found = false;
            for (Partition p : partitions) {
                if (p.getOwner().equals(instance2Member)) {
                    found = true;
                    break;
                }
            }
            assertTrue(found);
        }
    });
    // make sure client is connected to instance2
    String keyOwnedByInstance2 = generateKeyOwnedBy(instance2);
    IMap<String, String> map = client.getMap(randomString());
    map.put(keyOwnedByInstance2, randomString());
    blockMessagesFromInstance(instance2, client);
    expectedException.expect(TargetDisconnectedException.class);
    expectedException.expectMessage(containsString("Heartbeat"));
    map.put(keyOwnedByInstance2, randomString());
}
Also used : Partition(com.hazelcast.core.Partition) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Set(java.util.Set) AssertTask(com.hazelcast.test.AssertTask) Matchers.containsString(org.hamcrest.Matchers.containsString) Member(com.hazelcast.core.Member) ExpectedException(org.junit.rules.ExpectedException) ExecutionException(java.util.concurrent.ExecutionException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with Partition

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

the class SimpleMultiMapTest method load.

private static void load(boolean load, ExecutorService es, final MultiMap<String, byte[]> map) {
    if (load) {
        final Member thisMember = instance.getCluster().getLocalMember();
        for (int i = 0; i < entryCount; i++) {
            final String key = String.valueOf(i);
            Partition partition = instance.getPartitionService().getPartition(key);
            if (thisMember.equals(partition.getOwner())) {
                es.execute(new Runnable() {

                    public void run() {
                        map.put(key, new byte[valueSize]);
                    }
                });
            }
        }
    }
}
Also used : Partition(com.hazelcast.core.Partition) Member(com.hazelcast.core.Member)

Example 5 with Partition

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

the class SimpleReplicatedMapTest method load.

private void load(ExecutorService es) throws InterruptedException {
    if (!load) {
        return;
    }
    final ReplicatedMap<String, Object> map = instance.getReplicatedMap(NAMESPACE);
    final Member thisMember = instance.getCluster().getLocalMember();
    List<String> lsOwnedEntries = new LinkedList<String>();
    for (int i = 0; i < entryCount; i++) {
        final String key = String.valueOf(i);
        Partition partition = instance.getPartitionService().getPartition(key);
        if (thisMember.equals(partition.getOwner())) {
            lsOwnedEntries.add(key);
        }
    }
    final CountDownLatch latch = new CountDownLatch(lsOwnedEntries.size());
    for (final String ownedKey : lsOwnedEntries) {
        es.execute(new Runnable() {

            public void run() {
                map.put(ownedKey, createValue());
                latch.countDown();
            }
        });
    }
    latch.await();
}
Also used : Partition(com.hazelcast.core.Partition) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

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