Search in sources :

Example 36 with IScheduledExecutorService

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

Example 37 with IScheduledExecutorService

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

Example 38 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
 * @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;
}
Also used : IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService)

Example 39 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
 * @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;
}
Also used : IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService)

Example 40 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 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;
}
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)

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