Example #1
0
  public boolean compare(String mapName, Object value1, Object value2) {
    if (value1 == null && value2 == null) {
      return true;
    }
    if (value1 == null) {
      return false;
    }
    if (value2 == null) {
      return false;
    }

    MapContainer mapContainer = getMapContainer(mapName);
    return mapContainer.getRecordFactory().isEquals(value1, value2);
  }
Example #2
0
  public Record createRecord(
      String name, Data dataKey, Object value, long ttl, boolean shouldSchedule) {
    MapContainer mapContainer = getMapContainer(name);
    Record record = mapContainer.getRecordFactory().newRecord(dataKey, value);

    if (shouldSchedule) {
      // if ttl is 0 then no eviction. if ttl is -1 then default configured eviction is applied
      if (ttl < 0 && mapContainer.getMapConfig().getTimeToLiveSeconds() > 0) {
        scheduleTtlEviction(
            name, record, mapContainer.getMapConfig().getTimeToLiveSeconds() * 1000);
      } else if (ttl > 0) {
        scheduleTtlEviction(name, record, ttl);
      }
      if (mapContainer.getMapConfig().getMaxIdleSeconds() > 0) {
        scheduleIdleEviction(name, dataKey, mapContainer.getMapConfig().getMaxIdleSeconds() * 1000);
      }
    }
    return record;
  }
 public DefaultRecordStore(String name, MapService mapService, int partitionId) {
   this.name = name;
   this.partitionId = partitionId;
   this.mapService = mapService;
   this.mapContainer = mapService.getMapContainer(name);
   this.logger = mapService.getNodeEngine().getLogger(this.getName());
   recordFactory = mapContainer.getRecordFactory();
   NodeEngine nodeEngine = mapService.getNodeEngine();
   final LockService lockService = nodeEngine.getSharedService(LockService.SERVICE_NAME);
   this.lockStore =
       lockService == null
           ? null
           : lockService.createLockStore(
               partitionId, new DefaultObjectNamespace(MapService.SERVICE_NAME, name));
   this.sizeEstimator = SizeEstimators.createMapSizeEstimator();
   final int mapLoadChunkSize = nodeEngine.getGroupProperties().MAP_LOAD_CHUNK_SIZE.getInteger();
   final Queue<Map> chunks = new LinkedList<Map>();
   if (nodeEngine
       .getThisAddress()
       .equals(nodeEngine.getPartitionService().getPartitionOwner(partitionId))) {
     if (mapContainer.getStore() != null && !loaded.get()) {
       Map<Data, Object> loadedKeys = mapContainer.getInitialKeys();
       if (loadedKeys != null && !loadedKeys.isEmpty()) {
         Map<Data, Object> partitionKeys = new HashMap<Data, Object>();
         Iterator<Map.Entry<Data, Object>> iterator = loadedKeys.entrySet().iterator();
         while (iterator.hasNext()) {
           final Map.Entry<Data, Object> entry = iterator.next();
           final Data data = entry.getKey();
           if (partitionId == nodeEngine.getPartitionService().getPartitionId(data)) {
             partitionKeys.put(data, entry.getValue());
             // split into chunks
             if (partitionKeys.size() >= mapLoadChunkSize) {
               chunks.add(partitionKeys);
               partitionKeys = new HashMap<Data, Object>();
             }
             iterator.remove();
           }
         }
         if (!partitionKeys.isEmpty()) {
           chunks.add(partitionKeys);
         }
         if (!chunks.isEmpty()) {
           try {
             Map<Data, Object> chunkedKeys;
             final AtomicInteger checkIfMapLoaded = new AtomicInteger(chunks.size());
             while ((chunkedKeys = chunks.poll()) != null) {
               nodeEngine
                   .getExecutionService()
                   .submit("hz:map-load", new MapLoadAllTask(chunkedKeys, checkIfMapLoaded));
             }
           } catch (Throwable t) {
             throw ExceptionUtil.rethrow(t);
           }
         } else {
           loaded.set(true);
         }
       } else {
         loaded.set(true);
       }
     }
   } else {
     loaded.set(true);
   }
 }