/** {@inheritDoc} */
    @Override
    public Integer call() throws Exception {
      GridCacheTx tx = CU.txStartInternal(ctx, latchView, PESSIMISTIC, REPEATABLE_READ);

      try {
        GridCacheCountDownLatchValue latchVal = latchView.get(key);

        if (latchVal == null) {
          if (log.isDebugEnabled())
            log.debug("Failed to find count down latch with given name: " + name);

          assert cnt == 0;

          return cnt;
        }

        int retVal;

        if (val > 0) {
          retVal = latchVal.get() - val;

          if (retVal < 0) retVal = 0;
        } else retVal = 0;

        latchVal.set(retVal);

        latchView.put(key, latchVal);

        tx.commit();

        return retVal;
      } finally {
        tx.end();
      }
    }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public void commit() throws GridException {
    enter();

    try {
      tx.commit();
    } finally {
      leave();
    }
  }