Search in sources :

Example 11 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 12 with ScheduledTaskHandler

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

the class ScheduledExecutorServiceProxy method accumulateTaskHandlersAsScheduledFutures.

@SuppressWarnings("unchecked")
private <V> void accumulateTaskHandlersAsScheduledFutures(Map<Member, List<IScheduledFuture<V>>> accumulator, Map<?, ?> taskHandlersMap) {
    ClusterService clusterService = getNodeEngine().getClusterService();
    IPartitionService partitionService = getNodeEngine().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();
        List<IScheduledFuture<V>> futures = new ArrayList<IScheduledFuture<V>>();
        for (ScheduledTaskHandler handler : handlers) {
            IScheduledFuture future = new ScheduledFutureProxy(handler);
            attachHazelcastInstance(future);
            futures.add(future);
        }
        if (accumulator.containsKey(owner)) {
            List<IScheduledFuture<V>> memberFutures = accumulator.get(owner);
            memberFutures.addAll(futures);
        } else {
            accumulator.put(owner, futures);
        }
    }
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) ArrayList(java.util.ArrayList) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ClusterService(com.hazelcast.internal.cluster.ClusterService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Member(com.hazelcast.core.Member)

Example 13 with ScheduledTaskHandler

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

the class ScheduledTaskHandlerImpl method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    ScheduledTaskHandler handler = of(in.readUTF());
    this.address = handler.getAddress();
    this.partitionId = handler.getPartitionId();
    this.schedulerName = handler.getSchedulerName();
    this.taskName = handler.getTaskName();
}
Also used : ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler)

Example 14 with ScheduledTaskHandler

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

the class GetAllScheduledOnMemberOperation method run.

@Override
public void run() throws Exception {
    List<ScheduledTaskHandler> handlers = new ArrayList<ScheduledTaskHandler>();
    DistributedScheduledExecutorService service = getService();
    populateScheduledForHolder(handlers, service, MEMBER_BIN);
    response = handlers;
}
Also used : DistributedScheduledExecutorService(com.hazelcast.scheduledexecutor.impl.DistributedScheduledExecutorService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ArrayList(java.util.ArrayList)

Example 15 with ScheduledTaskHandler

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

the class GetAllScheduledOnPartitionOperation method run.

@Override
public void run() throws Exception {
    List<ScheduledTaskHandler> handlers = new ArrayList<ScheduledTaskHandler>();
    DistributedScheduledExecutorService service = getService();
    populateScheduledForHolder(handlers, service, getPartitionId());
    response = handlers;
}
Also used : DistributedScheduledExecutorService(com.hazelcast.scheduledexecutor.impl.DistributedScheduledExecutorService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ArrayList(java.util.ArrayList)

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