コード例 #1
0
    /**
     * @param e Entry.
     * @return Continuous query entry.
     */
    private CacheContinuousQueryEntry skipEntry(CacheContinuousQueryEntry e) {
      if (lastFiredCntr.get() > e.updateCounter() || e.updateCounter() == 1) {

        e.markFiltered();

        return e;
      } else {
        buf.add(e.updateCounter());

        // Double check. If another thread sent a event with counter higher than this event.
        if (lastFiredCntr.get() > e.updateCounter() && buf.contains(e.updateCounter())) {
          buf.remove(e.updateCounter());

          e.markFiltered();

          return e;
        } else return null;
      }
    }
コード例 #2
0
    /**
     * Add continuous entry.
     *
     * @param e Cache continuous query entry.
     * @return Collection entries which will be fired.
     */
    public CacheContinuousQueryEntry handle(CacheContinuousQueryEntry e) {
      assert e != null;

      if (e.isFiltered()) {
        Long last = buf.lastx();
        Long first = buf.firstx();

        if (last != null && first != null && last - first >= MAX_BUFF_SIZE) {
          NavigableSet<Long> prevHoles = buf.subSet(first, true, last, true);

          GridLongList filteredEvts = new GridLongList((int) (last - first));

          int size = 0;

          Long cntr;

          while ((cntr = prevHoles.pollFirst()) != null) {
            filteredEvts.add(cntr);

            ++size;
          }

          filteredEvts.truncate(size, true);

          e.filteredEvents(filteredEvts);

          return e;
        }

        if (lastFiredCntr.get() > e.updateCounter() || e.updateCounter() == 1) return e;
        else {
          buf.add(e.updateCounter());

          // Double check. If another thread sent a event with counter higher than this event.
          if (lastFiredCntr.get() > e.updateCounter() && buf.contains(e.updateCounter())) {
            buf.remove(e.updateCounter());

            return e;
          } else return null;
        }
      } else {
        long prevVal = updateFiredCounter(e.updateCounter());

        if (prevVal == -1) return e;
        else {
          NavigableSet<Long> prevHoles = buf.subSet(prevVal, true, e.updateCounter(), true);

          GridLongList filteredEvts = new GridLongList((int) (e.updateCounter() - prevVal));

          int size = 0;

          Long cntr;

          while ((cntr = prevHoles.pollFirst()) != null) {
            filteredEvts.add(cntr);

            ++size;
          }

          filteredEvts.truncate(size, true);

          e.filteredEvents(filteredEvts);

          return e;
        }
      }
    }