Search in sources :

Example 21 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class PartitionStateGeneratorImpl method createNodeGroups.

private Queue<NodeGroup> createNodeGroups(Collection<MemberGroup> memberGroups) {
    Queue<NodeGroup> nodeGroups = new LinkedList<NodeGroup>();
    if (memberGroups == null || memberGroups.isEmpty()) {
        return nodeGroups;
    }
    for (MemberGroup memberGroup : memberGroups) {
        NodeGroup nodeGroup;
        if (memberGroup.size() == 0) {
            continue;
        }
        if (memberGroup instanceof SingleMemberGroup || memberGroup.size() == 1) {
            nodeGroup = new SingleNodeGroup();
            MemberImpl next = (MemberImpl) memberGroup.iterator().next();
            nodeGroup.addNode(next.getAddress());
        } else {
            nodeGroup = new DefaultNodeGroup();
            Iterator<Member> iter = memberGroup.iterator();
            while (iter.hasNext()) {
                MemberImpl next = (MemberImpl) iter.next();
                nodeGroup.addNode(next.getAddress());
            }
        }
        nodeGroups.add(nodeGroup);
    }
    return nodeGroups;
}
Also used : MemberGroup(com.hazelcast.partition.membergroup.MemberGroup) SingleMemberGroup(com.hazelcast.partition.membergroup.SingleMemberGroup) SingleMemberGroup(com.hazelcast.partition.membergroup.SingleMemberGroup) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Example 22 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class HostAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Map<String, MemberGroup> groups = new HashMap<String, MemberGroup>();
    for (Member member : allMembers) {
        Address address = ((MemberImpl) member).getAddress();
        MemberGroup group = groups.get(address.getHost());
        if (group == null) {
            group = new DefaultMemberGroup();
            groups.put(address.getHost(), group);
        }
        group.addMember(member);
    }
    return new HashSet<MemberGroup>(groups.values());
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet)

Example 23 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class TopicService method dispatchEvent.

@Override
public void dispatchEvent(Object event, Object listener) {
    TopicEvent topicEvent = (TopicEvent) event;
    ClusterService clusterService = nodeEngine.getClusterService();
    MemberImpl member = clusterService.getMember(topicEvent.publisherAddress);
    if (member == null) {
        member = new MemberImpl(topicEvent.publisherAddress, nodeEngine.getVersion(), false);
    }
    Message message = new DataAwareMessage(topicEvent.name, topicEvent.data, topicEvent.publishTime, member, nodeEngine.getSerializationService());
    incrementReceivedMessages(topicEvent.name);
    MessageListener messageListener = (MessageListener) listener;
    messageListener.onMessage(message);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Message(com.hazelcast.core.Message) MemberImpl(com.hazelcast.instance.MemberImpl) MessageListener(com.hazelcast.core.MessageListener)

Example 24 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class TransactionManagerServiceImpl method pickBackupLogAddresses.

Address[] pickBackupLogAddresses(int durability) {
    if (durability == 0) {
        return EMPTY_ADDRESSES;
    }
    // This should be cleaned up because this is quite a complex approach since it depends on
    // the number of members in the cluster and creates litter.
    ClusterService clusterService = nodeEngine.getClusterService();
    List<MemberImpl> members = new ArrayList<MemberImpl>(clusterService.getMemberImpls());
    members.remove(nodeEngine.getLocalMember());
    int c = Math.min(members.size(), durability);
    shuffle(members);
    Address[] addresses = new Address[c];
    for (int i = 0; i < c; i++) {
        addresses[i] = members.get(i).getAddress();
    }
    return addresses;
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) ArrayList(java.util.ArrayList)

Example 25 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class CacheSerializationTest method testCachePartitionEventData.

@Test
public void testCachePartitionEventData() throws UnknownHostException {
    Address address = new Address("127.0.0.1", 5701);
    Member member = new MemberImpl(address, MemberVersion.UNKNOWN, true, false);
    CachePartitionEventData cachePartitionEventData = new CachePartitionEventData("test", 1, member);
    CachePartitionEventData deserialized = service.toObject(cachePartitionEventData);
    assertEquals(cachePartitionEventData, deserialized);
}
Also used : CachePartitionEventData(com.hazelcast.cache.impl.CachePartitionEventData) Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MemberImpl (com.hazelcast.instance.MemberImpl)86 Address (com.hazelcast.nio.Address)37 Test (org.junit.Test)18 Member (com.hazelcast.core.Member)17 QuickTest (com.hazelcast.test.annotation.QuickTest)16 ParallelTest (com.hazelcast.test.annotation.ParallelTest)14 ArrayList (java.util.ArrayList)12 InetAddress (java.net.InetAddress)9 Future (java.util.concurrent.Future)9 HashSet (java.util.HashSet)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)7 ClusterService (com.hazelcast.internal.cluster.ClusterService)5 MemberInfoUpdateOperation (com.hazelcast.internal.cluster.impl.operations.MemberInfoUpdateOperation)5 PartitionRuntimeState (com.hazelcast.internal.partition.PartitionRuntimeState)5 ILogger (com.hazelcast.logging.ILogger)5 OperationService (com.hazelcast.spi.OperationService)5 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)5 Before (org.junit.Before)5 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)4