use of com.hazelcast.scheduledexecutor.IScheduledFuture in project Payara by payara.
the class ClusterExecutionService method schedule.
/**
* Schedules a Callable object to be run in the future on the specified Member
* @param <V> The type of the result
* @param memberUUIDs The members to schedule the task on
* @param callable The Callable Object
* @param delay The delay before running the task
* @param unit The time unit of the delay
* @return A Future containing the result
*/
public <V extends Serializable> Map<String, ScheduledTaskFuture<V>> schedule(Collection<String> memberUUIDs, Callable<V> callable, long delay, TimeUnit unit) {
HashMap<String, ScheduledTaskFuture<V>> result = new HashMap<>(2);
if (hzCore.isEnabled()) {
Collection<Member> toSubmitTo = selectMembers(memberUUIDs);
IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME);
Map<Member, IScheduledFuture<V>> schedule = scheduledExecutorService.scheduleOnMembers(callable, toSubmitTo, delay, unit);
for (Member member : schedule.keySet()) {
result.put(member.getUuid(), new ScheduledTaskFuture<>(schedule.get(member)));
}
}
return result;
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project Payara by payara.
the class ClusterExecutionService method scheduleAtFixedRate.
/**
* Schedules a Callable object to be run in the future on the specified Member
* @param memberUUIDs The members to schedule the task on
* @param runnable The Runnable Object
* @param delay The delay before running the task
* @param period The period of the fixed rate
* @param unit The time unit of the delay
* @return A Future containing the result
*/
public Map<String, ScheduledTaskFuture<?>> scheduleAtFixedRate(Collection<String> memberUUIDs, Runnable runnable, long delay, long period, TimeUnit unit) {
HashMap<String, ScheduledTaskFuture<?>> result = new HashMap<>(2);
if (hzCore.isEnabled()) {
Collection<Member> toSubmitTo = selectMembers(memberUUIDs);
IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME);
Map<Member, IScheduledFuture<?>> schedule = scheduledExecutorService.scheduleOnMembersAtFixedRate(runnable, toSubmitTo, delay, period, unit);
for (Member member : schedule.keySet()) {
result.put(member.getUuid(), new ScheduledTaskFuture<>(schedule.get(member)));
}
}
return result;
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ScheduledExecutorServiceProxy method scheduleOnMembersAtFixedRate.
@Nonnull
@Override
public <V> Map<Member, IScheduledFuture<V>> scheduleOnMembersAtFixedRate(@Nonnull Runnable command, @Nonnull Collection<Member> members, long initialDelay, long period, @Nonnull TimeUnit unit) {
checkNotNull(command, "Command is null");
checkNotNull(members, "Members is null");
checkNotNull(unit, "Unit is null");
command = initializeManagedContext(command);
String name = extractNameOrGenerateOne(command);
ScheduledRunnableAdapter<?> adapter = createScheduledRunnableAdapter(command);
Map<Member, IScheduledFuture<V>> futures = createHashMapAdapter(members.size());
for (Member member : members) {
TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.AT_FIXED_RATE, name, adapter, initialDelay, period, unit, false);
futures.put(member, submitOnMemberSync(name, new ScheduleTaskOperation(getName(), definition), member));
}
return futures;
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture 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<>();
for (ScheduledTaskHandler handler : handlers) {
IScheduledFuture future = new ScheduledFutureProxy(handler, this);
futures.add(initializeManagedContext(future));
}
if (accumulator.containsKey(owner)) {
List<IScheduledFuture<V>> memberFutures = accumulator.get(owner);
memberFutures.addAll(futures);
} else {
accumulator.put(owner, futures);
}
}
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ScheduledExecutorServiceProxy method scheduleOnMembers.
@Nonnull
@Override
public <V> Map<Member, IScheduledFuture<V>> scheduleOnMembers(@Nonnull Callable<V> command, @Nonnull Collection<Member> members, long delay, @Nonnull TimeUnit unit) {
checkNotNull(command, "Command is null");
checkNotNull(members, "Members is null");
checkNotNull(unit, "Unit is null");
command = initializeManagedContext(command);
String name = extractNameOrGenerateOne(command);
Map<Member, IScheduledFuture<V>> futures = createHashMap(members.size());
boolean autoDisposable = isAutoDisposable(command);
for (Member member : members) {
TaskDefinition<V> definition = new TaskDefinition<>(TaskDefinition.Type.SINGLE_RUN, name, command, delay, unit, autoDisposable);
futures.put(member, submitOnMemberSync(name, new ScheduleTaskOperation(getName(), definition), member));
}
return futures;
}
Aggregations