Example #1
0
 @Override
 public Map<K, V> getAll(Set<K> keys) {
   Set<Data> keySet = new HashSet(keys.size());
   Map<K, V> result = new HashMap<K, V>();
   for (Object key : keys) {
     keySet.add(toData(key));
   }
   if (nearCache != null) {
     final Iterator<Data> iterator = keySet.iterator();
     while (iterator.hasNext()) {
       Data key = iterator.next();
       Object cached = nearCache.get(key);
       if (cached != null && !ClientNearCache.NULL_OBJECT.equals(cached)) {
         result.put((K) toObject(key), (V) cached);
         iterator.remove();
       }
     }
   }
   if (keys.isEmpty()) {
     return result;
   }
   MapGetAllRequest request = new MapGetAllRequest(name, keySet);
   MapEntrySet mapEntrySet = invoke(request);
   Set<Entry<Data, Data>> entrySet = mapEntrySet.getEntrySet();
   for (Entry<Data, Data> dataEntry : entrySet) {
     final V value = (V) toObject(dataEntry.getValue());
     final K key = (K) toObject(dataEntry.getKey());
     result.put(key, value);
     if (nearCache != null) {
       nearCache.put(dataEntry.getKey(), value);
     }
   }
   return result;
 }
 @Override
 protected Object reduce(Map<Integer, Object> map) {
   MapEntrySet resultSet = new MapEntrySet();
   MapService mapService = getService();
   for (Map.Entry<Integer, Object> entry : map.entrySet()) {
     MapEntrySet mapEntrySet = (MapEntrySet) mapService.toObject(entry.getValue());
     Set<Map.Entry<Data, Data>> entrySet = mapEntrySet.getEntrySet();
     for (Map.Entry<Data, Data> dataEntry : entrySet) {
       resultSet.add(dataEntry);
     }
   }
   return resultSet;
 }
Example #3
0
 @Override
 public Map<K, Object> executeOnEntries(EntryProcessor entryProcessor) {
   MapExecuteOnAllKeysRequest request = new MapExecuteOnAllKeysRequest(name, entryProcessor);
   MapEntrySet entrySet = invoke(request);
   Map<K, Object> result = new HashMap<K, Object>();
   for (Entry<Data, Data> dataEntry : entrySet.getEntrySet()) {
     final Data keyData = dataEntry.getKey();
     final Data valueData = dataEntry.getValue();
     K key = toObject(keyData);
     result.put(key, toObject(valueData));
   }
   return result;
 }
 @Override
 protected Object reduce(Map<Integer, Object> map) {
   MapEntrySet result = new MapEntrySet();
   MapService mapService = getService();
   for (Object o : map.values()) {
     if (o != null) {
       MapEntrySet entrySet = (MapEntrySet) mapService.toObject(o);
       Set<Map.Entry<Data, Data>> entries = entrySet.getEntrySet();
       for (Map.Entry<Data, Data> entry : entries) {
         result.add(entry);
       }
     }
   }
   return result;
 }
Example #5
0
 @Override
 public Set<Entry<K, V>> entrySet() {
   MapEntrySetRequest request = new MapEntrySetRequest(name);
   MapEntrySet result = invoke(request);
   Set<Entry<K, V>> entrySet = new HashSet<Entry<K, V>>();
   Set<Entry<Data, Data>> entries = result.getEntrySet();
   for (Entry<Data, Data> dataEntry : entries) {
     Data keyData = dataEntry.getKey();
     Data valueData = dataEntry.getValue();
     K key = toObject(keyData);
     V value = toObject(valueData);
     entrySet.add(new AbstractMap.SimpleEntry<K, V>(key, value));
   }
   return entrySet;
 }
Example #6
0
  @Override
  public Map<K, Object> executeOnKeys(Set<K> keys, EntryProcessor entryProcessor) {
    Set<Data> dataKeys = new HashSet<Data>(keys.size());
    for (K key : keys) {
      dataKeys.add(toData(key));
    }

    MapExecuteOnKeysRequest request = new MapExecuteOnKeysRequest(name, entryProcessor, dataKeys);
    MapEntrySet entrySet = invoke(request);
    Map<K, Object> result = new HashMap<K, Object>();
    for (Entry<Data, Data> dataEntry : entrySet.getEntrySet()) {
      final Data keyData = dataEntry.getKey();
      final Data valueData = dataEntry.getValue();
      K key = toObject(keyData);
      result.put(key, toObject(valueData));
    }
    return result;
  }
 public void run() {
   backupRecordInfos = new ArrayList<RecordInfo>();
   backupEntrySet = new ArrayList<Map.Entry<Data, Data>>();
   int partitionId = getPartitionId();
   final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
   RecordStore recordStore = mapServiceContext.getRecordStore(partitionId, name);
   Set<Map.Entry<Data, Data>> entries = entrySet.getEntrySet();
   InternalPartitionService partitionService = getNodeEngine().getPartitionService();
   Set<Data> keysToInvalidate = new HashSet<Data>();
   for (Map.Entry<Data, Data> entry : entries) {
     Data dataKey = entry.getKey();
     Data dataValue = entry.getValue();
     if (partitionId == partitionService.getPartitionId(dataKey)) {
       Data dataOldValue = null;
       if (initialLoad) {
         recordStore.putFromLoad(dataKey, dataValue, -1);
       } else {
         dataOldValue = mapServiceContext.toData(recordStore.put(dataKey, dataValue, -1));
       }
       mapServiceContext.interceptAfterPut(name, dataValue);
       EntryEventType eventType =
           dataOldValue == null ? EntryEventType.ADDED : EntryEventType.UPDATED;
       final MapEventPublisher mapEventPublisher = mapServiceContext.getMapEventPublisher();
       mapEventPublisher.publishEvent(
           getCallerAddress(), name, eventType, dataKey, dataOldValue, dataValue);
       keysToInvalidate.add(dataKey);
       if (mapContainer.getWanReplicationPublisher() != null
           && mapContainer.getWanMergePolicy() != null) {
         Record record = recordStore.getRecord(dataKey);
         final Data dataValueAsData = mapServiceContext.toData(dataValue);
         final EntryView entryView =
             EntryViews.createSimpleEntryView(dataKey, dataValueAsData, record);
         mapEventPublisher.publishWanReplicationUpdate(name, entryView);
       }
       backupEntrySet.add(entry);
       RecordInfo replicationInfo = Records.buildRecordInfo(recordStore.getRecord(dataKey));
       backupRecordInfos.add(replicationInfo);
     }
   }
   invalidateNearCaches(keysToInvalidate);
 }