Search in sources :

Example 6 with Member

use of com.hazelcast.core.Member in project neo4j by neo4j.

the class HazelcastClusterTopology method getCoreTopology.

static CoreTopology getCoreTopology(HazelcastInstance hazelcastInstance, Config config, Log log) {
    Map<MemberId, CoreServerInfo> coreMembers = emptyMap();
    boolean canBeBootstrapped = false;
    ClusterId clusterId = null;
    if (hazelcastInstance != null) {
        Set<Member> hzMembers = hazelcastInstance.getCluster().getMembers();
        canBeBootstrapped = canBeBootstrapped(hazelcastInstance, config);
        coreMembers = toCoreMemberMap(hzMembers, log, hazelcastInstance);
        clusterId = getClusterId(hazelcastInstance);
    } else {
        log.info("Cannot currently bind to distributed discovery service.");
    }
    return new CoreTopology(clusterId, canBeBootstrapped, coreMembers);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ClusterId(org.neo4j.causalclustering.identity.ClusterId) Member(com.hazelcast.core.Member)

Example 7 with Member

use of com.hazelcast.core.Member in project neo4j by neo4j.

the class HazelcastClusterTopology method toCoreMemberMap.

static Map<MemberId, CoreServerInfo> toCoreMemberMap(Set<Member> members, Log log, HazelcastInstance hazelcastInstance) {
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    MultiMap<String, String> serverGroupsMMap = hazelcastInstance.getMultiMap(SERVER_GROUPS_MULTIMAP_NAME);
    for (Member member : members) {
        try {
            MemberId memberId = new MemberId(UUID.fromString(member.getStringAttribute(MEMBER_UUID)));
            CoreServerInfo coreServerInfo = new CoreServerInfo(socketAddress(member.getStringAttribute(RAFT_SERVER), AdvertisedSocketAddress::new), socketAddress(member.getStringAttribute(TRANSACTION_SERVER), AdvertisedSocketAddress::new), ClientConnectorAddresses.fromString(member.getStringAttribute(CLIENT_CONNECTOR_ADDRESSES)), asSet(serverGroupsMMap.get(memberId.getUuid().toString())));
            coreMembers.put(memberId, coreServerInfo);
        } catch (IllegalArgumentException e) {
            log.warn("Incomplete member attributes supplied from Hazelcast", e);
        }
    }
    return coreMembers;
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member)

Example 8 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class ClientCacheProxy method updateCacheListenerConfigOnOtherNodes.

protected void updateCacheListenerConfigOnOtherNodes(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration, boolean isRegister) {
    final Collection<Member> members = clientContext.getClusterService().getMemberList();
    final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
    for (Member member : members) {
        try {
            final Address address = member.getAddress();
            Data configData = toData(cacheEntryListenerConfiguration);
            final ClientMessage request = CacheListenerRegistrationCodec.encodeRequest(nameWithPrefix, configData, isRegister, address);
            final ClientInvocation invocation = new ClientInvocation(client, request, address);
            invocation.invoke();
        } catch (Exception e) {
            ExceptionUtil.sneakyThrow(e);
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Member(com.hazelcast.core.Member) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException)

Example 9 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class ClientConsoleApp method handlePartitions.

protected void handlePartitions(String[] args) {
    Set<Partition> partitions = hazelcast.getPartitionService().getPartitions();
    Map<Member, Integer> partitionCounts = new HashMap<Member, Integer>();
    for (Partition partition : partitions) {
        Member owner = partition.getOwner();
        if (owner != null) {
            Integer count = partitionCounts.get(owner);
            int newCount = 1;
            if (count != null) {
                newCount = count + 1;
            }
            partitionCounts.put(owner, newCount);
        }
        println(partition);
    }
    Set<Entry<Member, Integer>> entries = partitionCounts.entrySet();
    for (Entry<Member, Integer> entry : entries) {
        println(entry.getKey() + ":" + entry.getValue());
    }
}
Also used : Partition(com.hazelcast.core.Partition) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member)

Example 10 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class ClientConsoleApp method executeOnMembers.

private void executeOnMembers(String[] args) {
    // executeOnMembers <echo-string>
    try {
        IExecutorService executorService = hazelcast.getExecutorService("default");
        Echo task = new Echo(args[1]);
        Map<Member, Future<String>> results = executorService.submitToAllMembers(task);
        for (Future f : results.values()) {
            println(f.get());
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : Echo(com.hazelcast.console.Echo) Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member)

Aggregations

Member (com.hazelcast.core.Member)318 Test (org.junit.Test)134 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)113 HazelcastInstance (com.hazelcast.core.HazelcastInstance)96 Address (com.hazelcast.nio.Address)60 IExecutorService (com.hazelcast.core.IExecutorService)57 ArrayList (java.util.ArrayList)45 Future (java.util.concurrent.Future)45 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)41 CountDownLatch (java.util.concurrent.CountDownLatch)37 Config (com.hazelcast.config.Config)35 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)26 IMap (com.hazelcast.core.IMap)24 HashMap (java.util.HashMap)22 LinkedList (java.util.LinkedList)20 OperationService (com.hazelcast.spi.OperationService)19 AssertTask (com.hazelcast.test.AssertTask)19 HashSet (java.util.HashSet)19 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)18