Search in sources :

Example 1 with TaskDefinition

use of com.hazelcast.scheduledexecutor.impl.TaskDefinition in project hazelcast by hazelcast.

the class ClientScheduledExecutorProxy method scheduleOnKeyOwnerAtFixedRate.

@Override
public IScheduledFuture<?> scheduleOnKeyOwnerAtFixedRate(Runnable command, Object key, long initialDelay, long period, TimeUnit unit) {
    checkNotNull(command, "Command is null");
    checkNotNull(key, "Key is null");
    checkNotNull(unit, "Unit is null");
    String name = extractNameOrGenerateOne(command);
    int partitionId = getKeyPartitionId(key);
    Callable adapter = createScheduledRunnableAdapter(command);
    TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.AT_FIXED_RATE, name, adapter, initialDelay, period, unit);
    return scheduleOnPartition(name, definition, partitionId);
}
Also used : TaskDefinition(com.hazelcast.scheduledexecutor.impl.TaskDefinition) Callable(java.util.concurrent.Callable)

Example 2 with TaskDefinition

use of com.hazelcast.scheduledexecutor.impl.TaskDefinition 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)

Example 3 with TaskDefinition

use of com.hazelcast.scheduledexecutor.impl.TaskDefinition in project hazelcast by hazelcast.

the class ScheduledExecutorSubmitToPartitionMessageTask method getParameters.

@Override
public Object[] getParameters() {
    Callable callable = serializationService.toObject(parameters.task);
    TaskDefinition def = new TaskDefinition(TaskDefinition.Type.getById(parameters.type), parameters.taskName, callable, parameters.initialDelayInMillis, parameters.periodInMillis, TimeUnit.MILLISECONDS);
    return new Object[] { parameters.schedulerName, def };
}
Also used : TaskDefinition(com.hazelcast.scheduledexecutor.impl.TaskDefinition) Callable(java.util.concurrent.Callable)

Example 4 with TaskDefinition

use of com.hazelcast.scheduledexecutor.impl.TaskDefinition in project hazelcast by hazelcast.

the class ClientScheduledExecutorProxy method scheduleOnKeyOwner.

@Override
public <V> IScheduledFuture<V> scheduleOnKeyOwner(Callable<V> command, Object key, long delay, TimeUnit unit) {
    checkNotNull(command, "Command is null");
    checkNotNull(key, "Key is null");
    checkNotNull(unit, "Unit is null");
    String name = extractNameOrGenerateOne(command);
    int partitionId = getKeyPartitionId(key);
    TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.SINGLE_RUN, name, command, delay, unit);
    return scheduleOnPartition(name, definition, partitionId);
}
Also used : TaskDefinition(com.hazelcast.scheduledexecutor.impl.TaskDefinition)

Example 5 with TaskDefinition

use of com.hazelcast.scheduledexecutor.impl.TaskDefinition in project hazelcast by hazelcast.

the class ClientScheduledExecutorProxy 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");
    String name = extractNameOrGenerateOne(command);
    Callable adapter = createScheduledRunnableAdapter(command);
    Map<Member, IScheduledFuture<?>> futures = new HashMap<Member, IScheduledFuture<?>>();
    for (Member member : members) {
        TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.AT_FIXED_RATE, name, adapter, initialDelay, period, unit);
        futures.put(member, 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) Callable(java.util.concurrent.Callable)

Aggregations

TaskDefinition (com.hazelcast.scheduledexecutor.impl.TaskDefinition)9 Callable (java.util.concurrent.Callable)7 Member (com.hazelcast.core.Member)2 IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)2 ScheduleTaskOperation (com.hazelcast.scheduledexecutor.impl.operations.ScheduleTaskOperation)2 HashMap (java.util.HashMap)2