Search in sources :

Example 6 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientCacheProxy method loadAll.

@Override
public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) {
    ensureOpen();
    validateNotNull(keys);
    for (K key : keys) {
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key);
    }
    HashSet<Data> keysData = new HashSet<Data>();
    for (K key : keys) {
        keysData.add(toData(key));
    }
    ClientMessage request = CacheLoadAllCodec.encodeRequest(nameWithPrefix, keysData, replaceExistingValues);
    try {
        submitLoadAllTask(request, completionListener, keysData);
    } catch (Exception e) {
        if (completionListener != null) {
            completionListener.onException(e);
        }
        throw new CacheException(e);
    }
}
Also used : CacheException(javax.cache.CacheException) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) HashSet(java.util.HashSet)

Example 7 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientCacheProxy method containsKey.

@Override
public boolean containsKey(K key) {
    ensureOpen();
    validateNotNull(key);
    final Data keyData = toData(key);
    Object cached = getCachedValue(keyData, false);
    if (cached != NOT_CACHED) {
        return true;
    }
    ClientMessage request = CacheContainsKeyCodec.encodeRequest(nameWithPrefix, keyData);
    ClientMessage result = invoke(request, keyData);
    return CacheContainsKeyCodec.decodeResponse(result).response;
}
Also used : Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 8 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientCacheProxy method invoke.

@Override
public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... arguments) throws EntryProcessorException {
    ensureOpen();
    validateNotNull(key);
    if (entryProcessor == null) {
        throw new NullPointerException("Entry Processor is null");
    }
    final Data keyData = toData(key);
    Data epData = toData(entryProcessor);
    List<Data> argumentsData = null;
    if (arguments != null) {
        argumentsData = new ArrayList<Data>(arguments.length);
        for (int i = 0; i < arguments.length; i++) {
            argumentsData.add(toData(arguments[i]));
        }
    }
    final int completionId = nextCompletionId();
    ClientMessage request = CacheEntryProcessorCodec.encodeRequest(nameWithPrefix, keyData, epData, argumentsData, completionId);
    try {
        final ICompletableFuture<ClientMessage> f = invoke(request, keyData, completionId);
        final ClientMessage response = getSafely(f);
        final Data data = CacheEntryProcessorCodec.decodeResponse(response).response;
        // At client side, we don't know what entry processor does so we ignore it from statistics perspective
        return toObject(data);
    } catch (CacheException ce) {
        throw ce;
    } catch (Exception e) {
        throw new EntryProcessorException(e);
    }
}
Also used : EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException)

Example 9 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientClusterWideIterator method fetch.

protected List fetch() {
    HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
    if (prefetchValues) {
        ClientMessage request = CacheIterateEntriesCodec.encodeRequest(cacheProxy.getPrefixedName(), partitionIndex, lastTableIndex, fetchSize);
        try {
            ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionIndex);
            ClientInvocationFuture f = clientInvocation.invoke();
            CacheIterateEntriesCodec.ResponseParameters responseParameters = CacheIterateEntriesCodec.decodeResponse(f.get());
            setLastTableIndex(responseParameters.entries, responseParameters.tableIndex);
            return responseParameters.entries;
        } catch (Exception e) {
            throw ExceptionUtil.rethrow(e);
        }
    } else {
        ClientMessage request = CacheIterateCodec.encodeRequest(cacheProxy.getPrefixedName(), partitionIndex, lastTableIndex, fetchSize);
        try {
            ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionIndex);
            ClientInvocationFuture f = clientInvocation.invoke();
            CacheIterateCodec.ResponseParameters responseParameters = CacheIterateCodec.decodeResponse(f.get());
            setLastTableIndex(responseParameters.keys, responseParameters.tableIndex);
            return responseParameters.keys;
        } catch (Exception e) {
            throw ExceptionUtil.rethrow(e);
        }
    }
}
Also used : CacheIterateCodec(com.hazelcast.client.impl.protocol.codec.CacheIterateCodec) CacheIterateEntriesCodec(com.hazelcast.client.impl.protocol.codec.CacheIterateEntriesCodec) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 10 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class AbstractClientInternalCacheProxy method putInternal.

protected Object putInternal(K key, V value, ExpiryPolicy expiryPolicy, boolean isGet, boolean withCompletionEvent, boolean async) {
    long start = System.nanoTime();
    ensureOpen();
    validateNotNull(key, value);
    CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, value);
    Data keyData = toData(key);
    Data valueData = toData(value);
    Data expiryPolicyData = toData(expiryPolicy);
    int completionId = withCompletionEvent ? nextCompletionId() : -1;
    ClientMessage request = CachePutCodec.encodeRequest(nameWithPrefix, keyData, valueData, expiryPolicyData, isGet, completionId);
    ClientInvocationFuture future;
    try {
        future = invoke(request, keyData, completionId);
    } catch (Exception e) {
        throw rethrow(e);
    }
    if (async) {
        return putInternalAsync(value, isGet, start, keyData, valueData, future);
    }
    return putInternalSync(value, isGet, start, keyData, valueData, future);
}
Also used : CacheEventData(com.hazelcast.cache.impl.CacheEventData) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) CacheException(javax.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Aggregations

ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)377 Data (com.hazelcast.nio.serialization.Data)140 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)47 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)37 SafeBuffer (com.hazelcast.client.impl.protocol.util.SafeBuffer)29 Address (com.hazelcast.nio.Address)25 QuickTest (com.hazelcast.test.annotation.QuickTest)24 Test (org.junit.Test)24 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)21 DataInputStream (java.io.DataInputStream)20 InputStream (java.io.InputStream)20 CacheEventData (com.hazelcast.cache.impl.CacheEventData)19 ParallelTest (com.hazelcast.test.annotation.ParallelTest)19 Member (com.hazelcast.core.Member)18 SerializationService (com.hazelcast.spi.serialization.SerializationService)18 ExecutionException (java.util.concurrent.ExecutionException)18 UnmodifiableLazyList (com.hazelcast.spi.impl.UnmodifiableLazyList)16 ArrayList (java.util.ArrayList)16 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)13 CacheException (javax.cache.CacheException)13