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<UUID, ScheduledTaskFuture<?>> scheduleAtFixedRate(Collection<UUID> memberUUIDs, Runnable runnable, long delay, long period, TimeUnit unit) {
HashMap<UUID, 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<Object>> schedule = scheduledExecutorService.<Object>scheduleOnMembersAtFixedRate(runnable, toSubmitTo, delay, period, unit);
for (Entry<Member, IScheduledFuture<Object>> entry : schedule.entrySet()) {
Member member = entry.getKey();
result.put(member.getUuid(), new ScheduledTaskFuture<>(entry.getValue()));
}
}
return result;
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ClientScheduledExecutorProxy 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");
String name = extractNameOrGenerateOne(command);
Callable adapter = createScheduledRunnableAdapter(command);
Map<Member, IScheduledFuture<V>> futures = new HashMap<>();
for (Member member : members) {
TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.AT_FIXED_RATE, name, adapter, initialDelay, period, unit, false);
futures.put(member, scheduleOnMember(name, member, definition));
}
return futures;
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ClientScheduledExecutorProxy 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");
String name = extractNameOrGenerateOne(command);
Map<Member, IScheduledFuture<V>> futures = new HashMap<>();
boolean autoDisposable = isAutoDisposable(command);
for (Member member : members) {
TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.SINGLE_RUN, name, command, delay, unit, autoDisposable);
futures.put(member, scheduleOnMember(name, member, definition));
}
return futures;
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method config.
@Test
public void config() {
String schedulerName = ANY_EXECUTOR_NAME;
ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(5).setPoolSize(24);
Config config = new Config().addScheduledExecutorConfig(sec);
HazelcastInstance[] instances = createClusterWithCount(1, config);
IScheduledFuture future = instances[0].getScheduledExecutorService(schedulerName).schedule(new PlainCallableTask(), 0, SECONDS);
NodeEngineImpl nodeEngine = getNodeEngineImpl(instances[0]);
ManagedExecutorService mes = (ManagedExecutorService) nodeEngine.getExecutionService().getScheduledDurable(sec.getName());
DistributedScheduledExecutorService dses = nodeEngine.getService(DistributedScheduledExecutorService.SERVICE_NAME);
assertNotNull(mes);
assertEquals(24, mes.getMaximumPoolSize());
assertEquals(5, dses.getPartition(future.getHandler().getPartitionId()).getOrCreateContainer(schedulerName).getDurability());
assertEquals(1, dses.getPartition(future.getHandler().getPartitionId()).getOrCreateContainer("other").getDurability());
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_andCancel.
@Test
public void schedule_andCancel() {
HazelcastInstance[] instances = createClusterWithCount(2);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture future = executorService.scheduleAtFixedRate(new ICountdownLatchRunnableTask("latch"), 1, 1, SECONDS);
sleepSeconds(5);
assertFalse(future.isCancelled());
assertFalse(future.isDone());
future.cancel(false);
assertTrue(future.isCancelled());
assertTrue(future.isDone());
}
Aggregations