コード例 #1
0
  @Override
  public boolean put(K key, V value) {
    SpillableSetImpl<V> spillableSet = getHelper(key);

    if (spillableSet == null) {
      if (timeExtractor == null) {
        spillableSet =
            new SpillableSetImpl<>(
                bucket,
                keyValueSerdeManager.serializeDataKey(key, true).toByteArray(),
                store,
                valueSerde);
      } else {
        spillableSet =
            new SpillableSetImpl<>(
                keyValueSerdeManager.serializeDataKey(key, true).toByteArray(),
                store,
                valueSerde,
                new FixedTimeExtractor(timeExtractor.getTime(key)));
      }
      spillableSet.setup(context);
      cache.put(key, spillableSet);
    }
    return spillableSet.add(value);
  }
コード例 #2
0
  private SpillableSetImpl<V> getHelper(@NotNull K key) {
    SpillableSetImpl<V> spillableSet = cache.get(key);

    if (spillableSet == null) {
      long keyTime = -1;
      Pair<Integer, V> meta;
      if (timeExtractor != null) {
        keyTime = timeExtractor.getTime(key);
      }
      meta = map.get(key);

      if (meta == null) {
        return null;
      }

      Slice keyPrefix = keyValueSerdeManager.serializeDataKey(key, false);
      if (timeExtractor != null) {
        spillableSet =
            new SpillableSetImpl<>(
                keyPrefix.toByteArray(), store, valueSerde, new FixedTimeExtractor(keyTime));
      } else {
        spillableSet = new SpillableSetImpl<>(bucket, keyPrefix.toByteArray(), store, valueSerde);
      }
      spillableSet.setSize(meta.getLeft());
      spillableSet.setHead(meta.getRight());
      spillableSet.setup(context);
    }

    cache.put(key, spillableSet);

    return spillableSet;
  }
コード例 #3
0
  @Override
  public void endWindow() {
    for (K key : cache.getChangedKeys()) {

      SpillableSetImpl<V> spillableSet = cache.get(key);
      spillableSet.endWindow();

      map.put(key, new ImmutablePair<>(spillableSet.size(), spillableSet.getHead()));
    }

    for (SpillableSetImpl removedSet : removedSets) {
      removedSet.endWindow();
    }
    removedSets.clear();

    cache.endWindow();
    map.endWindow();

    keyValueSerdeManager.resetReadBuffer();
  }
コード例 #4
0
 @Override
 public void beginWindow(long windowId) {
   map.beginWindow(windowId);
   keyValueSerdeManager.beginWindow(windowId);
 }
コード例 #5
0
 @Override
 public void setup(Context.OperatorContext context) {
   this.context = context;
   map.setup(context);
   keyValueSerdeManager.setup(store, bucket);
 }