Search in sources :

Example 6 with ScheduleTaskOperation

use of com.hazelcast.scheduledexecutor.impl.operations.ScheduleTaskOperation in project hazelcast by hazelcast.

the class ScheduledExecutorServiceProxy method scheduleAtFixedRate.

@Override
public IScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
    checkNotNull(command, "Command is null");
    checkNotNull(unit, "Unit is null");
    attachHazelcastInstance(command);
    String name = extractNameOrGenerateOne(command);
    int partitionId = getTaskOrKeyPartitionId(command, name);
    ScheduledRunnableAdapter<?> adapter = createScheduledRunnableAdapter(command);
    TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.AT_FIXED_RATE, name, adapter, initialDelay, period, unit);
    return submitOnPartitionSync(name, new ScheduleTaskOperation(getName(), definition), partitionId);
}
Also used : ScheduleTaskOperation(com.hazelcast.scheduledexecutor.impl.operations.ScheduleTaskOperation)

Example 7 with ScheduleTaskOperation

use of com.hazelcast.scheduledexecutor.impl.operations.ScheduleTaskOperation in project hazelcast by hazelcast.

the class ScheduledExecutorServiceProxy method scheduleOnMembersAtFixedRate.

@Override
public Map<Member, IScheduledFuture<?>> scheduleOnMembersAtFixedRate(Runnable command, Collection<Member> members, long initialDelay, long period, TimeUnit unit) {
    checkNotNull(command, "Command is null");
    checkNotNull(members, "Members is null");
    checkNotNull(unit, "Unit is null");
    attachHazelcastInstance(command);
    String name = extractNameOrGenerateOne(command);
    ScheduledRunnableAdapter<?> adapter = createScheduledRunnableAdapter(command);
    Map<Member, IScheduledFuture<?>> futures = new HashMapAdapter<Member, IScheduledFuture<?>>();
    for (Member member : members) {
        TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.AT_FIXED_RATE, name, adapter, initialDelay, period, unit);
        futures.put(member, submitOnMemberSync(name, new ScheduleTaskOperation(getName(), definition), member));
    }
    return futures;
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ScheduleTaskOperation(com.hazelcast.scheduledexecutor.impl.operations.ScheduleTaskOperation) HashMapAdapter(com.hazelcast.mapreduce.impl.HashMapAdapter) Member(com.hazelcast.core.Member)

Example 8 with ScheduleTaskOperation

use of com.hazelcast.scheduledexecutor.impl.operations.ScheduleTaskOperation in project hazelcast by hazelcast.

the class ScheduledExecutorServiceProxy 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");
    attachHazelcastInstance(command);
    String name = extractNameOrGenerateOne(command);
    Map<Member, IScheduledFuture<V>> futures = new HashMap<Member, IScheduledFuture<V>>();
    for (Member member : members) {
        TaskDefinition<V> definition = new TaskDefinition<V>(TaskDefinition.Type.SINGLE_RUN, name, command, delay, unit);
        futures.put(member, (IScheduledFuture<V>) submitOnMemberSync(name, new ScheduleTaskOperation(getName(), definition), member));
    }
    return futures;
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ScheduleTaskOperation(com.hazelcast.scheduledexecutor.impl.operations.ScheduleTaskOperation) Member(com.hazelcast.core.Member)

Aggregations

ScheduleTaskOperation (com.hazelcast.scheduledexecutor.impl.operations.ScheduleTaskOperation)8 Member (com.hazelcast.core.Member)2 IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)2 TaskDefinition (com.hazelcast.scheduledexecutor.impl.TaskDefinition)2 Callable (java.util.concurrent.Callable)2 HashMapAdapter (com.hazelcast.mapreduce.impl.HashMapAdapter)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1