Search in sources :

Example 71 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)

Example 72 with ClientMessage

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

the class AbstractClientInternalCacheProxy method getAndRemoveAsyncInternal.

protected <T> ICompletableFuture<T> getAndRemoveAsyncInternal(K key, boolean withCompletionEvent, boolean async) {
    final long start = System.nanoTime();
    ensureOpen();
    validateNotNull(key);
    CacheProxyUtil.validateConfiguredTypes(cacheConfig, key);
    final Data keyData = toData(key);
    final int completionId = withCompletionEvent ? nextCompletionId() : -1;
    ClientMessage request = CacheGetAndRemoveCodec.encodeRequest(nameWithPrefix, keyData, completionId);
    ClientInvocationFuture future;
    try {
        future = invoke(request, keyData, completionId);
        invalidateNearCache(keyData);
    } catch (Exception e) {
        throw rethrow(e);
    }
    ClientDelegatingFuture<T> delegatingFuture = new ClientDelegatingFuture<T>(future, clientContext.getSerializationService(), GET_AND_REMOVE_RESPONSE_DECODER);
    if (async && statisticsEnabled) {
        delegatingFuture.andThenInternal(new ExecutionCallback<T>() {

            public void onResponse(T response) {
                handleStatisticsOnRemove(true, start, response);
            }

            public void onFailure(Throwable t) {
            }
        }, true);
    }
    return delegatingFuture;
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) 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)

Example 73 with ClientMessage

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

the class AbstractClientInternalCacheProxy method putIfAbsentInternal.

protected Object putIfAbsentInternal(K key, V value, ExpiryPolicy expiryPolicy, 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 = CachePutIfAbsentCodec.encodeRequest(nameWithPrefix, keyData, valueData, expiryPolicyData, completionId);
    ClientInvocationFuture future;
    try {
        future = invoke(request, keyData, completionId);
    } catch (Throwable t) {
        throw rethrow(t);
    }
    ClientDelegatingFuture<Boolean> delegatingFuture = new ClientDelegatingFuture<Boolean>(future, clientContext.getSerializationService(), PUT_IF_ABSENT_RESPONSE_DECODER);
    if (async) {
        return putIfAbsentInternalAsync(value, start, keyData, valueData, delegatingFuture);
    }
    return putIfAbsentInternalSync(value, start, keyData, valueData, delegatingFuture);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) CacheEventData(com.hazelcast.cache.impl.CacheEventData) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 74 with ClientMessage

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

the class ClientQueueProxy method removeAll.

@Override
public boolean removeAll(Collection<?> c) {
    Preconditions.checkNotNull(c);
    Collection<Data> dataCollection = CollectionUtil.objectToDataCollection(c, getSerializationService());
    ClientMessage request = QueueCompareAndRemoveAllCodec.encodeRequest(name, dataCollection);
    ClientMessage response = invokeOnPartition(request);
    QueueCompareAndRemoveAllCodec.ResponseParameters resultParameters = QueueCompareAndRemoveAllCodec.decodeResponse(response);
    return resultParameters.response;
}
Also used : Data(com.hazelcast.nio.serialization.Data) QueueCompareAndRemoveAllCodec(com.hazelcast.client.impl.protocol.codec.QueueCompareAndRemoveAllCodec) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 75 with ClientMessage

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

the class ClientQueueProxy method put.

@Override
public void put(E e) throws InterruptedException {
    Data data = toData(e);
    ClientMessage request = QueuePutCodec.encodeRequest(name, data);
    invokeOnPartitionInterruptibly(request);
}
Also used : Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

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