/** Shrinks queue to maximum allowed size. */
  private void shrink() {
    long maxSize = this.maxSize;
    int maxBlocks = this.maxBlocks;

    int cnt = queue.sizex();

    for (int i = 0;
        i < cnt
            && (maxBlocks > 0 && queue.sizex() > maxBlocks
                || maxSize > 0 && curSize.longValue() > maxSize);
        i++) {
      GridCacheEntry<GridGgfsBlockKey, byte[]> entry = queue.poll();

      if (entry == null) break; // Queue is empty.

      byte[] val = entry.peek();

      if (val != null)
        changeSize(-val.length); // Change current size as we polled entry from the queue.

      if (!entry.evict()) {
        // Reorder entries which we failed to evict.
        entry.removeMeta(META_NODE);

        touch(entry);
      }
    }
  }
 /** {@inheritDoc} */
 @Override
 public long getCurrentSize() {
   return curSize.longValue();
 }
 /**
  * Change current size.
  *
  * @param delta Delta in bytes.
  */
 private void changeSize(int delta) {
   if (delta != 0) curSize.add(delta);
 }