public boolean set(Data dataKey, Object value, long ttl) { checkIfLoaded(); Record record = records.get(dataKey); boolean newRecord = false; if (record == null) { value = mapService.interceptPut(name, null, value); value = writeMapStore(dataKey, value, null); record = mapService.createRecord(name, dataKey, value, ttl); records.put(dataKey, record); updateSizeEstimator(calculateRecordSize(record)); newRecord = true; } else { value = mapService.interceptPut(name, record.getValue(), value); value = writeMapStore(dataKey, value, record); // if key exists before, first reduce size updateSizeEstimator(-calculateRecordSize(record)); setRecordValue(record, value); // then increase size. updateSizeEstimator(calculateRecordSize(record)); updateTtl(record, ttl); } saveIndex(record); return newRecord; }
public Object put(Data dataKey, Object value, long ttl) { checkIfLoaded(); Record record = records.get(dataKey); Object oldValue = null; if (record == null) { if (mapContainer.getStore() != null) { oldValue = mapContainer.getStore().load(mapService.toObject(dataKey)); } value = mapService.interceptPut(name, null, value); value = writeMapStore(dataKey, value, null); record = mapService.createRecord(name, dataKey, value, ttl); records.put(dataKey, record); updateSizeEstimator(calculateRecordSize(record)); saveIndex(record); } else { oldValue = record.getValue(); value = mapService.interceptPut(name, oldValue, value); value = writeMapStore(dataKey, value, record); // if key exists before, first reduce size updateSizeEstimator(-calculateRecordSize(record)); setRecordValue(record, value); // then increase size. updateSizeEstimator(calculateRecordSize(record)); updateTtl(record, ttl); saveIndex(record); } return oldValue; }
public void put(Map.Entry<Data, Object> entry) { checkIfLoaded(); Data dataKey = entry.getKey(); Object value = entry.getValue(); Record record = records.get(dataKey); if (record == null) { value = mapService.interceptPut(name, null, value); value = writeMapStore(dataKey, value, null); record = mapService.createRecord(name, dataKey, value, DEFAULT_TTL); records.put(dataKey, record); // increase size. updateSizeEstimator(calculateRecordSize(record)); saveIndex(record); } else { final Object oldValue = record.getValue(); value = mapService.interceptPut(name, oldValue, value); value = writeMapStore(dataKey, value, record); // if key exists before, first reduce size updateSizeEstimator(-calculateRecordSize(record)); setRecordValue(record, value); // then increase size updateSizeEstimator(calculateRecordSize(record)); saveIndex(record); } }
public Object putIfAbsent(Data dataKey, Object value, long ttl) { checkIfLoaded(); Record record = records.get(dataKey); Object oldValue = null; if (record == null) { if (mapContainer.getStore() != null) { oldValue = mapContainer.getStore().load(mapService.toObject(dataKey)); if (oldValue != null) { record = mapService.createRecord(name, dataKey, oldValue, DEFAULT_TTL); records.put(dataKey, record); updateSizeEstimator(calculateRecordSize(record)); } } } else { accessRecord(record); oldValue = record.getValue(); } if (oldValue == null) { value = mapService.interceptPut(name, null, value); value = writeMapStore(dataKey, value, record); record = mapService.createRecord(name, dataKey, value, ttl); records.put(dataKey, record); updateSizeEstimator(calculateRecordSize(record)); updateTtl(record, ttl); } saveIndex(record); return oldValue; }
public void putFromLoad(Data dataKey, Object value, long ttl) { Record record = records.get(dataKey); if (record == null) { value = mapService.interceptPut(name, null, value); record = mapService.createRecord(name, dataKey, value, ttl); records.put(dataKey, record); updateSizeEstimator(calculateRecordSize(record)); } else { value = mapService.interceptPut(name, record.getValue(), value); updateSizeEstimator(-calculateRecordSize(record)); setRecordValue(record, value); updateSizeEstimator(calculateRecordSize(record)); updateTtl(record, ttl); } saveIndex(record); }
public boolean tryPut(Data dataKey, Object value, long ttl) { checkIfLoaded(); Record record = records.get(dataKey); if (record == null) { value = mapService.interceptPut(name, null, value); value = writeMapStore(dataKey, value, null); record = mapService.createRecord(name, dataKey, value, ttl); records.put(dataKey, record); updateSizeEstimator(calculateRecordSize(record)); } else { value = mapService.interceptPut(name, record.getValue(), value); value = writeMapStore(dataKey, value, record); updateSizeEstimator(-calculateRecordSize(record)); setRecordValue(record, value); updateSizeEstimator(calculateRecordSize(record)); updateTtl(record, ttl); } saveIndex(record); return true; }
public boolean replace(Data dataKey, Object testValue, Object newValue) { checkIfLoaded(); Record record = records.get(dataKey); if (record == null) return false; if (mapService.compare(name, record.getValue(), testValue)) { newValue = mapService.interceptPut(name, record.getValue(), newValue); newValue = writeMapStore(dataKey, newValue, record); updateSizeEstimator(-calculateRecordSize(record)); setRecordValue(record, newValue); updateSizeEstimator(calculateRecordSize(record)); } else { return false; } saveIndex(record); return true; }
public Object replace(Data dataKey, Object value) { checkIfLoaded(); Record record = records.get(dataKey); Object oldValue = null; if (record != null && record.getValue() != null) { oldValue = record.getValue(); value = mapService.interceptPut(name, oldValue, value); value = writeMapStore(dataKey, value, record); updateSizeEstimator(-calculateRecordSize(record)); setRecordValue(record, value); updateSizeEstimator(calculateRecordSize(record)); } else { return null; } saveIndex(record); return oldValue; }