use of com.hazelcast.map.EntryLoader.MetadataAwareValue in project hazelcast by hazelcast.
the class EntryRecordStoreLoader method getLoadingSequence.
/**
* Transforms a map to a list of serialised key-value-expirationTime sequences.
*
* @param entries the map to be transformed
* @return the list of serialised alternating key-value pairs
*/
protected List<Data> getLoadingSequence(Map<?, ?> entries) {
List<Data> keyValueSequence = new ArrayList<>(entries.size() * 2);
for (Map.Entry<?, ?> entry : entries.entrySet()) {
Object key = entry.getKey();
MetadataAwareValue loaderEntry = (MetadataAwareValue) entry.getValue();
Object value = loaderEntry.getValue();
long expirationTime = loaderEntry.getExpirationTime();
Data dataKey = mapServiceContext.toData(key);
Data dataValue = mapServiceContext.toData(value);
Data dataExpirationTime = mapServiceContext.toData(expirationTime);
keyValueSequence.add(dataKey);
keyValueSequence.add(dataValue);
keyValueSequence.add(dataExpirationTime);
}
return keyValueSequence;
}
use of com.hazelcast.map.EntryLoader.MetadataAwareValue in project hazelcast by hazelcast.
the class DefaultRecordStore method loadValueOf.
/**
* Loads value of key. If necessary loads it by
* extracting from {@link MetadataAwareValue}
*
* @return loaded value from map-store,
* when no value found returns null
*/
private Object loadValueOf(Data key) {
Object value = mapDataStore.load(key);
if (value == null) {
return null;
}
if (mapDataStore.isWithExpirationTime()) {
MetadataAwareValue loaderEntry = (MetadataAwareValue) value;
long proposedTtl = expirationTimeToTtl(loaderEntry.getExpirationTime());
if (proposedTtl <= 0) {
return null;
}
value = loaderEntry.getValue();
}
return value;
}
use of com.hazelcast.map.EntryLoader.MetadataAwareValue in project hazelcast by hazelcast.
the class DefaultRecordStore method loadRecordOrNull.
@Override
public Record loadRecordOrNull(Data key, boolean backup, Address callerAddress) {
Object value = mapDataStore.load(key);
if (value == null) {
return null;
}
long ttl = UNSET;
if (mapDataStore.isWithExpirationTime()) {
MetadataAwareValue loaderEntry = (MetadataAwareValue) value;
long proposedTtl = expirationTimeToTtl(loaderEntry.getExpirationTime());
if (proposedTtl <= 0) {
return null;
}
value = loaderEntry.getValue();
ttl = proposedTtl;
}
long now = getNow();
Record record = putNewRecord(key, null, value, ttl, UNSET, UNSET, now, null, LOADED, false, backup);
if (!backup && mapEventPublisher.hasEventListener(name)) {
mapEventPublisher.publishEvent(callerAddress, name, EntryEventType.LOADED, key, null, record.getValue(), null);
}
evictEntries(key);
// otherwise query-caches cannot see loaded entries
if (!backup && hasQueryCache()) {
addEventToQueryCache(key, record);
}
return record;
}
use of com.hazelcast.map.EntryLoader.MetadataAwareValue in project hazelcast by hazelcast.
the class DefaultRecordStore method loadEntries.
private Map<Data, Object> loadEntries(Set<Data> keys, Address callerAddress) {
Map loadedEntries = mapDataStore.loadAll(keys);
if (isNullOrEmpty(loadedEntries)) {
return Collections.emptyMap();
}
// holds serialized keys and if values are
// serialized, also holds them in serialized format.
Map<Data, Object> resultMap = createHashMap(loadedEntries.size());
// add loaded key-value pairs to this record-store.
Set entrySet = loadedEntries.entrySet();
for (Object object : entrySet) {
Map.Entry entry = (Map.Entry) object;
Data key = toData(entry.getKey());
Object value = entry.getValue();
if (mapDataStore.isWithExpirationTime()) {
MetadataAwareValue loaderEntry = (MetadataAwareValue) value;
if (expirationTimeToTtl(loaderEntry.getExpirationTime()) > 0) {
resultMap.put(key, loaderEntry.getValue());
}
putFromLoad(key, loaderEntry.getValue(), loaderEntry.getExpirationTime(), callerAddress);
} else {
resultMap.put(key, value);
putFromLoad(key, value, callerAddress);
}
}
if (hasQueryCache()) {
for (Data key : resultMap.keySet()) {
Record record = storage.get(key);
// here we are only publishing events for loaded
// entries. This is required for notifying query-caches
// otherwise query-caches cannot see loaded entries
addEventToQueryCache(key, record);
}
}
return resultMap;
}
use of com.hazelcast.map.EntryLoader.MetadataAwareValue in project hazelcast by hazelcast.
the class WriteBehindStore method loadAll.
/**
* {@inheritDoc}
* The method first checks if some of the keys to be loaded
* have entries that are staged to be persisted to the
* underlying store and returns those values instead of loading
* the values from the store.
* The keys which don't have staged entries to be persisted will
* be loaded from the underlying store.
*
* @see MapLoader#loadAll(Collection)
*/
@Override
public Map loadAll(Collection keys) {
if (keys == null || keys.isEmpty()) {
return Collections.emptyMap();
}
Map<Object, Object> map = createHashMap(keys.size());
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
Data dataKey = toHeapData(key);
DelayedEntry delayedEntry = getFromStagingArea(dataKey);
if (delayedEntry != null) {
Object value = delayedEntry.getValue();
if (value != null) {
if (isWithExpirationTime()) {
map.put(dataKey, new MetadataAwareValue(toObject(value), delayedEntry.getExpirationTime()));
} else {
map.put(dataKey, toObject(value));
}
}
iterator.remove();
}
}
map.putAll(super.loadAll(keys));
return map;
}
Aggregations