Search in sources :

Example 26 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.

the class AbstractClientCacheProxy method groupDataToPartitions.

private List<Map.Entry<Data, Data>>[] groupDataToPartitions(Map<? extends K, ? extends V> map, ClientPartitionService partitionService, int partitionCount) {
    List<Map.Entry<Data, Data>>[] entriesPerPartition = new List[partitionCount];
    SerializationService serializationService = clientContext.getSerializationService();
    for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
        K key = entry.getKey();
        V value = entry.getValue();
        validateNotNull(key, value);
        Data keyData = serializationService.toData(key);
        Data valueData = serializationService.toData(value);
        int partitionId = partitionService.getPartitionId(keyData);
        List<Map.Entry<Data, Data>> entries = entriesPerPartition[partitionId];
        if (entries == null) {
            entries = new ArrayList<Map.Entry<Data, Data>>();
            entriesPerPartition[partitionId] = entries;
        }
        entries.add(new AbstractMap.SimpleImmutableEntry<Data, Data>(keyData, valueData));
    }
    return entriesPerPartition;
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) AbstractMap(java.util.AbstractMap) ArrayList(java.util.ArrayList) List(java.util.List) MapUtil.createHashMap(com.hazelcast.util.MapUtil.createHashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) AbstractMap(java.util.AbstractMap)

Example 27 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.

the class AbstractClientCacheProxyBase method submitLoadAllTask.

protected void submitLoadAllTask(ClientMessage request, CompletionListener completionListener, final Set<Data> keys) {
    final CompletionListener compListener = completionListener != null ? completionListener : NULL_COMPLETION_LISTENER;
    ClientDelegatingFuture<V> delegatingFuture = null;
    try {
        injectDependencies(completionListener);
        final long start = System.nanoTime();
        ClientInvocationFuture future = new ClientInvocation((HazelcastClientInstanceImpl) clientContext.getHazelcastInstance(), request).invoke();
        SerializationService serializationService = clientContext.getSerializationService();
        delegatingFuture = new ClientDelegatingFuture<V>(future, serializationService, LOAD_ALL_DECODER);
        final Future delFuture = delegatingFuture;
        loadAllCalls.put(delegatingFuture, compListener);
        delegatingFuture.andThen(new ExecutionCallback<V>() {

            @Override
            public void onResponse(V response) {
                loadAllCalls.remove(delFuture);
                onLoadAll(keys, response, start, System.nanoTime());
                compListener.onCompletion();
            }

            @Override
            public void onFailure(Throwable t) {
                loadAllCalls.remove(delFuture);
                handleFailureOnCompletionListener(compListener, t);
            }
        });
    } catch (Throwable t) {
        if (delegatingFuture != null) {
            loadAllCalls.remove(delegatingFuture);
        }
        handleFailureOnCompletionListener(compListener, t);
    }
}
Also used : CompletionListener(javax.cache.integration.CompletionListener) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) SerializationService(com.hazelcast.spi.serialization.SerializationService) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) Future(java.util.concurrent.Future) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 28 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.

the class QueueService method createLocalQueueStats.

/**
     * Returns the local queue statistics for the queue with the given {@code name}. If this node is the owner of the queue,
     * returned stats contain {@link LocalQueueStats#getOwnedItemCount()}, otherwise it contains
     * {@link LocalQueueStats#getBackupItemCount()}.
     *
     * @param name the name of the queue for which the statistics are returned
     * @return the statistics
     */
public LocalQueueStats createLocalQueueStats(String name) {
    SerializationService serializationService = nodeEngine.getSerializationService();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    Data keyData = serializationService.toData(name, StringPartitioningStrategy.INSTANCE);
    int partitionId = partitionService.getPartitionId(keyData);
    return createLocalQueueStats(name, partitionId);
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 29 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.

the class ClientMapProxy method getAsyncInternal.

protected ICompletableFuture<V> getAsyncInternal(Data keyData) {
    SerializationService serializationService = getContext().getSerializationService();
    ClientMessage request = MapGetCodec.encodeRequest(name, keyData, getThreadId());
    try {
        ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
        return new ClientDelegatingFuture<V>(future, serializationService, GET_ASYNC_RESPONSE_DECODER);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastException(com.hazelcast.core.HazelcastException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 30 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.

the class XAResourceProxy method finalizeTransactionRemotely.

private void finalizeTransactionRemotely(Xid xid, boolean isCommit) {
    SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
    SerializationService serializationService = getContext().getSerializationService();
    Data xidData = serializationService.toData(serializableXID);
    ClientMessage request = XATransactionFinalizeCodec.encodeRequest(serializableXID, isCommit);
    invoke(request, xidData);
}
Also used : SerializableXID(com.hazelcast.transaction.impl.xa.SerializableXID) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Aggregations

SerializationService (com.hazelcast.spi.serialization.SerializationService)120 Test (org.junit.Test)59 QuickTest (com.hazelcast.test.annotation.QuickTest)56 Data (com.hazelcast.nio.serialization.Data)54 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)46 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)28 ParallelTest (com.hazelcast.test.annotation.ParallelTest)22 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)18 HeapData (com.hazelcast.internal.serialization.impl.HeapData)17 Map (java.util.Map)15 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)9 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)8 Node (com.hazelcast.instance.Node)7 SerializationConfig (com.hazelcast.config.SerializationConfig)6 ICacheService (com.hazelcast.cache.impl.ICacheService)5 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)5 Record (com.hazelcast.map.impl.record.Record)5 ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)3