use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ProxyManager method findNextAddressToSendCreateRequest.
public Address findNextAddressToSendCreateRequest() {
int clusterSize = client.getClientClusterService().getSize();
Member liteMember = null;
final LoadBalancer loadBalancer = client.getLoadBalancer();
for (int i = 0; i < clusterSize; i++) {
Member member = loadBalancer.next();
if (member != null && !member.isLiteMember()) {
return member.getAddress();
} else if (liteMember == null) {
liteMember = member;
}
}
return liteMember != null ? liteMember.getAddress() : null;
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientClusterServiceImpl method initMembershipListener.
private void initMembershipListener(MembershipListener listener) {
if (listener instanceof InitialMembershipListener) {
Cluster cluster = client.getCluster();
Collection<Member> memberCollection = members.get().values();
LinkedHashSet<Member> members = new LinkedHashSet<Member>(memberCollection);
InitialMembershipEvent event = new InitialMembershipEvent(cluster, members);
((InitialMembershipListener) listener).init(event);
}
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientClusterServiceImpl method handleMembershipEvent.
void handleMembershipEvent(MembershipEvent event) {
synchronized (initialMembershipListenerMutex) {
Member member = event.getMember();
if (event.getEventType() == MembershipEvent.MEMBER_ADDED) {
LinkedHashMap<Address, Member> newMap = new LinkedHashMap<Address, Member>(members.get());
newMap.put(member.getAddress(), member);
members.set(Collections.unmodifiableMap(newMap));
} else {
LinkedHashMap<Address, Member> newMap = new LinkedHashMap<Address, Member>(members.get());
newMap.remove(member.getAddress());
members.set(Collections.unmodifiableMap(newMap));
}
fireMembershipEvent(event);
}
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientMembershipListener method detectMembershipEvents.
private List<MembershipEvent> detectMembershipEvents(Map<String, Member> prevMembers) {
List<MembershipEvent> events = new LinkedList<MembershipEvent>();
Set<Member> eventMembers = unmodifiableSet(members);
List<Member> newMembers = new LinkedList<Member>();
for (Member member : members) {
Member former = prevMembers.remove(member.getUuid());
if (former == null) {
newMembers.add(member);
}
}
// removal events should be added before added events
for (Member member : prevMembers.values()) {
events.add(new MembershipEvent(client.getCluster(), member, MembershipEvent.MEMBER_REMOVED, eventMembers));
Address address = member.getAddress();
if (clusterService.getMember(address) == null) {
Connection connection = connectionManager.getConnection(address);
if (connection != null) {
connection.close(null, newTargetDisconnectedExceptionCausedByMemberLeftEvent(connection));
}
}
}
for (Member member : newMembers) {
events.add(new MembershipEvent(client.getCluster(), member, MembershipEvent.MEMBER_ADDED, eventMembers));
}
return events;
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientMemberAttributeTest method testChangeMemberAttributes.
@Test
public void testChangeMemberAttributes() throws Exception {
final int count = 10;
final HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final ClientConfig config = new ClientConfig();
final ListenerConfig listenerConfig = new ListenerConfig();
final CountDownLatch countDownLatch = new CountDownLatch(count);
listenerConfig.setImplementation(new LatchMembershipListener(countDownLatch));
config.addListenerConfig(listenerConfig);
hazelcastFactory.newHazelcastClient(config);
final Member localMember = instance.getCluster().getLocalMember();
for (int i = 0; i < count; i++) {
localMember.setStringAttribute("key" + i, HazelcastTestSupport.randomString());
}
assertOpenEventually(countDownLatch);
}
Aggregations