use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_withNamedInstanceAware_whenLocalRun.
@Test
public void schedule_withNamedInstanceAware_whenLocalRun() {
HazelcastInstance[] instances = createClusterWithCount(1);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
s.schedule(TaskUtils.named("blah", new PlainInstanceAwareRunnableTask("latch")), 1, TimeUnit.SECONDS);
assertOpenEventually(latch);
assertEquals(0, latch.getCount());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorSplitBrainTest method onBeforeSplitBrainCreated.
@Override
protected void onBeforeSplitBrainCreated(HazelcastInstance[] instances) {
waitAllForSafeState(instances);
IScheduledExecutorService executorService = instances[0].getScheduledExecutorService(scheduledExecutorName);
for (int i = 0; i < INITIAL_COUNT; i++) {
schedule(executorService, i, EXPECTED_VALUE);
}
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project Payara by payara.
the class ClusterExecutionService method scheduleAtFixedRate.
/**
* Schedules a Callable object to be run in the future
* @param runnable The Runnable Object
* @param delay The delay before running the task
* @param period The period for the fixed rate
* @param unit The time unit of the delay
* @return A Future containing the result
*/
public ScheduledTaskFuture<? extends Serializable> scheduleAtFixedRate(Runnable runnable, long delay, long period, TimeUnit unit) {
ScheduledTaskFuture result = null;
if (hzCore.isEnabled()) {
IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME);
IScheduledFuture<?> schedule = scheduledExecutorService.scheduleAtFixedRate(runnable, delay, period, unit);
result = new ScheduledTaskFuture(schedule);
}
return result;
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project Payara by payara.
the class ClusterExecutionService method schedule.
/**
* Schedules a Callable object to be run in the future
* @param <V> The type of the result
* @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> ScheduledTaskFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
ScheduledTaskFuture result = null;
if (hzCore.isEnabled()) {
IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME);
IScheduledFuture<V> schedule = scheduledExecutorService.schedule(callable, delay, unit);
result = new ScheduledTaskFuture(schedule);
}
return result;
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService 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<UUID, ScheduledTaskFuture<V>> schedule(Collection<UUID> memberUUIDs, Callable<V> callable, long delay, TimeUnit unit) {
HashMap<UUID, 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 (Entry<Member, IScheduledFuture<V>> entry : schedule.entrySet()) {
Member member = entry.getKey();
result.put(member.getUuid(), new ScheduledTaskFuture<>(entry.getValue()));
}
}
return result;
}
Aggregations