use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientMapProxy method putAllInternal.
protected void putAllInternal(Map<Integer, List<Map.Entry<Data, Data>>> entryMap) throws RuntimeException {
List<Future<?>> futures = new ArrayList<Future<?>>(entryMap.size());
for (final Entry<Integer, List<Map.Entry<Data, Data>>> entry : entryMap.entrySet()) {
final Integer partitionId = entry.getKey();
// if there is only one entry, consider how we can use MapPutRequest
// without having to get back the return value
ClientMessage request = MapPutAllCodec.encodeRequest(name, entry.getValue());
futures.add(new ClientInvocation(getClient(), request, partitionId).invoke());
}
try {
for (Future<?> future : futures) {
future.get();
}
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientMapProxy method getAllInternal.
protected List<MapGetAllCodec.ResponseParameters> getAllInternal(Map<Integer, List<Data>> partitionToKeyData, Map<K, V> result) {
List<Future<ClientMessage>> futures = new ArrayList<Future<ClientMessage>>(partitionToKeyData.size());
List<MapGetAllCodec.ResponseParameters> responses = new ArrayList<MapGetAllCodec.ResponseParameters>(partitionToKeyData.size());
for (final Map.Entry<Integer, List<Data>> entry : partitionToKeyData.entrySet()) {
int partitionId = entry.getKey();
List<Data> keyList = entry.getValue();
if (!keyList.isEmpty()) {
ClientMessage request = MapGetAllCodec.encodeRequest(name, keyList);
futures.add(new ClientInvocation(getClient(), request, partitionId).invoke());
}
}
for (Future<ClientMessage> future : futures) {
try {
ClientMessage response = future.get();
MapGetAllCodec.ResponseParameters resultParameters = MapGetAllCodec.decodeResponse(response);
for (Entry<Data, Data> entry : resultParameters.response) {
final V value = toObject(entry.getValue());
final K key = toObject(entry.getKey());
result.put(key, value);
}
responses.add(resultParameters);
} catch (Exception e) {
throw rethrow(e);
}
}
return responses;
}
use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientMapReduceProxy method invoke.
private ClientMessage invoke(ClientMessage request, String jobId) throws Exception {
ClientTrackableJob trackableJob = trackableJobs.get(jobId);
if (trackableJob != null) {
ClientConnection sendConnection = trackableJob.clientInvocation.getSendConnectionOrWait();
Address runningMember = sendConnection.getEndPoint();
final ClientInvocation clientInvocation = new ClientInvocation(getClient(), request, runningMember);
ClientInvocationFuture future = clientInvocation.invoke();
return future.get();
}
return null;
}
use of com.hazelcast.client.spi.impl.ClientInvocation 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.spi.impl.ClientInvocation 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;
}
Aggregations