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());
}
}
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;
}
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());
}
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]);
}
});
}
}
}
}
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();
}
Aggregations