Search in sources :

Example 41 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<String, ScheduledTaskFuture<V>> schedule(Collection<String> memberUUIDs, Callable<V> callable, long delay, TimeUnit unit) {
    HashMap<String, 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 (Member member : schedule.keySet()) {
            result.put(member.getUuid(), new ScheduledTaskFuture<>(schedule.get(member)));
        }
    }
    return result;
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member)

Example 42 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<String, ScheduledTaskFuture<?>> scheduleAtFixedRate(Collection<String> memberUUIDs, Runnable runnable, long delay, long period, TimeUnit unit) {
    HashMap<String, 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<?>> schedule = scheduledExecutorService.scheduleOnMembersAtFixedRate(runnable, toSubmitTo, delay, period, unit);
        for (Member member : schedule.keySet()) {
            result.put(member.getUuid(), new ScheduledTaskFuture<>(schedule.get(member)));
        }
    }
    return result;
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member)

Example 43 with IScheduledExecutorService

use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.

the class AdvancedNetworkClientIntegrationTest method testGetScheduledFutures.

@Test
public void testGetScheduledFutures() throws Exception {
    client = HazelcastClient.newHazelcastClient(getClientConfig());
    IScheduledExecutorService executorService = client.getScheduledExecutorService("test");
    Member targetMember = client.getCluster().getMembers().iterator().next();
    IScheduledFuture<Address> future = executorService.scheduleOnMember(new ReportExecutionMember(), targetMember, 3, TimeUnit.SECONDS);
    Map<Member, List<IScheduledFuture<Address>>> futures = executorService.getAllScheduledFutures();
    assertContains(futures.keySet(), targetMember);
    IScheduledFuture<Address> futureOfMember = futures.get(targetMember).get(0);
    assertEquals(futureOfMember.get(), future.get());
}
Also used : IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) Address(com.hazelcast.cluster.Address) List(java.util.List) Member(com.hazelcast.cluster.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 44 with IScheduledExecutorService

use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.

the class AdvancedNetworkClientIntegrationTest method testScheduleOnMember.

@Test
public void testScheduleOnMember() throws Exception {
    client = HazelcastClient.newHazelcastClient(getClientConfig());
    IScheduledExecutorService executorService = client.getScheduledExecutorService("test");
    Member targetMember = client.getCluster().getMembers().iterator().next();
    IScheduledFuture<Address> future = executorService.scheduleOnMember(new ReportExecutionMember(), targetMember, 3, TimeUnit.SECONDS);
    assertEquals(targetMember.getUuid(), future.getHandler().getUuid());
    Address clusterMemberAddress = null;
    for (HazelcastInstance instance : instances) {
        if (targetMember.getAddress().equals(instance.getCluster().getLocalMember().getAddressMap().get(CLIENT))) {
            clusterMemberAddress = instance.getCluster().getLocalMember().getAddress();
        }
    }
    assertEquals(future.get(), clusterMemberAddress);
}
Also used : IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) Member(com.hazelcast.cluster.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 45 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 memberUUID The member to schedule the task on
 * @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<?> scheduleAtFixedRate(String memberUUID, Runnable runnable, long delay, long period, TimeUnit unit) {
    ScheduledTaskFuture result = null;
    if (hzCore.isEnabled()) {
        Member toSubmitTo = selectMember(memberUUID);
        IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME);
        IScheduledFuture<?> schedule = scheduledExecutorService.scheduleOnMemberAtFixedRate(runnable, toSubmitTo, delay, period, unit);
        result = new ScheduledTaskFuture(schedule);
    }
    return result;
}
Also used : IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) 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