Search in sources :

Example 76 with Member

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

the class ClientMapMetaDataFetcher method scanMembers.

@Override
protected List<InternalCompletableFuture> scanMembers(List<String> names) {
    Collection<Member> members = clusterService.getMembers(DATA_MEMBER_SELECTOR);
    List<InternalCompletableFuture> futures = new ArrayList<InternalCompletableFuture>(members.size());
    for (Member member : members) {
        Address address = member.getAddress();
        ClientMessage message = encodeRequest(names, address);
        ClientInvocation invocation = new ClientInvocation(clientImpl, message, address);
        try {
            futures.add(invocation.invoke());
        } catch (Exception e) {
            if (logger.isWarningEnabled()) {
                logger.warning("Cant fetch invalidation meta-data from address + " + address + " + [" + e.getMessage() + "]");
            }
        }
    }
    return futures;
}
Also used : Address(com.hazelcast.nio.Address) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ArrayList(java.util.ArrayList) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Member(com.hazelcast.core.Member) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 77 with Member

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

the class ExecuteScriptRequest method writeResponse.

@Override
public void writeResponse(ManagementCenterService mcs, JsonObject root) throws Exception {
    JsonObject jsonResult = new JsonObject();
    ArrayList results;
    if (targetAllMembers) {
        Set<Member> members = mcs.getHazelcastInstance().getCluster().getMembers();
        ArrayList<Object> list = new ArrayList<Object>(members.size());
        for (Member member : members) {
            list.add(mcs.callOnMember(member, new ScriptExecutorOperation(engine, script, bindings)));
        }
        results = list;
    } else {
        ArrayList<Object> list = new ArrayList<Object>(targets.size());
        for (String address : targets) {
            AddressUtil.AddressHolder addressHolder = AddressUtil.getAddressHolder(address);
            Address targetAddress = new Address(addressHolder.getAddress(), addressHolder.getPort());
            list.add(mcs.callOnAddress(targetAddress, new ScriptExecutorOperation(engine, script, bindings)));
        }
        results = list;
    }
    StringBuilder sb = new StringBuilder();
    for (Object result : results) {
        if (result instanceof String) {
            sb.append(result);
        } else if (result instanceof List) {
            List list = (List) result;
            for (Object o : list) {
                sb.append(o).append("\n");
            }
        } else if (result instanceof Map) {
            Map map = (Map) result;
            for (Object o : map.entrySet()) {
                Map.Entry entry = (Map.Entry) o;
                sb.append(entry.getKey()).append("->").append(entry.getValue()).append("\n");
            }
        } else if (result == null) {
            sb.append("error");
        }
        sb.append("\n");
    }
    jsonResult.add("scriptResult", sb.toString());
    root.add("result", jsonResult);
}
Also used : AddressUtil(com.hazelcast.util.AddressUtil) Address(com.hazelcast.nio.Address) ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject) JsonUtil.getString(com.hazelcast.util.JsonUtil.getString) ScriptExecutorOperation(com.hazelcast.internal.management.operation.ScriptExecutorOperation) JsonObject(com.eclipsesource.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Member(com.hazelcast.core.Member) HashMap(java.util.HashMap) Map(java.util.Map)

Example 78 with Member

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

the class MapReduceService method checkAssignedMembersAvailable.

public boolean checkAssignedMembersAvailable(Collection<Address> assignedMembers) {
    Collection<Member> members = clusterService.getMembers();
    List<Address> addresses = new ArrayList<Address>(members.size());
    for (Member member : members) {
        addresses.add(member.getAddress());
    }
    for (Address address : assignedMembers) {
        if (!addresses.contains(address)) {
            return false;
        }
    }
    return true;
}
Also used : Address(com.hazelcast.nio.Address) ArrayList(java.util.ArrayList) Member(com.hazelcast.core.Member)

Example 79 with Member

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

the class SingleNodeTest method alwaysFalseMemberSelector_expectRejection.

@Test(expected = RejectedExecutionException.class)
public void alwaysFalseMemberSelector_expectRejection() {
    HazelcastInstanceAwareRunnable task = new HazelcastInstanceAwareRunnable();
    executor.execute(task, new MemberSelector() {

        @Override
        public boolean select(Member member) {
            return false;
        }
    });
}
Also used : MemberSelector(com.hazelcast.core.MemberSelector) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 80 with Member

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

the class ClusterListenerSupport method getSocketAddresses.

private Collection<InetSocketAddress> getSocketAddresses() {
    final List<InetSocketAddress> socketAddresses = new LinkedList<InetSocketAddress>();
    Collection<Member> memberList = getMemberList();
    for (Member member : memberList) {
        socketAddresses.add(member.getSocketAddress());
    }
    for (AddressProvider addressProvider : addressProviders) {
        socketAddresses.addAll(addressProvider.loadAddresses());
    }
    if (shuffleMemberList) {
        Collections.shuffle(socketAddresses);
    }
    return socketAddresses;
}
Also used : AddressProvider(com.hazelcast.client.connection.AddressProvider) InetSocketAddress(java.net.InetSocketAddress) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

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