Search in sources :

Example 81 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MemberMap method cloneAdding.

/**
 * Creates clone of source {@code MemberMap} additionally including new members.
 *
 * @param source     source map
 * @param newMembers new members to add
 * @return clone map
 */
static MemberMap cloneAdding(MemberMap source, MemberImpl... newMembers) {
    Map<Address, MemberImpl> addressMap = new LinkedHashMap<>(source.addressToMemberMap);
    Map<UUID, MemberImpl> uuidMap = new LinkedHashMap<>(source.uuidToMemberMap);
    for (MemberImpl member : newMembers) {
        putMember(addressMap, uuidMap, member);
    }
    return new MemberMap(source.version + newMembers.length, addressMap, uuidMap);
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) UUID(java.util.UUID) MapUtil.createLinkedHashMap(com.hazelcast.internal.util.MapUtil.createLinkedHashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 82 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MemberMap method tailMemberSet.

Set<MemberImpl> tailMemberSet(MemberImpl member, boolean inclusive) {
    ensureMemberExist(member);
    Set<MemberImpl> result = new LinkedHashSet<>();
    boolean found = false;
    for (MemberImpl m : members) {
        if (!found && m.equals(member)) {
            found = true;
            if (inclusive) {
                result.add(m);
            }
            continue;
        }
        if (found) {
            result.add(m);
        }
    }
    assert found : member + " should have been found!";
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 83 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MemberMap method getMember.

MemberImpl getMember(Address address, UUID uuid) {
    MemberImpl member1 = addressToMemberMap.get(address);
    MemberImpl member2 = uuidToMemberMap.get(uuid);
    if (member1 != null && member1.equals(member2)) {
        return member1;
    }
    return null;
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 84 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MemberMap method cloneExcluding.

/**
 * Creates clone of source {@code MemberMap}, excluding given members.
 * If source is empty, same map instance will be returned. If excluded members are empty or not present in
 * source, a new map will be created containing the same members with source.
 *
 * @param source         source map
 * @param excludeMembers members to exclude
 * @return clone map
 */
static MemberMap cloneExcluding(MemberMap source, MemberImpl... excludeMembers) {
    if (source.size() == 0) {
        return source;
    }
    Map<Address, MemberImpl> addressMap = new LinkedHashMap<>(source.addressToMemberMap);
    Map<UUID, MemberImpl> uuidMap = new LinkedHashMap<>(source.uuidToMemberMap);
    for (MemberImpl member : excludeMembers) {
        MemberImpl removed = addressMap.remove(member.getAddress());
        if (removed != null) {
            uuidMap.remove(removed.getUuid());
        }
        removed = uuidMap.remove(member.getUuid());
        if (removed != null) {
            addressMap.remove(removed.getAddress());
        }
    }
    return new MemberMap(source.version + excludeMembers.length, addressMap, uuidMap);
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) UUID(java.util.UUID) MapUtil.createLinkedHashMap(com.hazelcast.internal.util.MapUtil.createLinkedHashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 85 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MembersView method toMemberMap.

MemberMap toMemberMap() {
    MemberImpl[] m = new MemberImpl[size()];
    int ix = 0;
    for (MemberInfo memberInfo : members) {
        m[ix++] = memberInfo.toMember();
    }
    return MemberMap.createNew(version, m);
}
Also used : MemberInfo(com.hazelcast.internal.cluster.MemberInfo) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Aggregations

MemberImpl (com.hazelcast.cluster.impl.MemberImpl)123 Address (com.hazelcast.cluster.Address)41 Test (org.junit.Test)37 QuickTest (com.hazelcast.test.annotation.QuickTest)34 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)32 Member (com.hazelcast.cluster.Member)21 HazelcastInstance (com.hazelcast.core.HazelcastInstance)16 UUID (java.util.UUID)14 ArrayList (java.util.ArrayList)10 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)9 HashMap (java.util.HashMap)9 InetAddress (java.net.InetAddress)8 HashSet (java.util.HashSet)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 Config (com.hazelcast.config.Config)6 Future (java.util.concurrent.Future)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 StaticMemberNodeContext (com.hazelcast.instance.StaticMemberNodeContext)4 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)4 MembersUpdateOp (com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp)4