Search in sources :

Example 81 with SerializationService

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

the class KeySetOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    Collection<ReplicatedRecordStore> stores = service.getAllReplicatedRecordStores(name);
    List keys = new ArrayList();
    for (ReplicatedRecordStore store : stores) {
        keys.addAll(store.keySet(false));
    }
    ArrayList<Data> dataKeys = new ArrayList<Data>(keys.size());
    SerializationService serializationService = getNodeEngine().getSerializationService();
    for (Object key : keys) {
        dataKeys.add(serializationService.toData(key));
    }
    response = new ReplicatedMapKeys(dataKeys);
}
Also used : ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ArrayList(java.util.ArrayList) ReplicatedMapKeys(com.hazelcast.replicatedmap.impl.client.ReplicatedMapKeys) SerializationService(com.hazelcast.spi.serialization.SerializationService) List(java.util.List) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data)

Example 82 with SerializationService

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

the class RequestMapDataOperation method getRecordSet.

private Set<RecordMigrationInfo> getRecordSet(ReplicatedRecordStore store) {
    Set<RecordMigrationInfo> recordSet = new HashSet<RecordMigrationInfo>(store.size());
    Iterator<ReplicatedRecord> iterator = store.recordIterator();
    while (iterator.hasNext()) {
        ReplicatedRecord record = iterator.next();
        SerializationService serializationService = getNodeEngine().getSerializationService();
        Data dataKey = serializationService.toData(record.getKeyInternal());
        Data dataValue = serializationService.toData(record.getValueInternal());
        recordSet.add(new RecordMigrationInfo(dataKey, dataValue, record.getTtlMillis()));
    }
    return recordSet;
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo) HashSet(java.util.HashSet)

Example 83 with SerializationService

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

the class ValuesOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    Collection<ReplicatedRecordStore> stores = service.getAllReplicatedRecordStores(name);
    Collection<ReplicatedRecord> values = new ArrayList<ReplicatedRecord>();
    for (ReplicatedRecordStore store : stores) {
        values.addAll(store.values(false));
    }
    Collection<Data> dataValues = new ArrayList<Data>(values.size());
    SerializationService serializationService = getNodeEngine().getSerializationService();
    for (ReplicatedRecord value : values) {
        dataValues.add(serializationService.toData(value.getValue()));
    }
    response = new ReplicatedMapValueCollection(dataValues);
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ReplicatedMapValueCollection(com.hazelcast.replicatedmap.impl.client.ReplicatedMapValueCollection)

Example 84 with SerializationService

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

the class EntrySetOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    Collection<ReplicatedRecordStore> stores = service.getAllReplicatedRecordStores(name);
    List<Map.Entry<Object, ReplicatedRecord>> entries = new ArrayList<Map.Entry<Object, ReplicatedRecord>>();
    for (ReplicatedRecordStore store : stores) {
        entries.addAll(store.entrySet(false));
    }
    ArrayList<Map.Entry<Data, Data>> dataEntries = new ArrayList<Map.Entry<Data, Data>>(entries.size());
    SerializationService serializationService = getNodeEngine().getSerializationService();
    for (Map.Entry<Object, ReplicatedRecord> entry : entries) {
        Data key = serializationService.toData(entry.getKey());
        Data value = serializationService.toData(entry.getValue().getValue());
        dataEntries.add(new AbstractMap.SimpleImmutableEntry<Data, Data>(key, value));
    }
    response = new ReplicatedMapEntries(dataEntries);
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) AbstractMap(java.util.AbstractMap) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) AbstractMap(java.util.AbstractMap) Map(java.util.Map) ReplicatedMapEntries(com.hazelcast.replicatedmap.impl.client.ReplicatedMapEntries)

Example 85 with SerializationService

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

the class NearCacheConfigTest method testSerialization.

@Test
public void testSerialization() {
    config.setInvalidateOnChange(true);
    config.setCacheLocalEntries(true);
    config.setName("foobar");
    config.setInMemoryFormat(InMemoryFormat.NATIVE);
    config.setTimeToLiveSeconds(23);
    config.setMaxIdleSeconds(42);
    config.setLocalUpdatePolicy(NearCacheConfig.LocalUpdatePolicy.CACHE_ON_UPDATE);
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(config);
    NearCacheConfig deserialized = serializationService.toObject(serialized);
    assertEquals(config.isInvalidateOnChange(), deserialized.isInvalidateOnChange());
    assertEquals(config.isCacheLocalEntries(), deserialized.isCacheLocalEntries());
    assertEquals(config.getName(), deserialized.getName());
    assertEquals(config.getInMemoryFormat(), deserialized.getInMemoryFormat());
    assertEquals(config.getTimeToLiveSeconds(), deserialized.getTimeToLiveSeconds());
    assertEquals(config.getMaxIdleSeconds(), deserialized.getMaxIdleSeconds());
    assertEquals(config.getLocalUpdatePolicy(), deserialized.getLocalUpdatePolicy());
    assertEquals(config.getEvictionPolicy(), deserialized.getEvictionPolicy());
    assertEquals(config.getMaxSize(), deserialized.getMaxSize());
    assertEquals(config.toString(), deserialized.toString());
}
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