Search in sources :

Example 81 with Member

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;
}
Also used : LoadBalancer(com.hazelcast.client.LoadBalancer) Member(com.hazelcast.core.Member)

Example 82 with Member

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InitialMembershipListener(com.hazelcast.core.InitialMembershipListener) Cluster(com.hazelcast.core.Cluster) Member(com.hazelcast.core.Member) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent)

Example 83 with Member

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);
    }
}
Also used : Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) Member(com.hazelcast.core.Member) LinkedHashMap(java.util.LinkedHashMap)

Example 84 with Member

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;
}
Also used : Address(com.hazelcast.nio.Address) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) MembershipEvent(com.hazelcast.core.MembershipEvent) Connection(com.hazelcast.nio.Connection) AbstractMember(com.hazelcast.instance.AbstractMember) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Example 85 with Member

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);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Member (com.hazelcast.core.Member)167 Test (org.junit.Test)43 Address (com.hazelcast.nio.Address)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)37 QuickTest (com.hazelcast.test.annotation.QuickTest)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)20 Config (com.hazelcast.config.Config)18 HashSet (java.util.HashSet)18 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)17 Future (java.util.concurrent.Future)17 Data (com.hazelcast.nio.serialization.Data)13 Operation (com.hazelcast.spi.Operation)13 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)13 CacheEventData (com.hazelcast.cache.impl.CacheEventData)12 HeapData (com.hazelcast.internal.serialization.impl.HeapData)12 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)12 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)12 OperationService (com.hazelcast.spi.OperationService)12