Search in sources :

Example 86 with Member

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

Example 87 with Member

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;
        }
    }
}
Also used : MemberAttributeOperationType(com.hazelcast.cluster.MemberAttributeOperationType) AbstractMember(com.hazelcast.instance.AbstractMember) MemberAttributeEvent(com.hazelcast.core.MemberAttributeEvent) AbstractMember(com.hazelcast.instance.AbstractMember) Member(com.hazelcast.core.Member)

Example 88 with Member

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

Example 89 with Member

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);
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Future(java.util.concurrent.Future) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) RemoveInterceptorOperation(com.hazelcast.map.impl.operation.RemoveInterceptorOperation) Member(com.hazelcast.core.Member)

Example 90 with Member

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());
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig) HashSet(java.util.HashSet)

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