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

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

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

Promise.trySuccess介绍

[英]Marks this future as a success and notifies all listeners.
[中]将此未来标记为成功,并通知所有听众。

代码示例

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

  1. @Override
  2. public boolean trySuccess(T result) {
  3. return promise.trySuccess(result);
  4. }

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

  1. @Override
  2. public boolean trySuccess(T result) {
  3. return promise.trySuccess(result);
  4. }

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

  1. @Override
  2. public List<Runnable> shutdownNow() {
  3. List<Runnable> tasks = super.shutdownNow();
  4. terminationFuture.trySuccess(null);
  5. return tasks;
  6. }

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

  1. @Override
  2. public void shutdown() {
  3. super.shutdown();
  4. terminationFuture.trySuccess(null);
  5. }

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

  1. @Override
  2. public List<Runnable> shutdownNow() {
  3. List<Runnable> tasks = super.shutdownNow();
  4. terminationFuture.trySuccess(null);
  5. return tasks;
  6. }

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

  1. @Override
  2. public void shutdown() {
  3. super.shutdown();
  4. terminationFuture.trySuccess(null);
  5. }

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

  1. @Override
  2. public void operationComplete(Future<Object> future) throws Exception {
  3. // Inefficient, but works.
  4. if (isTerminated()) {
  5. terminationFuture.trySuccess(null);
  6. }
  7. }
  8. };

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

  1. private boolean tryPromise() {
  2. return (cause == null) ? aggregatePromise.trySuccess(null) : aggregatePromise.tryFailure(cause);
  3. }

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

  1. @Override
  2. public void operationComplete(Future<Object> future) throws Exception {
  3. // Inefficient, but works.
  4. if (isTerminated()) {
  5. terminationFuture.trySuccess(null);
  6. }
  7. }
  8. };

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

  1. static <T> void trySuccess(Promise<T> promise, T result) {
  2. if (!promise.trySuccess(result)) {
  3. logger.warn("Failed to notify success ({}) to a promise: {}", result, promise);
  4. }
  5. }

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

  1. private void notifyConnect(ChannelFuture future, Promise<Channel> promise) {
  2. if (future.isSuccess()) {
  3. Channel channel = future.channel();
  4. if (!promise.trySuccess(channel)) {
  5. // Promise was completed in the meantime (like cancelled), just release the channel again
  6. release(channel);
  7. }
  8. } else {
  9. promise.tryFailure(future.cause());
  10. }
  11. }

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

  1. private void notifyConnect(ChannelFuture future, Promise<Channel> promise) {
  2. if (future.isSuccess()) {
  3. Channel channel = future.channel();
  4. if (!promise.trySuccess(channel)) {
  5. // Promise was completed in the meantime (like cancelled), just release the channel again
  6. release(channel);
  7. }
  8. } else {
  9. promise.tryFailure(future.cause());
  10. }
  11. }

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

  1. private static <T> void transferResult(Future<T> src, Promise<T> dst) {
  2. if (src.isSuccess()) {
  3. dst.trySuccess(src.getNow());
  4. } else {
  5. dst.tryFailure(src.cause());
  6. }
  7. }

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

  1. @Override
  2. public boolean onStatus(PubSubType type, CharSequence channel) {
  3. if (name.equals(channel) && this.type.equals(type)) {
  4. promise.trySuccess(null);
  5. }
  6. return true;
  7. }

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

  1. @Override
  2. public boolean onStatus(PubSubType type, CharSequence channel) {
  3. if (name.equals(channel) && this.type.equals(type)) {
  4. promise.trySuccess(null);
  5. }
  6. return true;
  7. }

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

  1. private void setSuccess(AddressedEnvelope<? extends DnsResponse, InetSocketAddress> envelope) {
  2. Promise<AddressedEnvelope<DnsResponse, InetSocketAddress>> promise = this.promise;
  3. @SuppressWarnings("unchecked")
  4. AddressedEnvelope<DnsResponse, InetSocketAddress> castResponse =
  5. (AddressedEnvelope<DnsResponse, InetSocketAddress>) envelope.retain();
  6. if (!promise.trySuccess(castResponse)) {
  7. // We failed to notify the promise as it was failed before, thus we need to release the envelope
  8. envelope.release();
  9. }
  10. }

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

  1. @Override
  2. @Deprecated
  3. public void shutdown() {
  4. shuttingDown = true;
  5. for (EventLoop l: activeChildren) {
  6. l.shutdown();
  7. }
  8. for (EventLoop l: idleChildren) {
  9. l.shutdown();
  10. }
  11. // Notify the future if there was no children.
  12. if (isTerminated()) {
  13. terminationFuture.trySuccess(null);
  14. }
  15. }

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

  1. /**
  2. * Try to mark the {@link Promise} as success and log if {@code logger} is not {@code null} in case this fails.
  3. */
  4. public static <V> void trySuccess(Promise<? super V> p, V result, InternalLogger logger) {
  5. if (!p.trySuccess(result) && logger != null) {
  6. Throwable err = p.cause();
  7. if (err == null) {
  8. logger.warn("Failed to mark a promise as success because it has succeeded already: {}", p);
  9. } else {
  10. logger.warn(
  11. "Failed to mark a promise as success because it has failed already: {}, unnotified cause:",
  12. p, err);
  13. }
  14. }
  15. }

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

  1. public static <X> void cascadeTo(Future<X> completedFuture, Promise<? super X> promise) {
  2. if (completedFuture.isSuccess()) {
  3. if (!promise.trySuccess(completedFuture.getNow())) {
  4. logger.warn("Failed to mark a promise as success because it is done already: {}", promise);
  5. }
  6. } else if (completedFuture.isCancelled()) {
  7. if (!promise.cancel(false)) {
  8. logger.warn("Failed to cancel a promise because it is done already: {}", promise);
  9. }
  10. } else {
  11. if (!promise.tryFailure(completedFuture.cause())) {
  12. logger.warn("Failed to mark a promise as failure because it's done already: {}", promise,
  13. completedFuture.cause());
  14. }
  15. }
  16. }
  17. }

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

  1. @Override
  2. public Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit) {
  3. shuttingDown = true;
  4. for (EventLoop l: activeChildren) {
  5. l.shutdownGracefully(quietPeriod, timeout, unit);
  6. }
  7. for (EventLoop l: idleChildren) {
  8. l.shutdownGracefully(quietPeriod, timeout, unit);
  9. }
  10. // Notify the future if there was no children.
  11. if (isTerminated()) {
  12. terminationFuture.trySuccess(null);
  13. }
  14. return terminationFuture();
  15. }

相关文章