use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.
the class ClientScheduledExecutorProxy method scheduleOnMember.
private <V> IScheduledFuture<V> scheduleOnMember(String name, Member member, TaskDefinition definition) {
TimeUnit unit = definition.getUnit();
Data commandData = getSerializationService().toData(definition.getCommand());
ClientMessage request = ScheduledExecutorSubmitToAddressCodec.encodeRequest(getName(), member.getAddress(), definition.getType().getId(), definition.getName(), commandData, unit.toMillis(definition.getInitialDelay()), unit.toMillis(definition.getPeriod()));
try {
new ClientInvocation(getClient(), request, member.getAddress()).invoke().get();
} catch (Exception e) {
throw rethrow(e);
}
return createFutureProxy(member.getAddress(), name);
}
use of com.hazelcast.client.impl.protocol.ClientMessage 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.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.
the class ClientScheduledFutureProxy method getStats.
@Override
public ScheduledTaskStatistics getStats() {
checkAccessibleHandler();
Address address = handler.getAddress();
String schedulerName = handler.getSchedulerName();
String taskName = handler.getTaskName();
int partitionId = handler.getPartitionId();
try {
if (address != null) {
ClientMessage request = ScheduledExecutorGetStatsFromAddressCodec.encodeRequest(schedulerName, taskName, address);
ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
ScheduledExecutorGetStatsFromAddressCodec.ResponseParameters responseParameters = ScheduledExecutorGetStatsFromAddressCodec.decodeResponse(response);
return new ScheduledTaskStatisticsImpl(responseParameters.totalRuns, responseParameters.lastIdleTimeNanos, responseParameters.totalRunTimeNanos, responseParameters.totalIdleTimeNanos);
} else {
ClientMessage request = ScheduledExecutorGetStatsFromPartitionCodec.encodeRequest(schedulerName, taskName);
ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
ScheduledExecutorGetStatsFromAddressCodec.ResponseParameters responseParameters = ScheduledExecutorGetStatsFromAddressCodec.decodeResponse(response);
return new ScheduledTaskStatisticsImpl(responseParameters.totalRuns, responseParameters.lastIdleTimeNanos, responseParameters.totalRunTimeNanos, responseParameters.totalIdleTimeNanos);
}
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.
the class ClientScheduledFutureProxy method cancel.
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
if (mayInterruptIfRunning) {
// inside the TaskRunner but it adds extra complexity.
throw new UnsupportedOperationException("mayInterruptIfRunning flag is not supported.");
}
checkAccessibleHandler();
Address address = handler.getAddress();
String schedulerName = handler.getSchedulerName();
String taskName = handler.getTaskName();
int partitionId = handler.getPartitionId();
try {
if (address != null) {
ClientMessage request = ScheduledExecutorCancelFromAddressCodec.encodeRequest(schedulerName, taskName, address, false);
ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
return ScheduledExecutorCancelFromAddressCodec.decodeResponse(response).response;
} else {
ClientMessage request = ScheduledExecutorCancelFromPartitionCodec.encodeRequest(schedulerName, taskName, false);
ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
return ScheduledExecutorCancelFromPartitionCodec.decodeResponse(response).response;
}
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.
the class ClientScheduledFutureProxy method isCancelled.
@Override
public boolean isCancelled() {
checkAccessibleHandler();
Address address = handler.getAddress();
String schedulerName = handler.getSchedulerName();
String taskName = handler.getTaskName();
int partitionId = handler.getPartitionId();
try {
if (address != null) {
ClientMessage request = ScheduledExecutorIsCancelledFromAddressCodec.encodeRequest(schedulerName, taskName, address);
ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
return ScheduledExecutorIsCancelledFromAddressCodec.decodeResponse(response).response;
} else {
ClientMessage request = ScheduledExecutorIsCancelledFromPartitionCodec.encodeRequest(schedulerName, taskName);
ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
return ScheduledExecutorIsCancelledFromPartitionCodec.decodeResponse(response).response;
}
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
Aggregations