public void clear() {
    checkIfLoaded();
    resetSizeEstimator();
    final Collection<Data> lockedKeys =
        lockStore != null ? lockStore.getLockedKeys() : Collections.<Data>emptySet();
    final Map<Data, Record> lockedRecords = new HashMap<Data, Record>(lockedKeys.size());
    // Locked records should not be removed!
    for (Data key : lockedKeys) {
      Record record = records.get(key);
      if (record != null) {
        lockedRecords.put(key, record);
        updateSizeEstimator(calculateRecordSize(record));
      }
    }
    Set<Data> keysToDelete = records.keySet();
    keysToDelete.removeAll(lockedRecords.keySet());

    final MapStoreWrapper store = mapContainer.getStore();
    // Use an ArrayList so that we don't trigger calls to equals or hashCode on the key objects
    Collection<Object> keysObject = new ArrayList<Object>(keysToDelete.size());
    for (Data key : keysToDelete) {
      // todo ea have a clear(Keys) method for optimizations
      removeIndex(key);
      keysObject.add(mapService.toObject(key));
    }

    if (store != null) {
      store.deleteAll(keysObject);
      toBeRemovedKeys.removeAll(keysToDelete);
    }

    clearRecordsMap(lockedRecords);
    cancelAssociatedSchedulers(keysToDelete);
    resetAccessSequenceNumber();
  }
Beispiel #2
0
 private void destroyMapStores() {
   for (MapContainer mapContainer : mapContainers.values()) {
     MapStoreWrapper store = mapContainer.getStore();
     if (store != null) {
       store.destroy();
     }
   }
 }
 private void mapStoreDelete(Record record, Data key) {
   final MapStoreWrapper store = mapContainer.getStore();
   if (store != null) {
     long writeDelayMillis = mapContainer.getWriteDelayMillis();
     if (writeDelayMillis == 0) {
       store.delete(mapService.toObject(key));
       // todo ea record will be deleted then why calling onStore
       if (record != null) {
         record.onStore();
       }
     } else {
       mapService.scheduleMapStoreDelete(name, key, writeDelayMillis);
       toBeRemovedKeys.add(key);
     }
   }
 }
 private Object writeMapStore(Data dataKey, Object recordValue, Record record) {
   final MapStoreWrapper store = mapContainer.getStore();
   if (store != null) {
     if (mapContainer.getWriteDelayMillis() <= 0) {
       Object objectValue = mapService.toObject(recordValue);
       store.store(mapService.toObject(dataKey), objectValue);
       if (record != null) {
         record.onStore();
       }
       // if store is not a post-processing map-store, then avoid extra de-serialization phase.
       return store.isPostProcessingMapStore() ? objectValue : recordValue;
     } else {
       mapService.scheduleMapStoreWrite(
           name, dataKey, recordValue, mapContainer.getWriteDelayMillis());
     }
   }
   return recordValue;
 }