Ejemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public boolean heldcc() {
    if (ctx == null) return false;

    if (job == null) job = ctx.job().activeJob(jobId);

    return job != null && job.held();
  }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public void callcc() {
    if (ctx != null) {
      if (job == null) job = ctx.job().activeJob(jobId);

      if (job != null)
        // Execute in the same thread.
        job.execute();
    }
  }
Ejemplo n.º 3
0
  /** {@inheritDoc} */
  @Override
  public <T> T holdcc(long timeout) {
    if (ctx != null) {
      if (job == null) job = ctx.job().activeJob(jobId);

      // Completed?
      if (job != null) {
        if (timeout > 0 && !job.isDone()) {
          final long endTime = System.currentTimeMillis() + timeout;

          // Overflow.
          if (endTime > 0) {
            ctx.timeout()
                .addTimeoutObject(
                    new GridTimeoutObject() {
                      private final GridUuid id = GridUuid.randomUuid();

                      @Override
                      public GridUuid timeoutId() {
                        return id;
                      }

                      @Override
                      public long endTime() {
                        return endTime;
                      }

                      @Override
                      public void onTimeout() {
                        callcc();
                      }
                    });
          }
        }

        job.hold();
      }
    }

    return null;
  }