Search in sources :

Example 21 with SerializationService

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

the class WanPublisherConfigTest method testSerialization.

@Test
public void testSerialization() {
    Map<String, Comparable> properties = new HashMap<String, Comparable>();
    properties.put("key", "value");
    config.setGroupName("groupName");
    config.setQueueCapacity(500);
    config.setQueueFullBehavior(WANQueueFullBehavior.THROW_EXCEPTION);
    config.setProperties(properties);
    config.setClassName("className");
    config.setImplementation("implementation");
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(config);
    WanPublisherConfig deserialized = serializationService.toObject(serialized);
    assertWanPublisherConfig(config, deserialized);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HashMap(java.util.HashMap) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with SerializationService

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

the class WanReplicationConfigTest method testSerialization.

@Test
public void testSerialization() {
    Map<String, Comparable> properties = new HashMap<String, Comparable>();
    properties.put("key", "value");
    WanConsumerConfig wanConsumerConfig = new WanConsumerConfig();
    wanConsumerConfig.setProperties(properties);
    wanConsumerConfig.setClassName("className");
    wanConsumerConfig.setImplementation("implementation");
    WanPublisherConfig wanPublisherConfig1 = new WanPublisherConfig();
    WanPublisherConfig wanPublisherConfig2 = new WanPublisherConfig();
    List<WanPublisherConfig> publisherConfigs = new LinkedList<WanPublisherConfig>();
    publisherConfigs.add(wanPublisherConfig1);
    config.setName("name");
    config.setWanConsumerConfig(wanConsumerConfig);
    config.setWanPublisherConfigs(publisherConfigs);
    config.addWanPublisherConfig(wanPublisherConfig2);
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(config);
    WanReplicationConfig deserialized = serializationService.toObject(serialized);
    assertWanReplicationConfig(config, deserialized);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HashMap(java.util.HashMap) WanConsumerConfigTest.assertWanConsumerConfig(com.hazelcast.config.WanConsumerConfigTest.assertWanConsumerConfig) SerializationService(com.hazelcast.spi.serialization.SerializationService) WanPublisherConfigTest.assertWanPublisherConfig(com.hazelcast.config.WanPublisherConfigTest.assertWanPublisherConfig) Data(com.hazelcast.nio.serialization.Data) LinkedList(java.util.LinkedList) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with SerializationService

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

the class DefaultMapProjectMessageTask method reduce.

@Override
protected List<Data> reduce(Collection<QueryResult> results) {
    if (results.isEmpty()) {
        return Collections.emptyList();
    }
    QueryResult combinedResult = null;
    for (QueryResult result : results) {
        if (combinedResult == null) {
            combinedResult = result;
        } else {
            combinedResult.combine(result);
        }
    }
    Set result = QueryResultUtils.transformToSet(nodeEngine.getSerializationService(), combinedResult, getPredicate(), IterationType.VALUE, false);
    List<Data> serialized = new ArrayList<Data>(result.size());
    SerializationService serializationService = nodeEngine.getSerializationService();
    for (Object row : result) {
        serialized.add(serializationService.toData(row));
    }
    return serialized;
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) Set(java.util.Set) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data)

Example 24 with SerializationService

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

the class AbstractCollectionProxyImpl method getAll.

private Collection<E> getAll() {
    CollectionGetAllOperation operation = new CollectionGetAllOperation(name);
    SerializableList result = invoke(operation);
    List<Data> collection = result.getCollection();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    return new UnmodifiableLazyList<E>(collection, serializationService);
}
Also used : CollectionGetAllOperation(com.hazelcast.collection.impl.collection.operations.CollectionGetAllOperation) SerializableList(com.hazelcast.spi.impl.SerializableList) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList)

Example 25 with SerializationService

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

the class AbstractClientCacheProxy method getInternal.

protected Object getInternal(final K key, ExpiryPolicy expiryPolicy, boolean async) {
    final long start = System.nanoTime();
    ensureOpen();
    validateNotNull(key);
    final Data keyData = toData(key);
    Object cached = getCachedValue(keyData, !async);
    if (cached != NOT_CACHED) {
        return asCompletedFutureOrValue(cached, async);
    }
    final long reservationId = tryReserveForUpdate(keyData);
    final Data expiryPolicyData = toData(expiryPolicy);
    ClientMessage request = CacheGetCodec.encodeRequest(nameWithPrefix, keyData, expiryPolicyData);
    ClientInvocationFuture future;
    try {
        final int partitionId = clientContext.getPartitionService().getPartitionId(keyData);
        final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
        final ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
        future = clientInvocation.invoke();
    } catch (Throwable t) {
        invalidateNearCache(keyData);
        throw rethrow(t);
    }
    SerializationService serializationService = clientContext.getSerializationService();
    ClientDelegatingFuture<V> delegatingFuture = new ClientDelegatingFuture<V>(future, serializationService, cacheGetResponseDecoder);
    if (async) {
        if (nearCache != null) {
            delegatingFuture.andThenInternal(new ExecutionCallback<Data>() {

                public void onResponse(Data valueData) {
                    storeInNearCache(keyData, valueData, null, reservationId, false);
                    if (statisticsEnabled) {
                        handleStatisticsOnGet(start, valueData);
                    }
                }

                public void onFailure(Throwable t) {
                    invalidateNearCache(keyData);
                }
            }, false);
        }
        return delegatingFuture;
    } else {
        try {
            V value = toObject(delegatingFuture.get());
            if (nearCache != null) {
                storeInNearCache(keyData, (Data) delegatingFuture.getResponse(), value, reservationId, false);
            }
            if (statisticsEnabled) {
                handleStatisticsOnGet(start, value);
            }
            return value;
        } catch (Throwable e) {
            invalidateNearCache(keyData);
            throw rethrowAllowedTypeFirst(e, CacheException.class);
        }
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) CacheException(javax.cache.CacheException) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl)

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