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

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

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

Promise.tryFailure介绍

[英]Marks this future as a failure and notifies all listeners.
[中]将此未来标记为失败,并通知所有侦听器。

代码示例

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

@Override
public boolean tryFailure(Throwable cause) {
  return promise.tryFailure(cause);
}

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

@Override
public boolean tryFailure(Throwable cause) {
  return promise.tryFailure(cause);
}

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

private static void closeAndFail(Channel channel, Throwable cause, Promise<?> promise) {
  closeChannel(channel);
  promise.tryFailure(cause);
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Override
 protected void onFailure(Throwable t) {
  try {
   asyncHandler.onHostnameResolutionFailure(hostname, t);
  } catch (Exception e) {
   LOGGER.error("onHostnameResolutionFailure crashed", e);
   promise.tryFailure(e);
   return;
  }
  promise.tryFailure(t);
 }
});

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

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

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

private static void closeAndFail(Channel channel, Throwable cause, Promise<?> promise) {
  closeChannel(channel);
  promise.tryFailure(cause);
}

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

private static void tryFailure(Promise<?> promise, Throwable cause) {
  if (!promise.tryFailure(cause)) {
    logger.warn("Failed to notify failure to a promise: {}", promise, cause);
  }
}

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

private void notifyConnect(ChannelFuture future, Promise<Channel> promise) {
  if (future.isSuccess()) {
    Channel channel = future.channel();
    if (!promise.trySuccess(channel)) {
      // Promise was completed in the meantime (like cancelled), just release the channel again
      release(channel);
    }
  } else {
    promise.tryFailure(future.cause());
  }
}

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

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

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

@Override
  public void operationComplete(Future<? super Channel> future) {
    if (future.isSuccess()) {
      // If the query is done in a late fashion (as the channel was not ready yet) we always flush
      // to ensure we did not race with a previous flush() that was done when the Channel was not
      // ready yet.
      writeQuery(query, true, writePromise);
    } else {
      Throwable cause = future.cause();
      promise.tryFailure(cause);
      writePromise.setFailure(cause);
    }
  }
});

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

private void notifyConnect(ChannelFuture future, Promise<Channel> promise) {
  if (future.isSuccess()) {
    Channel channel = future.channel();
    if (!promise.trySuccess(channel)) {
      // Promise was completed in the meantime (like cancelled), just release the channel again
      release(channel);
    }
  } else {
    promise.tryFailure(future.cause());
  }
}

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

private static <T> void transferResult(Future<T> src, Promise<T> dst) {
  if (src.isSuccess()) {
    dst.trySuccess(src.getNow());
  } else {
    dst.tryFailure(src.cause());
  }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Override
protected void onSuccess(List<InetAddress> value) {
 ArrayList<InetSocketAddress> socketAddresses = new ArrayList<>(value.size());
 for (InetAddress a : value) {
  socketAddresses.add(new InetSocketAddress(a, port));
 }
 try {
  asyncHandler.onHostnameResolutionSuccess(hostname, socketAddresses);
 } catch (Exception e) {
  LOGGER.error("onHostnameResolutionSuccess crashed", e);
  promise.tryFailure(e);
  return;
 }
 promise.trySuccess(socketAddresses);
}

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

@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);

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

private boolean query(String hostname, DnsRecordType type, DnsServerAddressStream dnsServerAddressStream,
           boolean flush, Promise<List<T>> promise) {
  final DnsQuestion question;
  try {
    question = new DefaultDnsQuestion(hostname, type, dnsClass);
  } catch (Throwable cause) {
    // Assume a single failure means that queries will succeed. If the hostname is invalid for one type
    // there is no case where it is known to be valid for another type.
    promise.tryFailure(new IllegalArgumentException("Unable to create DNS Question for: [" + hostname + ", " +
        type + ']', cause));
    return false;
  }
  query(dnsServerAddressStream, 0, question, newDnsQueryLifecycleObserver(question), flush, promise, null);
  return true;
}

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

private boolean ensureThreadStarted(int oldState) {
  if (oldState == ST_NOT_STARTED) {
    try {
      doStartThread();
    } catch (Throwable cause) {
      STATE_UPDATER.set(this, ST_TERMINATED);
      terminationFuture.tryFailure(cause);
      if (!(cause instanceof Exception)) {
        // Also rethrow as it may be an OOME for example
        PlatformDependent.throwException(cause);
      }
      return true;
    }
  }
  return false;
}

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

public static <X> void cascadeTo(Future<X> completedFuture, Promise<? super X> promise) {
    if (completedFuture.isSuccess()) {
      if (!promise.trySuccess(completedFuture.getNow())) {
        logger.warn("Failed to mark a promise as success because it is done already: {}", promise);
      }
    } else if (completedFuture.isCancelled()) {
      if (!promise.cancel(false)) {
        logger.warn("Failed to cancel a promise because it is done already: {}", promise);
      }
    } else {
      if (!promise.tryFailure(completedFuture.cause())) {
        logger.warn("Failed to mark a promise as failure because it's done already: {}", promise,
              completedFuture.cause());
      }
    }
  }
}

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

private boolean ensureThreadStarted(int oldState) {
  if (oldState == ST_NOT_STARTED) {
    try {
      doStartThread();
    } catch (Throwable cause) {
      STATE_UPDATER.set(this, ST_TERMINATED);
      terminationFuture.tryFailure(cause);
      if (!(cause instanceof Exception)) {
        // Also rethrow as it may be an OOME for example
        PlatformDependent.throwException(cause);
      }
      return true;
    }
  }
  return false;
}

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

/**
 * Try to mark the {@link Promise} as failure and log if {@code logger} is not {@code null} in case this fails.
 */
public static void tryFailure(Promise<?> p, Throwable cause, InternalLogger logger) {
  if (!p.tryFailure(cause) && logger != null) {
    Throwable err = p.cause();
    if (err == null) {
      logger.warn("Failed to mark a promise as failure because it has succeeded already: {}", p, cause);
    } else {
      logger.warn(
          "Failed to mark a promise as failure because it has failed already: {}, unnotified cause: {}",
          p, ThrowableUtil.stackTraceToString(err), cause);
    }
  }
}

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

/**
 * Try to mark the {@link Promise} as failure and log if {@code logger} is not {@code null} in case this fails.
 */
public static void tryFailure(Promise<?> p, Throwable cause, InternalLogger logger) {
  if (!p.tryFailure(cause) && logger != null) {
    Throwable err = p.cause();
    if (err == null) {
      logger.warn("Failed to mark a promise as failure because it has succeeded already: {}", p, cause);
    } else {
      logger.warn(
          "Failed to mark a promise as failure because it has failed already: {}, unnotified cause: {}",
          p, ThrowableUtil.stackTraceToString(err), cause);
    }
  }
}

相关文章