Search in sources :

Example 26 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class PutAllOperation method put.

private void put(Data dataKey, Data dataValue) {
    Object oldValue = putToRecordStore(dataKey, dataValue);
    dataValue = getValueOrPostProcessedValue(dataKey, dataValue);
    mapServiceContext.interceptAfterPut(name, dataValue);
    if (hasMapListener) {
        EntryEventType eventType = (oldValue == null ? ADDED : UPDATED);
        mapEventPublisher.publishEvent(getCallerAddress(), name, eventType, dataKey, oldValue, dataValue);
    }
    Record record = (hasWanReplication || hasBackups) ? recordStore.getRecord(dataKey) : null;
    if (hasWanReplication) {
        EntryView entryView = createSimpleEntryView(dataKey, dataValue, record);
        mapEventPublisher.publishWanReplicationUpdate(name, entryView);
    }
    if (hasBackups) {
        RecordInfo replicationInfo = buildRecordInfo(record);
        backupRecordInfos.add(replicationInfo);
    }
    evict(dataKey);
    if (hasInvalidation) {
        invalidationKeys.add(dataKey);
    }
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType) RecordInfo(com.hazelcast.map.impl.record.RecordInfo) Records.buildRecordInfo(com.hazelcast.map.impl.record.Records.buildRecordInfo) EntryView(com.hazelcast.core.EntryView) EntryViews.createSimpleEntryView(com.hazelcast.map.impl.EntryViews.createSimpleEntryView) Record(com.hazelcast.map.impl.record.Record)

Example 27 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class PutFromLoadAllBackupOperation method publishWanReplicationEvent.

private void publishWanReplicationEvent(Data key, Data value, Record record) {
    if (record == null) {
        return;
    }
    if (mapContainer.getWanReplicationPublisher() != null && mapContainer.getWanMergePolicy() != null) {
        EntryView entryView = EntryViews.createSimpleEntryView(key, value, record);
        mapEventPublisher.publishWanReplicationUpdateBackup(name, entryView);
    }
}
Also used : EntryView(com.hazelcast.core.EntryView)

Example 28 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class GetMapEntryRequest method writeResponse.

@Override
public void writeResponse(ManagementCenterService mcs, JsonObject root) throws Exception {
    IMap map = mcs.getHazelcastInstance().getMap(mapName);
    JsonObject result = new JsonObject();
    EntryView entry = null;
    if (type.equals("string")) {
        entry = map.getEntryView(key);
    } else if (type.equals("long")) {
        entry = map.getEntryView(Long.valueOf(key));
    } else if (type.equals("integer")) {
        entry = map.getEntryView(Integer.valueOf(key));
    }
    if (entry != null) {
        Object value = entry.getValue();
        result.add("browse_value", value != null ? value.toString() : "null");
        result.add("browse_class", value != null ? value.getClass().getName() : "null");
        result.add("memory_cost", Long.toString(entry.getCost()));
        result.add("date_creation_time", Long.toString(entry.getCreationTime()));
        result.add("date_expiration_time", Long.toString(entry.getExpirationTime()));
        result.add("browse_hits", Long.toString(entry.getHits()));
        result.add("date_access_time", Long.toString(entry.getLastAccessTime()));
        result.add("date_update_time", Long.toString(entry.getLastUpdateTime()));
        result.add("browse_version", Long.toString(entry.getVersion()));
    }
    root.add("result", result);
}
Also used : IMap(com.hazelcast.core.IMap) EntryView(com.hazelcast.core.EntryView) JsonObject(com.eclipsesource.json.JsonObject) JsonObject(com.eclipsesource.json.JsonObject)

Example 29 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class DefaultRecordStore method merge.

@Override
public boolean merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy) {
    checkIfLoaded();
    final long now = getNow();
    Record record = getRecordOrNull(key, now, false);
    mergingEntry = EntryViews.convertToLazyEntryView(mergingEntry, serializationService, mergePolicy);
    Object newValue;
    Object oldValue = null;
    if (record == null) {
        final Object notExistingKey = mapServiceContext.toObject(key);
        final EntryView nullEntryView = EntryViews.createNullEntryView(notExistingKey);
        newValue = mergePolicy.merge(name, mergingEntry, nullEntryView);
        if (newValue == null) {
            return false;
        }
        newValue = mapDataStore.add(key, newValue, now);
        record = createRecord(newValue, DEFAULT_TTL, now);
        mergeRecordExpiration(record, mergingEntry);
        storage.put(key, record);
    } else {
        oldValue = record.getValue();
        EntryView existingEntry = EntryViews.createLazyEntryView(record.getKey(), record.getValue(), record, serializationService, mergePolicy);
        newValue = mergePolicy.merge(name, mergingEntry, existingEntry);
        // existing entry will be removed
        if (newValue == null) {
            removeIndex(record);
            mapDataStore.remove(key, now);
            onStore(record);
            storage.removeRecord(record);
            updateStatsOnRemove(record.getHits());
            return true;
        }
        if (newValue == mergingEntry.getValue()) {
            mergeRecordExpiration(record, mergingEntry);
        }
        // same with the existing entry so no need to map-store etc operations.
        if (recordFactory.isEquals(newValue, oldValue)) {
            return true;
        }
        newValue = mapDataStore.add(key, newValue, now);
        onStore(record);
        storage.updateRecordValue(key, record, newValue);
    }
    saveIndex(record, oldValue);
    return newValue != null;
}
Also used : EntryView(com.hazelcast.core.EntryView) Record(com.hazelcast.map.impl.record.Record)

Example 30 with EntryView

use of com.hazelcast.core.EntryView in project hazelcast by hazelcast.

the class MapProxySupport method getEntryViewInternal.

protected EntryView getEntryViewInternal(Data key) {
    int partitionId = partitionService.getPartitionId(key);
    MapOperation operation = operationProvider.createGetEntryViewOperation(name, key);
    operation.setThreadId(ThreadUtil.getThreadId());
    operation.setServiceName(SERVICE_NAME);
    try {
        Future future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
        return (EntryView) toObject(future.get());
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : EntryView(com.hazelcast.core.EntryView) Future(java.util.concurrent.Future) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Aggregations

EntryView (com.hazelcast.core.EntryView)30 Test (org.junit.Test)14 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Record (com.hazelcast.map.impl.record.Record)10 Data (com.hazelcast.nio.serialization.Data)9 EntryViews.createSimpleEntryView (com.hazelcast.map.impl.EntryViews.createSimpleEntryView)6 IMap (com.hazelcast.core.IMap)2 MapContainer (com.hazelcast.map.impl.MapContainer)2 MapEventPublisher (com.hazelcast.map.impl.event.MapEventPublisher)2 MapOperation (com.hazelcast.map.impl.operation.MapOperation)2 Future (java.util.concurrent.Future)2 JsonObject (com.eclipsesource.json.JsonObject)1 EntryEventType (com.hazelcast.core.EntryEventType)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Node (com.hazelcast.instance.Node)1 MapOperationProvider (com.hazelcast.map.impl.operation.MapOperationProvider)1 MergeOperation (com.hazelcast.map.impl.operation.MergeOperation)1 RecordInfo (com.hazelcast.map.impl.record.RecordInfo)1 Records.buildRecordInfo (com.hazelcast.map.impl.record.Records.buildRecordInfo)1