io.netty.util.concurrent.Promise.addListener()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中io.netty.util.concurrent.Promise.addListener()方法的一些代码示例,展示了Promise.addListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Promise.addListener()方法的具体详情如下:
包路径:io.netty.util.concurrent.Promise
类名称:Promise
方法名:addListener

Promise.addListener介绍

暂无

代码示例

代码示例来源:origin: redisson/redisson

@Override
public RPromise<T> addListener(FutureListener<? super T> listener) {
  promise.addListener(listener);
  return this;
}

代码示例来源:origin: redisson/redisson

@Override
public RPromise<T> addListener(FutureListener<? super T> listener) {
  promise.addListener(listener);
  return this;
}

代码示例来源:origin: netty/netty

AcquireTask(Promise<Channel> promise) {
    super(promise);
    // We need to create a new promise as we need to ensure the AcquireListener runs in the correct
    // EventLoop.
    this.promise = executor.<Channel>newPromise().addListener(this);
  }
}

代码示例来源:origin: netty/netty

p.addListener(this);

代码示例来源:origin: redisson/redisson

public AcquireTask(Promise<Channel> promise) {
    super(promise);
    // We need to create a new promise as we need to ensure the AcquireListener runs in the correct
    // EventLoop.
    this.promise = executor.<Channel>newPromise().addListener(this);
  }
}

代码示例来源:origin: redisson/redisson

p.addListener(this);

代码示例来源:origin: wildfly/wildfly

public AcquireTask(Promise<Channel> promise) {
    super(promise);
    // We need to create a new promise as we need to ensure the AcquireListener runs in the correct
    // EventLoop.
    this.promise = executor.<Channel>newPromise().addListener(this);
  }
}

代码示例来源:origin: line/armeria

@Override
public Promise<T> addListener(
    GenericFutureListener<? extends Future<? super T>> listener) {
  return delegate.addListener(context.makeContextAware(listener));
}

代码示例来源:origin: netty/netty

@Override
public Future<Void> release(final Channel channel, final Promise<Void> promise) {
  ObjectUtil.checkNotNull(promise, "promise");
  final Promise<Void> p = executor.newPromise();
  super.release(channel, p.addListener(new FutureListener<Void>() {
    @Override
    public void operationComplete(Future<Void> future) throws Exception {
      assert executor.inEventLoop();
      if (closed) {
        // Since the pool is closed, we have no choice but to close the channel
        channel.close();
        promise.setFailure(POOL_CLOSED_ON_RELEASE_EXCEPTION);
        return;
      }
      if (future.isSuccess()) {
        decrementAndRunTaskQueue();
        promise.setSuccess(null);
      } else {
        Throwable cause = future.cause();
        // Check if the exception was not because of we passed the Channel to the wrong pool.
        if (!(cause instanceof IllegalArgumentException)) {
          decrementAndRunTaskQueue();
        }
        promise.setFailure(future.cause());
      }
    }
  }));
  return promise;
}

代码示例来源:origin: redisson/redisson

private void doResolveUncached(String hostname,
                DnsRecord[] additionals,
                final Promise<InetAddress> promise,
                DnsCache resolveCache) {
  final Promise<List<InetAddress>> allPromise = executor().newPromise();
  doResolveAllUncached(hostname, additionals, allPromise, resolveCache);
  allPromise.addListener(new FutureListener<List<InetAddress>>() {
    @Override
    public void operationComplete(Future<List<InetAddress>> future) {
      if (future.isSuccess()) {
        trySuccess(promise, future.getNow().get(0));
      } else {
        tryFailure(promise, future.cause());
      }
    }
  });
}

代码示例来源:origin: redisson/redisson

private void renegotiateOnEventLoop(final Promise<Channel> newHandshakePromise) {
  final Promise<Channel> oldHandshakePromise = handshakePromise;
  if (!oldHandshakePromise.isDone()) {
    // There's no need to handshake because handshake is in progress already.
    // Merge the new promise into the old one.
    oldHandshakePromise.addListener(new PromiseNotifier<Channel, Future<Channel>>(newHandshakePromise));
  } else {
    handshakePromise = newHandshakePromise;
    handshake();
    applyHandshakeTimeout();
  }
}

代码示例来源:origin: redisson/redisson

@Override
public Future<Void> release(final Channel channel, final Promise<Void> promise) {
  ObjectUtil.checkNotNull(promise, "promise");
  final Promise<Void> p = executor.newPromise();
  super.release(channel, p.addListener(new FutureListener<Void>() {
    @Override
    public void operationComplete(Future<Void> future) throws Exception {
      assert executor.inEventLoop();
      if (closed) {
        // Since the pool is closed, we have no choice but to close the channel
        channel.close();
        promise.setFailure(POOL_CLOSED_ON_RELEASE_EXCEPTION);
        return;
      }
      if (future.isSuccess()) {
        decrementAndRunTaskQueue();
        promise.setSuccess(null);
      } else {
        Throwable cause = future.cause();
        // Check if the exception was not because of we passed the Channel to the wrong pool.
        if (!(cause instanceof IllegalArgumentException)) {
          decrementAndRunTaskQueue();
        }
        promise.setFailure(future.cause());
      }
    }
  }));
  return promise;
}

代码示例来源:origin: redisson/redisson

private void applyHandshakeTimeout() {
  final Promise<Channel> localHandshakePromise = this.handshakePromise;
  // Set timeout if necessary.
  final long handshakeTimeoutMillis = this.handshakeTimeoutMillis;
  if (handshakeTimeoutMillis <= 0 || localHandshakePromise.isDone()) {
    return;
  }
  final ScheduledFuture<?> timeoutFuture = ctx.executor().schedule(new Runnable() {
    @Override
    public void run() {
      if (localHandshakePromise.isDone()) {
        return;
      }
      try {
        if (localHandshakePromise.tryFailure(HANDSHAKE_TIMED_OUT)) {
          SslUtils.handleHandshakeFailure(ctx, HANDSHAKE_TIMED_OUT, true);
        }
      } finally {
        releaseAndFailAll(HANDSHAKE_TIMED_OUT);
      }
    }
  }, handshakeTimeoutMillis, TimeUnit.MILLISECONDS);
  // Cancel the handshake timeout when handshake is finished.
  localHandshakePromise.addListener(new FutureListener<Channel>() {
    @Override
    public void operationComplete(Future<Channel> f) throws Exception {
      timeoutFuture.cancel(false);
    }
  });
}

代码示例来源:origin: wildfly/wildfly

private void doResolveUncached(String hostname,
                DnsRecord[] additionals,
                final Promise<InetAddress> promise,
                DnsCache resolveCache) {
  final Promise<List<InetAddress>> allPromise = executor().newPromise();
  doResolveAllUncached(hostname, additionals, allPromise, resolveCache);
  allPromise.addListener(new FutureListener<List<InetAddress>>() {
    @Override
    public void operationComplete(Future<List<InetAddress>> future) {
      if (future.isSuccess()) {
        trySuccess(promise, future.getNow().get(0));
      } else {
        tryFailure(promise, future.cause());
      }
    }
  });
}

代码示例来源:origin: netty/netty

AcquireListener l = new AcquireListener(promise);
  l.acquired();
  p.addListener(l);
  super.acquire(p);
} else {

代码示例来源:origin: redisson/redisson

AcquireListener l = new AcquireListener(promise);
  l.acquired();
  p.addListener(l);
  super.acquire(p);
} else {

代码示例来源:origin: Netflix/zuul

operationComplete(promise);
} else {
  promise.addListener(this);

代码示例来源:origin: redisson/redisson

@Override
  public void operationComplete(Future<List<T>> future) {
    Throwable cause = future.cause();
    if (cause == null) {
      promise.trySuccess(future.getNow());
    } else {
      if (DnsNameResolver.isTransportOrTimeoutError(cause)) {
        promise.tryFailure(new SearchDomainUnknownHostException(cause, hostname));
      } else if (searchDomainIdx < searchDomains.length) {
        Promise<List<T>> newPromise = parent.executor().newPromise();
        newPromise.addListener(this);
        doSearchDomainQuery(hostname + '.' + searchDomains[searchDomainIdx++], newPromise);
      } else if (!startWithoutSearchDomain) {
        internalResolve(hostname, promise);
      } else {
        promise.tryFailure(new SearchDomainUnknownHostException(cause, hostname));
      }
    }
  }
});

代码示例来源:origin: redisson/redisson

DnsQueryContext(DnsNameResolver parent,
        InetSocketAddress nameServerAddr,
        DnsQuestion question,
        DnsRecord[] additionals,
        Promise<AddressedEnvelope<DnsResponse, InetSocketAddress>> promise) {
  this.parent = checkNotNull(parent, "parent");
  this.nameServerAddr = checkNotNull(nameServerAddr, "nameServerAddr");
  this.question = checkNotNull(question, "question");
  this.additionals = checkNotNull(additionals, "additionals");
  this.promise = checkNotNull(promise, "promise");
  recursionDesired = parent.isRecursionDesired();
  id = parent.queryContextManager.add(this);
  // Ensure we remove the id from the QueryContextManager once the query completes.
  promise.addListener(this);
  if (parent.isOptResourceEnabled()) {
    optResource = new AbstractDnsOptPseudoRrRecord(parent.maxPayloadSize(), 0, 0) {
      // We may want to remove this in the future and let the user just specify the opt record in the query.
    };
  } else {
    optResource = null;
  }
}

代码示例来源:origin: Netflix/zuul

operationComplete(promise);
} else {
  promise.addListener(this);

相关文章