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;
}
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;
}
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());
}
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);
}
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;
}
Aggregations