com.hazelcast.cluster.Member Java Examples

The following examples show how to use com.hazelcast.cluster.Member. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Application.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
@Override
public void updateJpaAddresses() {
	StringBuilder sb = new StringBuilder();
	String delim = "";
	for (Member m : hazelcast.getCluster().getMembers()) {
		sb.append(delim).append(m.getAddress().getHost());
		delim = ";";
	}
	if (Strings.isEmpty(delim)) {
		sb.append("localhost");
	}
	try {
		cfgDao.updateClusterAddresses(sb.toString());
	} catch (UnknownHostException e) {
		log.error("Uexpected exception while updating JPA addresses", e);
		throw new WicketRuntimeException(e);
	}
}
 
Example #2
Source File: HazelcastClusterManager.java    From vertx-hazelcast with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void memberAdded(MembershipEvent membershipEvent) {
  if (!active) {
    return;
  }
  Member member = membershipEvent.getMember();
  String nid = member.getUuid().toString();
  try {
    if (nodeListener != null) {
      nodeIds.add(nid);
      nodeListener.nodeAdded(nid);
    }
  } catch (Throwable t) {
    log.error("Failed to handle memberAdded", t);
  }
}
 
Example #3
Source File: HazelcastUtilsTest.java    From hazelcast-simulator with Apache License 2.0 6 votes vote down vote up
private HazelcastInstance createMockHazelcastInstance(Member member, boolean returnMember, Exception getClusterException) {
    Set<Member> memberSet = new HashSet<Member>();
    memberSet.add(member);

    Cluster cluster = mock(Cluster.class);
    when(cluster.getMembers()).thenReturn(memberSet);
    when(cluster.getLocalMember()).thenReturn(returnMember ? member : null);

    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(hazelcastInstance.getLocalEndpoint()).thenReturn(returnMember ? member : null);
    if (getClusterException == null) {
        when(hazelcastInstance.getCluster()).thenReturn(cluster);
    } else {
        when(hazelcastInstance.getCluster()).thenReturn(cluster).thenThrow(getClusterException);
    }

    return hazelcastInstance;
}
 
Example #4
Source File: HazelcastClusterManager.java    From vertx-hazelcast with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getNodes() {
  List<String> list = new ArrayList<>();
  for (Member member : hazelcast.getCluster().getMembers()) {
    list.add(member.getUuid().toString());
  }
  return list;
}
 
Example #5
Source File: HazelcastClusterManager.java    From vertx-hazelcast with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void memberRemoved(MembershipEvent membershipEvent) {
  if (!active) {
    return;
  }
  Member member = membershipEvent.getMember();
  String nid = member.getUuid().toString();
  try {
    membersRemoved(Collections.singleton(nid));
  } catch (Throwable t) {
    log.error("Failed to handle memberRemoved", t);
  }
}
 
Example #6
Source File: KeyUtils.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if a key is located on a Hazelcast instance.
 *
 * @param instance the HazelcastInstance the key should belong to
 * @param key      the key to check
 * @return <tt>true</tt> if the key belongs to the Hazelcast instance, <tt>false</tt> otherwise
 */
public static boolean isLocalKey(HazelcastInstance instance, Object key) {
    PartitionService partitionService = instance.getPartitionService();
    Partition partition = partitionService.getPartition(key);
    Member owner;
    while (true) {
        owner = partition.getOwner();
        if (owner != null) {
            break;
        }
        sleepSeconds(1);
    }
    return owner.equals(instance.getLocalEndpoint());
}
 
Example #7
Source File: KeyUtils.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
private void verifyHasPartitions(Set<Integer> targetPartitions) {
    if (targetPartitions.isEmpty()) {
        Map<Member, Integer> partitionsPerMember = new HashMap<>();
        for (Partition partition : partitionService.getPartitions()) {
            Member owner = partition.getOwner();
            if (owner == null) {
                throw new IllegalStateException("Owner is null for partition: " + partition);
            }
            Integer value = partitionsPerMember.get(owner);
            Integer result = value == null ? 1 : value + 1;
            partitionsPerMember.put(owner, result);
        }
        throw new IllegalStateException("No partitions found, partitionsPerMember: " + partitionsPerMember);
    }
}
 
Example #8
Source File: KeyUtils.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
private Member getLocalMember(HazelcastInstance hz) {
    try {
        return hz.getCluster().getLocalMember();
    } catch (UnsupportedOperationException ignore) {
        // clients throw UnsupportedOperationExceptions
        return null;
    }
}
 
Example #9
Source File: HazelcastUtilsTest.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetHazelcastAddress_withMemberWorker() {
    Member member = mock(Member.class);
    when(member.getSocketAddress()).thenReturn(SOCKET_ADDRESS);
    hazelcastInstance = createMockHazelcastInstance(member);

    String address = getHazelcastAddress("member", "172.16.16.1", hazelcastInstance);

    assertEquals("127.0.0.1:5701", address);
}
 
Example #10
Source File: HazelcastUtilsTest.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetHazelcastAddress_withClientWorker() {
    Member member = mock(Member.class);
    when(member.getSocketAddress()).thenReturn(SOCKET_ADDRESS);
    hazelcastInstance = createMockHazelcastInstance(member);

    String address = getHazelcastAddress("javaclient", "172.16.16.1", hazelcastInstance);

    assertEquals("127.0.0.1:5701", address);
}
 
Example #11
Source File: ClusterListener.java    From mercury with Apache License 2.0 4 votes vote down vote up
public static void setMembers(Set<Member> members) {
    for (Member m: members) {
        String now = Utility.getInstance().date2str(new Date());
        nodes.put(m.getUuid().toString(), m.getAddress().toString()+", "+now);
    }
}
 
Example #12
Source File: HazelcastUtils.java    From hazelcast-simulator with Apache License 2.0 4 votes vote down vote up
public static boolean isOldestMember(HazelcastInstance hazelcastInstance) {
    Iterator<Member> memberIterator = hazelcastInstance.getCluster().getMembers().iterator();
    return memberIterator.hasNext() && memberIterator.next().equals(hazelcastInstance.getLocalEndpoint());
}
 
Example #13
Source File: HazelcastUtilsTest.java    From hazelcast-simulator with Apache License 2.0 4 votes vote down vote up
private HazelcastInstance createMockHazelcastInstance(boolean returnMember, Exception getClusterException) {
    Member member = mock(Member.class);
    return createMockHazelcastInstance(member, returnMember, getClusterException);
}
 
Example #14
Source File: HazelcastUtilsTest.java    From hazelcast-simulator with Apache License 2.0 4 votes vote down vote up
private HazelcastInstance createMockHazelcastInstance(Member member) {
    return createMockHazelcastInstance(member, true, null);
}