Search in sources :

Example 6 with ClientInvocation

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ICompletableFuture(com.hazelcast.core.ICompletableFuture) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) ArrayList(java.util.ArrayList) List(java.util.List) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Collections.emptyMap(java.util.Collections.emptyMap) AbstractMap(java.util.AbstractMap) IMap(com.hazelcast.core.IMap) HazelcastException(com.hazelcast.core.HazelcastException)

Example 7 with ClientInvocation

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;
}
Also used : ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastException(com.hazelcast.core.HazelcastException) MapGetAllCodec(com.hazelcast.client.impl.protocol.codec.MapGetAllCodec) Future(java.util.concurrent.Future) ICompletableFuture(com.hazelcast.core.ICompletableFuture) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Collections.emptyMap(java.util.Collections.emptyMap) AbstractMap(java.util.AbstractMap) IMap(com.hazelcast.core.IMap)

Example 8 with ClientInvocation

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;
}
Also used : Address(com.hazelcast.nio.Address) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 9 with ClientInvocation

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);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 10 with ClientInvocation

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Member(com.hazelcast.core.Member) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)52 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)47 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)25 Address (com.hazelcast.nio.Address)13 ExecutionException (java.util.concurrent.ExecutionException)13 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)10 Data (com.hazelcast.nio.serialization.Data)10 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)9 TimeoutException (java.util.concurrent.TimeoutException)9 StaleTaskException (com.hazelcast.scheduledexecutor.StaleTaskException)6 ArrayList (java.util.ArrayList)6 Future (java.util.concurrent.Future)6 Member (com.hazelcast.core.Member)5 SerializationService (com.hazelcast.spi.serialization.SerializationService)5 IOException (java.io.IOException)5 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)4 HazelcastException (com.hazelcast.core.HazelcastException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 CacheException (javax.cache.CacheException)4