use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ClientScheduledExecutorProxy method getAllScheduledFutures.
@Override
public <V> Map<Member, List<IScheduledFuture<V>>> getAllScheduledFutures() {
ClientMessage request = ScheduledExecutorGetAllScheduledFuturesCodec.encodeRequest(getName());
final ClientInvocationFuture future = new ClientInvocation(getClient(), request).invoke();
ClientMessage response;
try {
response = future.get();
} catch (Exception e) {
throw rethrow(e);
}
Collection<Map.Entry<Member, List<ScheduledTaskHandler>>> urnsPerMember = ScheduledExecutorGetAllScheduledFuturesCodec.decodeResponse(response).handlers;
Map<Member, List<IScheduledFuture<V>>> tasksMap = new HashMap<Member, List<IScheduledFuture<V>>>();
for (Map.Entry<Member, List<ScheduledTaskHandler>> entry : urnsPerMember) {
List<IScheduledFuture<V>> memberTasks = new ArrayList<IScheduledFuture<V>>();
for (ScheduledTaskHandler scheduledTaskHandler : entry.getValue()) {
memberTasks.add(new ClientScheduledFutureProxy(scheduledTaskHandler, getContext()));
}
tasksMap.put(entry.getKey(), memberTasks);
}
return tasksMap;
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ClientScheduledExecutorProxy method scheduleOnMembers.
@Override
public <V> Map<Member, IScheduledFuture<V>> scheduleOnMembers(Callable<V> command, Collection<Member> members, long delay, TimeUnit unit) {
checkNotNull(command, "Command is null");
checkNotNull(members, "Members is null");
checkNotNull(unit, "Unit is null");
String name = extractNameOrGenerateOne(command);
Map<Member, IScheduledFuture<V>> futures = new HashMap<Member, IScheduledFuture<V>>();
for (Member member : members) {
TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.SINGLE_RUN, name, command, delay, unit);
futures.put(member, (IScheduledFuture<V>) scheduleOnMember(name, member, definition));
}
return futures;
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ClientScheduledExecutorProxy method getAllScheduledFutures.
@Nonnull
@Override
public <V> Map<Member, List<IScheduledFuture<V>>> getAllScheduledFutures() {
ClientMessage request = ScheduledExecutorGetAllScheduledFuturesCodec.encodeRequest(getName());
ClientInvocationFuture future = new ClientInvocation(getClient(), request, getName()).invoke();
ClientMessage response;
try {
response = future.get();
} catch (Exception e) {
throw rethrow(e);
}
Collection<ScheduledTaskHandler> urnsPerMember = ScheduledExecutorGetAllScheduledFuturesCodec.decodeResponse(response);
Map<Member, List<IScheduledFuture<V>>> tasksMap = new HashMap<>();
for (ScheduledTaskHandler scheduledTaskHandler : urnsPerMember) {
UUID memberUuid = scheduledTaskHandler.getUuid();
Member member = getContext().getClusterService().getMember(memberUuid);
tasksMap.compute(member, (BiFunctionEx<Member, List<IScheduledFuture<V>>, List<IScheduledFuture<V>>>) (m, iScheduledFutures) -> {
if (iScheduledFutures == null) {
iScheduledFutures = new LinkedList<>();
}
iScheduledFutures.add(new ClientScheduledFutureProxy(scheduledTaskHandler, getContext()));
return iScheduledFutures;
});
}
return tasksMap;
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method scheduleRandomPartitions_getAllScheduled_durable.
@Test
public void scheduleRandomPartitions_getAllScheduled_durable() throws Exception {
ScheduledExecutorConfig scheduledExecutorConfig = new ScheduledExecutorConfig().setName("s").setDurability(2);
Config config = new Config().setProperty("hazelcast.partition.count", "10").addScheduledExecutorConfig(scheduledExecutorConfig);
HazelcastInstance[] instances = createClusterWithCount(4, config);
IScheduledExecutorService s = getScheduledExecutor(instances, "s");
int expectedTotal = 11;
IScheduledFuture[] futures = new IScheduledFuture[expectedTotal];
for (int i = 0; i < expectedTotal; i++) {
futures[i] = s.schedule(new PlainCallableTask(i), 0, SECONDS);
}
instances[1].shutdown();
assertEquals(expectedTotal, countScheduledTasksOn(s), 0);
// verify all tasks
for (int i = 0; i < expectedTotal; i++) {
assertEquals(25.0 + i, futures[i].get());
}
}
use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method stats_longRunningTask_durable.
@Test
public void stats_longRunningTask_durable() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(4);
String key = generateKeyOwnedBy(instances[1]);
ICountDownLatch firstLatch = instances[0].getCPSubsystem().getCountDownLatch("firstLatch");
firstLatch.trySetCount(2);
ICountDownLatch lastLatch = instances[0].getCPSubsystem().getCountDownLatch("lastLatch");
lastLatch.trySetCount(6);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("firstLatch", "lastLatch"), key, 0, 10, SECONDS);
firstLatch.await(12, SECONDS);
instances[1].getLifecycleService().shutdown();
lastLatch.await(70, SECONDS);
// wait for run-cycle to finish before cancelling, in order for stats to get updated
sleepSeconds(4);
future.cancel(false);
ScheduledTaskStatistics stats = future.getStats();
assertEquals(6, stats.getTotalRuns(), 1);
}
Aggregations