Search in sources :

Example 46 with IScheduledExecutorService

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;
}
Also used : IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) Member(com.hazelcast.cluster.Member)

Example 47 with IScheduledExecutorService

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;
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) HashMap(java.util.HashMap) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member)

Example 48 with IScheduledExecutorService

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with IScheduledExecutorService

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with IScheduledExecutorService

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)94 HazelcastInstance (com.hazelcast.core.HazelcastInstance)83 Test (org.junit.Test)83 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)81 QuickTest (com.hazelcast.test.annotation.QuickTest)70 IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)38 ICountDownLatch (com.hazelcast.cp.ICountDownLatch)29 Config (com.hazelcast.config.Config)21 ScheduledExecutorConfig (com.hazelcast.config.ScheduledExecutorConfig)21 Member (com.hazelcast.cluster.Member)18 SlowTest (com.hazelcast.test.annotation.SlowTest)15 ArrayList (java.util.ArrayList)11 ScheduledTaskHandler (com.hazelcast.scheduledexecutor.ScheduledTaskHandler)10 HashMap (java.util.HashMap)6 List (java.util.List)6 RootCauseMatcher (com.hazelcast.internal.util.RootCauseMatcher)4 ScheduledTaskStatistics (com.hazelcast.scheduledexecutor.ScheduledTaskStatistics)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 Address (com.hazelcast.cluster.Address)2 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)2