Search in sources :

Example 11 with Data

use of com.hazelcast.nio.serialization.Data 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 12 with Data

use of com.hazelcast.nio.serialization.Data 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 13 with Data

use of com.hazelcast.nio.serialization.Data 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 14 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class QueueProxyImpl method remove.

@Override
public boolean remove(Object o) {
    final NodeEngine nodeEngine = getNodeEngine();
    final Data data = nodeEngine.toData(o);
    return removeInternal(data);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Data(com.hazelcast.nio.serialization.Data)

Example 15 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class QueueProxyImpl method drainTo.

@Override
public int drainTo(Collection<? super E> objects, int i) {
    checkNotNull(objects, "Collection is null");
    checkFalse(this.equals(objects), "Can not drain to same Queue");
    final NodeEngine nodeEngine = getNodeEngine();
    Collection<Data> dataList = drainInternal(i);
    for (Data data : dataList) {
        E e = nodeEngine.toObject(data);
        objects.add(e);
    }
    return dataList.size();
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Data(com.hazelcast.nio.serialization.Data)

Aggregations

Data (com.hazelcast.nio.serialization.Data)773 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)140 Test (org.junit.Test)121 QuickTest (com.hazelcast.test.annotation.QuickTest)118 ParallelTest (com.hazelcast.test.annotation.ParallelTest)108 ArrayList (java.util.ArrayList)81 Map (java.util.Map)64 SerializationService (com.hazelcast.spi.serialization.SerializationService)54 HashMap (java.util.HashMap)54 NodeEngine (com.hazelcast.spi.NodeEngine)50 HashSet (java.util.HashSet)39 Address (com.hazelcast.nio.Address)28 AbstractMap (java.util.AbstractMap)28 Record (com.hazelcast.map.impl.record.Record)27 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 HeapData (com.hazelcast.internal.serialization.impl.HeapData)26 List (java.util.List)20 Future (java.util.concurrent.Future)20 CacheEventData (com.hazelcast.cache.impl.CacheEventData)19 Operation (com.hazelcast.spi.Operation)18