/** Handles size after put. */
  private void onPut() {
    cnt.incrementAndGet();

    int c;

    while ((c = cnt.get()) > max) {
      // Decrement count.
      if (cnt.compareAndSet(c, c - 1)) {
        try {
          K key = firstEntry().getKey();

          V val;

          // Make sure that an element is removed.
          while ((val = super.remove(firstEntry().getKey())) == null) {
            // No-op.
          }

          assert val != null;

          GridInClosure2<K, V> lsnr = this.lsnr;

          // Listener notification.
          if (lsnr != null) lsnr.apply(key, val);
        } catch (NoSuchElementException e1) {
          e1.printStackTrace(); // Should never happen.

          assert false : "Internal error in grid bounded ordered set.";
        }
      }
    }
  }
예제 #2
0
  /**
   * Gets closure that ignores its arguments and executes the same way as this absolute closure.
   *
   * @param <E1> Type of 1st ignore argument.
   * @param <E2> Type of 2nd ignore argument.
   * @return Closure that ignores its arguments and executes the same way as this absolute closure.
   */
  public <E1, E2> GridInClosure2<E1, E2> uncurry2() {
    GridInClosure2<E1, E2> c =
        new CI2<E1, E2>() {
          @Override
          public void apply(E1 e1, E2 e2) {
            GridAbsClosure.this.apply();
          }
        };

    c.peerDeployLike(this);

    return withMeta(c);
  }