Search in sources :

Example 1 with ScheduledTaskHandler

use of com.hazelcast.scheduledexecutor.ScheduledTaskHandler 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 2 with ScheduledTaskHandler

use of com.hazelcast.scheduledexecutor.ScheduledTaskHandler in project hazelcast by hazelcast.

the class ScheduledExecutorGetAllScheduledMessageTask method accumulateTaskHandlersAsUrnValues.

@SuppressWarnings("unchecked")
private void accumulateTaskHandlersAsUrnValues(Map<Member, List<ScheduledTaskHandler>> accumulator, Map<?, ?> taskHandlersMap) {
    ClusterService clusterService = nodeEngine.getClusterService();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    for (Map.Entry<?, ?> entry : taskHandlersMap.entrySet()) {
        Member owner;
        Object key = entry.getKey();
        if (key instanceof Number) {
            owner = clusterService.getMember(partitionService.getPartitionOwner((Integer) key));
        } else {
            owner = (Member) key;
        }
        List<ScheduledTaskHandler> handlers = (List<ScheduledTaskHandler>) entry.getValue();
        if (accumulator.containsKey(owner)) {
            List<ScheduledTaskHandler> memberUrns = accumulator.get(owner);
            memberUrns.addAll(handlers);
        } else {
            accumulator.put(owner, handlers);
        }
    }
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) IPartitionService(com.hazelcast.spi.partition.IPartitionService) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Member(com.hazelcast.core.Member)

Example 3 with ScheduledTaskHandler

use of com.hazelcast.scheduledexecutor.ScheduledTaskHandler in project hazelcast by hazelcast.

the class ScheduledExecutorWaitNotifyKeyTest method equals_fail_withDiffDistObject.

@Test
public void equals_fail_withDiffDistObject() throws Exception {
    ScheduledTaskHandler handlerA = ScheduledTaskHandlerImpl.of(1, "MyScheduler", "MyTask");
    String myTaskURN = handlerA.toUrn();
    ScheduledTaskHandler handlerB = ScheduledTaskHandlerImpl.of(1, "MyScheduler", "MyTask2");
    String myTask2URN = handlerB.toUrn();
    ScheduledExecutorWaitNotifyKey keyA = new ScheduledExecutorWaitNotifyKey("myScheduler", myTaskURN);
    ScheduledExecutorWaitNotifyKey keyB = new ScheduledExecutorWaitNotifyKey("myWrongScheduler", myTask2URN);
    assertFalse(keyA.equals(keyB));
}
Also used : ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) Test(org.junit.Test)

Example 4 with ScheduledTaskHandler

use of com.hazelcast.scheduledexecutor.ScheduledTaskHandler in project hazelcast by hazelcast.

the class ScheduledExecutorWaitNotifyKeyTest method hashcode_fail_withDiffURN.

@Test
public void hashcode_fail_withDiffURN() throws Exception {
    ScheduledTaskHandler handlerA = ScheduledTaskHandlerImpl.of(1, "MyScheduler", "MyTask");
    String myTaskURN = handlerA.toUrn();
    ScheduledTaskHandler handlerB = ScheduledTaskHandlerImpl.of(1, "MyScheduler", "MyTask2");
    String myTask2URN = handlerB.toUrn();
    ScheduledExecutorWaitNotifyKey keyA = new ScheduledExecutorWaitNotifyKey("myScheduler", myTaskURN);
    ScheduledExecutorWaitNotifyKey keyB = new ScheduledExecutorWaitNotifyKey("myScheduler", myTask2URN);
    assertNotEquals(keyA.hashCode(), keyB.hashCode());
}
Also used : ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) Test(org.junit.Test)

Example 5 with ScheduledTaskHandler

use of com.hazelcast.scheduledexecutor.ScheduledTaskHandler in project hazelcast by hazelcast.

the class ScheduledExecutorWaitNotifyKeyTest method equals_fail_withDiffURN.

@Test
public void equals_fail_withDiffURN() throws Exception {
    ScheduledTaskHandler handlerA = ScheduledTaskHandlerImpl.of(1, "MyScheduler", "MyTask");
    String myTaskURN = handlerA.toUrn();
    ScheduledTaskHandler handlerB = ScheduledTaskHandlerImpl.of(1, "MyScheduler", "MyTask2");
    String myTask2URN = handlerB.toUrn();
    ScheduledExecutorWaitNotifyKey keyA = new ScheduledExecutorWaitNotifyKey("myScheduler", myTaskURN);
    ScheduledExecutorWaitNotifyKey keyB = new ScheduledExecutorWaitNotifyKey("myScheduler", myTask2URN);
    assertFalse(keyA.equals(keyB));
}
Also used : ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) Test(org.junit.Test)

Aggregations

ScheduledTaskHandler (com.hazelcast.scheduledexecutor.ScheduledTaskHandler)19 Test (org.junit.Test)13 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 ArrayList (java.util.ArrayList)4 Member (com.hazelcast.core.Member)3 List (java.util.List)3 Map (java.util.Map)3 ClusterService (com.hazelcast.internal.cluster.ClusterService)2 Address (com.hazelcast.nio.Address)2 IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)2 DistributedScheduledExecutorService (com.hazelcast.scheduledexecutor.impl.DistributedScheduledExecutorService)2 IPartitionService (com.hazelcast.spi.partition.IPartitionService)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)1 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)1 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)1