/** @param log Logger. */
    private void execute(GridLogger log) {
      try {
        log.info("Started execute.");

        // Countdown shared job latch so that the main thread know that all jobs are
        // inside the "execute" routine.
        jobLatch.countDown();

        log.info("After job latch.");

        // Await for the main thread to allow jobs to proceed.
        latch.await();

        log.info("After latch.");

        if (awaitMasterLeaveCallback) {
          latch0.await();

          log.info("After latch0.");
        } else log.info("Latch 0 skipped.");
      } catch (InterruptedException e) {
        // We do not expect any interruptions here, hence this statement.
        fail("Unexpected exception: " + e);
      }
    }
    /** {@inheritDoc} */
    @Override
    public Serializable reduce(List<GridComputeJobResult> results) throws GridException {
      if (log.isInfoEnabled()) log.info("Reducing job [job=" + this + ", results=" + results + ']');

      if (results.size() > 1) fail();

      return results.get(0).getData();
    }
    /** {@inheritDoc} */
    @Override
    protected Collection<? extends GridComputeJob> split(int gridSize, Object arg)
        throws GridException {
      if (log.isInfoEnabled())
        log.info("Splitting job [job=" + this + ", gridSize=" + gridSize + ", arg=" + arg + ']');

      Collection<GridComputeJob> jobs = new ArrayList<>(SPLIT_COUNT);

      for (int i = 1; i <= SPLIT_COUNT; i++) jobs.add(new GridCancelTestJob(i));

      return jobs;
    }
    /** {@inheritDoc} */
    @Override
    public Serializable execute() {
      int arg = this.<Integer>argument(0);

      try {
        if (log.isInfoEnabled()) log.info("Executing job [job=" + this + ", arg=" + arg + ']');

        startSignal.countDown();

        try {
          if (!startSignal.await(WAIT_TIME, TimeUnit.MILLISECONDS)) fail();

          if (arg == 1) {
            if (log.isInfoEnabled()) log.info("Job one is proceeding.");
          } else Thread.sleep(WAIT_TIME);
        } catch (InterruptedException e) {
          if (log.isInfoEnabled())
            log.info("Job got cancelled [arg=" + arg + ", ses=" + ses + ", e=" + e + ']');

          return 0;
        }

        if (log.isInfoEnabled()) log.info("Completing job: " + ses);

        return argument(0);
      } finally {
        stopSignal.countDown();

        processedCnt++;
      }
    }
    /**
     * @param log Logger.
     * @param job Actual job.
     */
    private void onMasterLeave(GridLogger log, Object job) {
      log.info("Callback executed: " + job);

      latch0.countDown();

      invokeLatch.countDown();
    }