Search in sources :

Example 11 with Member

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

the class ClientConsoleApp method handleExecutorSimulate.

private void handleExecutorSimulate(String[] args) {
    String first = args[0];
    int threadCount = Integer.parseInt(first.substring(1, first.indexOf(".")));
    if (threadCount < 1 || threadCount > MAX_THREAD_COUNT) {
        throw new RuntimeException("threadcount can't be smaller than 1 or larger than 16");
    }
    int taskCount = Integer.parseInt(args[1]);
    int durationSec = Integer.parseInt(args[2]);
    long startMs = System.currentTimeMillis();
    IExecutorService executor = hazelcast.getExecutorService(executorNamespace + ' ' + threadCount);
    List<Future> futures = new LinkedList<Future>();
    List<Member> members = new LinkedList<Member>(hazelcast.getCluster().getMembers());
    int totalThreadCount = hazelcast.getCluster().getMembers().size() * threadCount;
    int latchId = 0;
    for (int k = 0; k < taskCount; k++) {
        Member member = members.get(k % members.size());
        if (taskCount % totalThreadCount == 0) {
            latchId = taskCount / totalThreadCount;
            hazelcast.getCountDownLatch("latch" + latchId).trySetCount(totalThreadCount);
        }
        Future f = executor.submitToMember(new SimulateLoadTask(durationSec, k + 1, "latch" + latchId), member);
        futures.add(f);
    }
    for (Future f : futures) {
        try {
            f.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
    long durationMs = System.currentTimeMillis() - startMs;
    println(format("Executed %s tasks in %s ms", taskCount, durationMs));
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) LinkedList(java.util.LinkedList) Future(java.util.concurrent.Future) SimulateLoadTask(com.hazelcast.console.SimulateLoadTask) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member)

Example 12 with Member

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

the class ClientClusterServiceImpl method handleInitialMembershipEvent.

void handleInitialMembershipEvent(InitialMembershipEvent event) {
    synchronized (initialMembershipListenerMutex) {
        Set<Member> initialMembers = event.getMembers();
        LinkedHashMap<Address, Member> newMap = new LinkedHashMap<Address, Member>();
        for (Member initialMember : initialMembers) {
            newMap.put(initialMember.getAddress(), initialMember);
        }
        members.set(Collections.unmodifiableMap(newMap));
        fireInitialMembershipEvent(event);
    }
}
Also used : Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) Member(com.hazelcast.core.Member) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with Member

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

the class ClientMembershipListener method membersString.

private String membersString() {
    StringBuilder sb = new StringBuilder("\n\nMembers [");
    sb.append(members.size());
    sb.append("] {");
    for (Member member : members) {
        sb.append("\n\t").append(member);
    }
    sb.append("\n}\n");
    return sb.toString();
}
Also used : AbstractMember(com.hazelcast.instance.AbstractMember) Member(com.hazelcast.core.Member)

Example 14 with Member

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

the class ClientScheduledExecutorProxy method getAllScheduledFutures.

@Override
public <V> Map<Member, List<IScheduledFuture<V>>> getAllScheduledFutures() {
    ClientMessage request = ScheduledExecutorGetAllScheduledFuturesCodec.encodeRequest(getName());
    final ClientInvocationFuture future = new ClientInvocation(getClient(), request).invoke();
    ClientMessage response;
    try {
        response = future.get();
    } catch (Exception e) {
        throw rethrow(e);
    }
    Collection<Map.Entry<Member, List<ScheduledTaskHandler>>> urnsPerMember = ScheduledExecutorGetAllScheduledFuturesCodec.decodeResponse(response).handlers;
    Map<Member, List<IScheduledFuture<V>>> tasksMap = new HashMap<Member, List<IScheduledFuture<V>>>();
    for (Map.Entry<Member, List<ScheduledTaskHandler>> entry : urnsPerMember) {
        List<IScheduledFuture<V>> memberTasks = new ArrayList<IScheduledFuture<V>>();
        for (ScheduledTaskHandler scheduledTaskHandler : entry.getValue()) {
            memberTasks.add(new ClientScheduledFutureProxy(scheduledTaskHandler, getContext()));
        }
        tasksMap.put(entry.getKey(), memberTasks);
    }
    return tasksMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Member(com.hazelcast.core.Member) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with Member

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

the class ClientScheduledExecutorProxy method scheduleOnMembers.

@Override
public <V> Map<Member, IScheduledFuture<V>> scheduleOnMembers(Callable<V> command, Collection<Member> members, long delay, TimeUnit unit) {
    checkNotNull(command, "Command is null");
    checkNotNull(members, "Members is null");
    checkNotNull(unit, "Unit is null");
    String name = extractNameOrGenerateOne(command);
    Map<Member, IScheduledFuture<V>> futures = new HashMap<Member, IScheduledFuture<V>>();
    for (Member member : members) {
        TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.SINGLE_RUN, name, command, delay, unit);
        futures.put(member, (IScheduledFuture<V>) scheduleOnMember(name, member, definition));
    }
    return futures;
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) TaskDefinition(com.hazelcast.scheduledexecutor.impl.TaskDefinition) HashMap(java.util.HashMap) 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