예제 #1
0
 public MapEntrySet getAll(Set<Data> keySet) {
   checkIfLoaded();
   final MapEntrySet mapEntrySet = new MapEntrySet();
   Map<Object, Data> keyMapForLoader = null;
   if (mapContainer.getStore() != null) {
     keyMapForLoader = new HashMap<Object, Data>();
   }
   for (Data dataKey : keySet) {
     Record record = records.get(dataKey);
     if (record == null) {
       if (mapContainer.getStore() != null) {
         keyMapForLoader.put(mapService.toObject(dataKey), dataKey);
       }
     } else {
       accessRecord(record);
       Object value = record.getValue();
       value = mapService.interceptGet(name, value);
       if (value != null) {
         mapEntrySet.add(new AbstractMap.SimpleImmutableEntry(dataKey, mapService.toData(value)));
       }
     }
   }
   if (mapContainer.getStore() == null || keyMapForLoader.size() == 0) {
     return mapEntrySet;
   }
   final Map<Object, Object> loadedKeys =
       mapContainer.getStore().loadAll(keyMapForLoader.keySet());
   for (Map.Entry entry : loadedKeys.entrySet()) {
     final Object objectKey = entry.getKey();
     Object value = entry.getValue();
     Data dataKey = keyMapForLoader.get(objectKey);
     if (value != null) {
       Record record = mapService.createRecord(name, dataKey, value, DEFAULT_TTL);
       records.put(dataKey, record);
       saveIndex(record);
       updateSizeEstimator(calculateRecordSize(record));
     }
     value = mapService.interceptGet(name, value);
     if (value != null) {
       mapEntrySet.add(new AbstractMap.SimpleImmutableEntry(dataKey, mapService.toData(value)));
     }
   }
   return mapEntrySet;
 }
예제 #2
0
  public Object get(Data dataKey) {
    checkIfLoaded();
    Record record = records.get(dataKey);
    Object value = null;
    if (record == null) {
      if (mapContainer.getStore() != null) {
        value = mapContainer.getStore().load(mapService.toObject(dataKey));
        if (value != null) {
          record = mapService.createRecord(name, dataKey, value, DEFAULT_TTL);
          records.put(dataKey, record);
          saveIndex(record);
          updateSizeEstimator(calculateRecordSize(record));
        }
      }

    } else {
      accessRecord(record);
      value = record.getValue();
    }
    value = mapService.interceptGet(name, value);

    return value;
  }