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

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

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

Promise.cancel介绍

暂无

代码示例

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

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
  return promise.cancel(mayInterruptIfRunning);
}

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

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
  return promise.cancel(mayInterruptIfRunning);
}

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

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
  return delegate.cancel(mayInterruptIfRunning);
}

代码示例来源:origin: apache/hive

@Override
public void close() {
 try {
  channel.close();
  for (ClientInfo client : pendingClients.values()) {
   client.promise.cancel(true);
  }
  pendingClients.clear();
 } finally {
  group.shutdownGracefully();
 }
}

代码示例来源:origin: apache/hive

@Override
public final void channelInactive(ChannelHandlerContext ctx) throws Exception {
 if (rpcs.size() > 0) {
  LOG.warn("[{}] Closing RPC channel with {} outstanding RPCs.", name(), rpcs.size());
  for (OutstandingRpc rpc : rpcs) {
   rpc.future.cancel(true);
  }
 }
 super.channelInactive(ctx);
}

代码示例来源:origin: apache/hive

/** Requests a running job to be cancelled. */
@Override
public boolean cancel(boolean mayInterrupt) {
 if (changeState(State.CANCELLED)) {
  client.cancel(jobId);
  promise.cancel(mayInterrupt);
  return true;
 }
 return false;
}

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

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

代码示例来源: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

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

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

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: wildfly/wildfly

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

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

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: wildfly/wildfly

@Override
  public void operationComplete(ChannelFuture future) throws Exception {
    if (future.isSuccess()) {
      promise.setSuccess(streamChannel);
    } else if (future.isCancelled()) {
      promise.cancel(false);
    } else {
      if (streamChannel.isRegistered()) {
        streamChannel.close();
      } else {
        streamChannel.unsafe().closeForcibly();
      }
      promise.setFailure(future.cause());
    }
  }
});

代码示例来源:origin: io.netty/netty-common

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

代码示例来源:origin: io.netty/netty-common

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: jurmous/etcd4j

/**
 * Cancel the request
 *
 * @param throwable the exception to be associated to this promise
 */
public void cancel(Throwable throwable) {
 this.promise.cancel(true);
 this.exception = throwable;
}

代码示例来源:origin: org.nanoframework/nano-ext-etcd

/**
 * Cancel the request
 */
public void cancel() {
 promise.cancel(true);
}

代码示例来源:origin: com.cloudera.livy/livy-rsc

@Override
public final void channelInactive(ChannelHandlerContext ctx) throws Exception {
 if (rpcs.size() > 0) {
  LOG.warn("[{}] Closing RPC channel with {} outstanding RPCs.", name(), rpcs.size());
  for (OutstandingRpc rpc : rpcs) {
   rpc.future.cancel(true);
  }
 } else {
  LOG.debug("Channel {} became inactive.", ctx.channel());
 }
 super.channelInactive(ctx);
}

代码示例来源:origin: org.spark-project.hive/spark-client

@Override
public final void channelInactive(ChannelHandlerContext ctx) throws Exception {
 if (rpcs.size() > 0) {
  LOG.warn("[{}] Closing RPC channel with {} outstanding RPCs.", name(), rpcs.size());
  for (OutstandingRpc rpc : rpcs) {
   rpc.future.cancel(true);
  }
 }
 super.channelInactive(ctx);
}

代码示例来源:origin: com.cloudera.livy/livy-rsc

/** Requests a running job to be cancelled. */
@Override
public boolean cancel(boolean mayInterrupt) {
 if (changeState(State.CANCELLED)) {
  client.cancel(jobId);
  promise.cancel(mayInterrupt);
  return true;
 }
 return false;
}

相关文章