コード例 #1
0
  private void clearRecordsMap(Map<Data, Record> excludeRecords) {
    InMemoryFormat inMemoryFormat = recordFactory.getStorageFormat();
    switch (inMemoryFormat) {
      case BINARY:
      case OBJECT:
        records.clear();
        if (excludeRecords != null && !excludeRecords.isEmpty()) {
          records.putAll(excludeRecords);
        }
        return;

      case OFFHEAP:
        Iterator<Record> iter = records.values().iterator();
        while (iter.hasNext()) {
          Record record = iter.next();
          if (excludeRecords == null || !excludeRecords.containsKey(record.getKey())) {
            record.invalidate();
            iter.remove();
          }
        }
        return;

      default:
        throw new IllegalArgumentException("Unknown storage format: " + inMemoryFormat);
    }
  }
コード例 #2
0
 public boolean merge(Data dataKey, EntryView mergingEntry, MapMergePolicy mergePolicy) {
   checkIfLoaded();
   Record record = records.get(dataKey);
   Object newValue = null;
   if (record == null) {
     newValue = mergingEntry.getValue();
     newValue = writeMapStore(dataKey, newValue, null);
     record = mapService.createRecord(name, dataKey, newValue, DEFAULT_TTL);
     records.put(dataKey, record);
     updateSizeEstimator(calculateRecordSize(record));
   } else {
     Object oldValue = record.getValue();
     EntryView existingEntry =
         mapService.createSimpleEntryView(
             mapService.toObject(record.getKey()), mapService.toObject(record.getValue()), record);
     newValue = mergePolicy.merge(name, mergingEntry, existingEntry);
     if (newValue == null) { // existing entry will be removed
       removeIndex(dataKey);
       mapStoreDelete(record, dataKey);
       // reduce size.
       updateSizeEstimator(-calculateRecordSize(record));
       // remove from map & invalidate.
       deleteRecord(dataKey);
       return true;
     }
     // same with the existing entry so no need to mapstore etc operations.
     if (mapService.compare(name, newValue, oldValue)) {
       return true;
     }
     newValue = writeMapStore(dataKey, newValue, record);
     updateSizeEstimator(-calculateRecordSize(record));
     recordFactory.setValue(record, newValue);
     updateSizeEstimator(calculateRecordSize(record));
   }
   saveIndex(record);
   return newValue != null;
 }
コード例 #3
0
 private void setRecordValue(Record record, Object value) {
   accessRecord(record);
   record.onUpdate();
   recordFactory.setValue(record, value);
 }