Search in sources :

Example 11 with SerializationService

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

the class PartitionWideEntryBackupOperation method run.

@Override
public void run() {
    long now = getNow();
    boolean shouldClone = mapContainer.shouldCloneOnEntryProcessing();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    Iterator<Record> iterator = recordStore.iterator(now, true);
    while (iterator.hasNext()) {
        Record record = iterator.next();
        Data dataKey = record.getKey();
        Object oldValue = record.getValue();
        Object value = shouldClone ? serializationService.toObject(serializationService.toData(oldValue)) : oldValue;
        if (!applyPredicate(dataKey, value)) {
            continue;
        }
        Map.Entry entry = createMapEntry(dataKey, value);
        processBackup(entry);
        if (noOp(entry, oldValue)) {
            continue;
        }
        if (entryRemovedBackup(entry, dataKey)) {
            continue;
        }
        entryAddedOrUpdatedBackup(entry, dataKey);
        evict(dataKey);
    }
    publishWanReplicationEventBackups();
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.nio.serialization.Data) Map(java.util.Map)

Example 12 with SerializationService

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

the class PartitionWideEntryOperation method run.

@Override
public void run() {
    long now = getNow();
    boolean shouldClone = mapContainer.shouldCloneOnEntryProcessing();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    responses = new MapEntries(recordStore.size());
    Iterator<Record> iterator = recordStore.iterator(now, false);
    while (iterator.hasNext()) {
        Record record = iterator.next();
        Data dataKey = record.getKey();
        Object oldValue = record.getValue();
        Object value = shouldClone ? serializationService.toObject(serializationService.toData(oldValue)) : oldValue;
        if (!applyPredicate(dataKey, value)) {
            continue;
        }
        Map.Entry entry = createMapEntry(dataKey, value);
        Data response = process(entry);
        if (response != null) {
            responses.add(dataKey, response);
        }
        // first call noOp, other if checks below depends on it.
        if (noOp(entry, oldValue, now)) {
            continue;
        }
        if (entryRemoved(entry, dataKey, oldValue, now)) {
            continue;
        }
        entryAddedOrUpdated(entry, dataKey, oldValue, now);
        evict(dataKey);
    }
}
Also used : MapEntries(com.hazelcast.map.impl.MapEntries) SerializationService(com.hazelcast.spi.serialization.SerializationService) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.nio.serialization.Data) Map(java.util.Map)

Example 13 with SerializationService

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

the class PartitionWideEntryOperation method innerBeforeRun.

@Override
public void innerBeforeRun() throws Exception {
    super.innerBeforeRun();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    ManagedContext managedContext = serializationService.getManagedContext();
    managedContext.initialize(entryProcessor);
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) ManagedContext(com.hazelcast.core.ManagedContext)

Example 14 with SerializationService

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

the class MultipleEntryOperation method run.

@Override
@SuppressWarnings("checkstyle:npathcomplexity")
public void run() throws Exception {
    long now = getNow();
    boolean shouldClone = mapContainer.shouldCloneOnEntryProcessing();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    responses = new MapEntries(keys.size());
    for (Data key : keys) {
        if (!isKeyProcessable(key)) {
            continue;
        }
        Object oldValue = recordStore.get(key, false);
        Object value = shouldClone ? serializationService.toObject(serializationService.toData(oldValue)) : oldValue;
        Map.Entry entry = createMapEntry(key, value);
        if (!isEntryProcessable(entry)) {
            continue;
        }
        Data response = process(entry);
        if (response != null) {
            responses.add(key, response);
        }
        // first call noOp, other if checks below depends on it.
        if (noOp(entry, oldValue, now)) {
            continue;
        }
        if (entryRemoved(entry, key, oldValue, now)) {
            continue;
        }
        entryAddedOrUpdated(entry, key, oldValue, now);
        evict(key);
    }
}
Also used : MapEntries(com.hazelcast.map.impl.MapEntries) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) Map(java.util.Map)

Example 15 with SerializationService

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

the class TransactionalMapProxy method values.

@Override
@SuppressWarnings("unchecked")
public Collection values(Predicate predicate) {
    checkTransactionState();
    checkNotNull(predicate, "Predicate can 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.ENTRY).build();
    QueryResult queryResylt = queryEngine.execute(query, Target.ALL_NODES);
    Set result = QueryResultUtils.transformToSet(serializationService, queryResylt, predicate, IterationType.ENTRY, true);
    // TODO: Can't we just use the original set?
    List<Object> valueSet = new ArrayList<Object>();
    Set<Object> keyWontBeIncluded = new HashSet<Object>();
    Extractors extractors = mapServiceContext.getExtractors(name);
    // iterate over the txMap and see if the values are updated or removed
    for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
        boolean isRemoved = Type.REMOVED.equals(entry.getValue().type);
        boolean isUpdated = Type.UPDATED.equals(entry.getValue().type);
        Object keyObject = serializationService.toObject(entry.getKey());
        if (isRemoved) {
            keyWontBeIncluded.add(keyObject);
        } else {
            if (isUpdated) {
                keyWontBeIncluded.add(keyObject);
            }
            Object entryValue = entry.getValue().value;
            QueryableEntry queryEntry = new CachedQueryEntry((InternalSerializationService) serializationService, entry.getKey(), entryValue, extractors);
            if (predicate.apply(queryEntry)) {
                valueSet.add(queryEntry.getValue());
            }
        }
    }
    removeFromResultSet(result, valueSet, keyWontBeIncluded);
    return valueSet;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Query(com.hazelcast.map.impl.query.Query) ArrayList(java.util.ArrayList) 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)

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