use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientMemberAttributeTest method testAddAttributes.
@Test(timeout = 120000)
public void testAddAttributes() throws Exception {
Config c = new Config();
JoinConfig join = c.getNetworkConfig().getJoin();
join.getTcpIpConfig().addMember("127.0.0.1").setEnabled(true);
join.getMulticastConfig().setEnabled(false);
HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(c);
Member m1 = h1.getCluster().getLocalMember();
m1.setIntAttribute("Test", 123);
HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(c);
assertEquals(2, h2.getCluster().getMembers().size());
Member member = null;
for (Member m : h2.getCluster().getMembers()) {
if (m == h2.getCluster().getLocalMember()) {
continue;
}
member = m;
}
assertNotNull(member);
assertEquals(m1, member);
assertNotNull(member.getIntAttribute("Test"));
assertEquals(123, (int) member.getIntAttribute("Test"));
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final CountDownLatch latch = new CountDownLatch(3);
final MembershipListener listener = new LatchMembershipListener(latch);
h2.getCluster().addMembershipListener(listener);
h1.getCluster().addMembershipListener(listener);
client.getCluster().addMembershipListener(listener);
m1.setIntAttribute("Test2", 321);
// Force sleep to distribute value
assertOpenEventually(latch);
assertNotNull(member.getIntAttribute("Test2"));
assertEquals(321, (int) member.getIntAttribute("Test2"));
boolean found = false;
Collection<Member> members = client.getCluster().getMembers();
for (Member m : members) {
if (m.equals(m1)) {
assertEquals(321, (int) m.getIntAttribute("Test2"));
found = true;
}
}
assertTrue(found);
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientMembershipListener method handle.
@Override
public void handle(String uuid, String key, int opType, String value) {
Collection<Member> members = clusterService.getMemberList();
for (Member target : members) {
if (target.getUuid().equals(uuid)) {
final MemberAttributeOperationType operationType = MemberAttributeOperationType.getValue(opType);
((AbstractMember) target).updateAttribute(operationType, key, value);
MemberAttributeEvent memberAttributeEvent = new MemberAttributeEvent(client.getCluster(), target, operationType, key, value);
clusterService.fireMemberAttributeEvent(memberAttributeEvent);
break;
}
}
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientMembershipListener method handle.
@Override
public void handle(Collection<Member> initialMembers) {
Map<String, Member> prevMembers = Collections.emptyMap();
if (!members.isEmpty()) {
prevMembers = new HashMap<String, Member>(members.size());
for (Member member : members) {
prevMembers.put(member.getUuid(), member);
}
members.clear();
}
for (Member initialMember : initialMembers) {
members.add(initialMember);
}
if (prevMembers.isEmpty()) {
//this means this is the first time client connected to server
logger.info(membersString());
clusterService.handleInitialMembershipEvent(new InitialMembershipEvent(client.getCluster(), unmodifiableSet(members)));
initialListFetchedLatch.countDown();
return;
}
List<MembershipEvent> events = detectMembershipEvents(prevMembers);
logger.info(membersString());
fireMembershipEvent(events);
initialListFetchedLatch.countDown();
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class MapProxySupport method removeMapInterceptorInternal.
public void removeMapInterceptorInternal(String id) {
NodeEngine nodeEngine = getNodeEngine();
mapServiceContext.removeInterceptor(name, id);
Collection<Member> members = nodeEngine.getClusterService().getMembers();
for (Member member : members) {
try {
if (member.localMember()) {
continue;
}
RemoveInterceptorOperation op = new RemoveInterceptorOperation(name, id);
Future future = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
future.get();
} catch (Throwable t) {
throw rethrow(t);
}
}
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ConfigMemberGroupFactory method createInternalMemberGroups.
@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> members) {
Map<Integer, MemberGroup> memberGroups = new HashMap<Integer, MemberGroup>();
for (Member member : members) {
String host = ((MemberImpl) member).getAddress().getHost();
for (Entry<Integer, MemberGroupConfig> entry : memberGroupConfigMap.entrySet()) {
Collection<String> interfaces = entry.getValue().getInterfaces();
boolean match;
if (AddressUtil.isIpAddress(host)) {
match = AddressUtil.matchAnyInterface(host, interfaces);
} else {
match = AddressUtil.matchAnyDomain(host, interfaces);
}
if (match) {
MemberGroup group = memberGroups.get(entry.getKey());
if (group == null) {
group = new DefaultMemberGroup();
memberGroups.put(entry.getKey(), group);
}
group.addMember(member);
break;
}
}
}
return new HashSet<MemberGroup>(memberGroups.values());
}
Aggregations