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 memberUUID The member 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> ScheduledTaskFuture<V> schedule(String memberUUID, Callable<V> callable, long delay, TimeUnit unit) {
ScheduledTaskFuture result = null;
if (hzCore.isEnabled()) {
Member toSubmitTo = selectMember(memberUUID);
IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME);
IScheduledFuture<V> schedule = scheduledExecutorService.scheduleOnMember(callable, toSubmitTo, delay, unit);
result = new ScheduledTaskFuture(schedule);
}
return result;
}
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 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.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method capacity_onMember_whenPositiveLimit_perPartition_shouldNotReject.
@Test
public void capacity_onMember_whenPositiveLimit_perPartition_shouldNotReject() {
String schedulerName = ANY_EXECUTOR_NAME;
ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(10).setCapacityPolicy(ScheduledExecutorConfig.CapacityPolicy.PER_PARTITION);
Config config = new Config().addScheduledExecutorConfig(sec);
HazelcastInstance[] instances = createClusterWithCount(1, config);
IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
Member member = instances[0].getCluster().getLocalMember();
for (int i = 0; i < 10; i++) {
service.scheduleOnMember(new PlainCallableTask(), member, 0, TimeUnit.SECONDS);
}
// Should pass - PER_PARTITION policy disables MEMBER OWNED capacity checking
service.scheduleOnMember(new PlainCallableTask(), member, 0, TimeUnit.SECONDS);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_whenShutdown.
@Test(expected = RejectedExecutionException.class)
public void schedule_whenShutdown() {
int delay = 1;
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
executorService.schedule(new PlainCallableTask(), delay, SECONDS);
executorService.shutdown();
executorService.schedule(new PlainCallableTask(), delay, SECONDS);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method getErroneous_durable.
@Test
public void getErroneous_durable() throws Exception {
int delay = 2;
String taskName = "Test";
String completionLatchName = "completionLatch";
HazelcastInstance[] instances = createClusterWithCount(2);
String key = generateKeyOwnedBy(instances[1]);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
ICountDownLatch latch = instances[1].getCPSubsystem().getCountDownLatch(completionLatchName);
latch.trySetCount(1);
IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
assertOpenEventually(latch);
instances[1].getLifecycleService().shutdown();
Thread.sleep(2000);
expected.expect(ExecutionException.class);
expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
future.get();
}
Aggregations