Search in sources :

Example 71 with SerializationService

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

the class ListProxyImpl method subList.

@Override
public List<E> subList(int fromIndex, int toIndex) {
    ListSubOperation operation = new ListSubOperation(name, fromIndex, toIndex);
    SerializableList result = invoke(operation);
    List<Data> collection = result.getCollection();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    return new UnmodifiableLazyList<E>(collection, serializationService);
}
Also used : ListSubOperation(com.hazelcast.collection.impl.list.operations.ListSubOperation) 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 72 with SerializationService

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

the class TransactionalMapProxy method keySet.

@Override
@SuppressWarnings("unchecked")
public Set keySet(Predicate predicate) {
    checkTransactionState();
    checkNotNull(predicate, "Predicate should not be null!");
    checkNotInstanceOf(PagingPredicate.class, predicate, "Paging is not supported for Transactional queries!");
    MapQueryEngine queryEngine = mapServiceContext.getMapQueryEngine(name);
    SerializationService serializationService = getNodeEngine().getSerializationService();
    Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.KEY).build();
    QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
    Set result = QueryResultUtils.transformToSet(serializationService, queryResult, predicate, IterationType.KEY, true);
    // TODO: Can't we just use the original set?
    Set<Object> keySet = new HashSet<Object>(result);
    Extractors extractors = mapServiceContext.getExtractors(name);
    for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
        Data keyData = entry.getKey();
        if (!Type.REMOVED.equals(entry.getValue().type)) {
            Object value = (entry.getValue().value instanceof Data) ? toObjectIfNeeded(entry.getValue().value) : entry.getValue().value;
            QueryableEntry queryEntry = new CachedQueryEntry((InternalSerializationService) serializationService, keyData, value, extractors);
            // apply predicate on txMap
            if (predicate.apply(queryEntry)) {
                Object keyObject = serializationService.toObject(keyData);
                keySet.add(keyObject);
            }
        } else {
            // meanwhile remove keys which are not in txMap
            Object keyObject = serializationService.toObject(keyData);
            keySet.remove(keyObject);
        }
    }
    return keySet;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Query(com.hazelcast.map.impl.query.Query) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) QueryResult(com.hazelcast.map.impl.query.QueryResult) Extractors(com.hazelcast.query.impl.getters.Extractors) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) HashMap(java.util.HashMap) Map(java.util.Map) TransactionalMap(com.hazelcast.core.TransactionalMap) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) HashSet(java.util.HashSet)

Example 73 with SerializationService

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

the class ReadResultSetImpl method get.

@Override
public E get(int index) {
    checkNotNegative(index, "index should not be negative");
    checkTrue(index < size, "index should not be equal or larger than size");
    SerializationService serializationService = getSerializationService();
    Data item = items[index];
    return serializationService.toObject(item);
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data)

Example 74 with SerializationService

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

the class WanConsumerConfigTest method testSerialization.

@Test
public void testSerialization() {
    Map<String, Comparable> properties = new HashMap<String, Comparable>();
    properties.put("key", "value");
    config.setProperties(properties);
    config.setClassName("className");
    config.setImplementation("implementation");
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(config);
    WanConsumerConfig deserialized = serializationService.toObject(serialized);
    assertWanConsumerConfig(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 75 with SerializationService

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

the class WanReplicationConfigTest method testSerialization_withEmpyConfigs.

@Test
public void testSerialization_withEmpyConfigs() {
    config.setName("name");
    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) 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)

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