Exemplo n.º 1
0
  public T get(long timeout, TimeUnit unit) {
    if (isDone()) {
      return getResultValue();
    }

    Thread thread = Thread.currentThread();

    // _thread = thread;

    long expires = unit.toMillis(timeout) + System.currentTimeMillis();

    while (true) {
      if (isDone()) {
        return getResultValue();
      } else if (_state == FutureState.ASYNC) {
        Result<Object> chain = _chain;
        Object chainValue = _chainValue;
        _chain = null;
        _chainValue = null;

        _state = FutureState.INIT;

        // _thread = null;

        chain.completeFuture(chainValue);

        /*
        if (isDone()) {
          return getResultValue();
        }
        */

        // _thread = thread;
      } else {
        if (ServiceRef.flushOutboxAndExecuteLast()) {
          // if pending messages, continue to process them
          continue;
        }

        // ServiceRef.flushOutbox();

        _thread = thread;

        if (_state.isParkRequired()) {
          if (expires < System.currentTimeMillis()) {
            _thread = null;

            throw new ServiceExceptionFutureTimeout("future timeout " + timeout + " " + unit);
          }

          LockSupport.parkUntil(expires);
        }

        _thread = null;
      }
    }
  }
Exemplo n.º 2
0
 public final boolean isDone() {
   return _state.isDone();
 }