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

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

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

Promise.setSuccess介绍

[英]Marks this future as a success and notifies all listeners. If it is success or failed already it will throw an IllegalStateException.
[中]将此未来标记为成功,并通知所有听众。如果它已经成功或失败,它将抛出一个非法的例外。

代码示例

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

@Override
protected void doResolve(SocketAddress unresolvedAddress, Promise<SocketAddress> promise) throws Exception {
  promise.setSuccess(unresolvedAddress);
}

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

@Override
  protected void doResolveAll(
      SocketAddress unresolvedAddress, Promise<List<SocketAddress>> promise) throws Exception {
    promise.setSuccess(Collections.singletonList(unresolvedAddress));
  }
}

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

@Override
  public void operationComplete(Future<Object> future) throws Exception {
    if (terminatedChildren.incrementAndGet() == children.length) {
      terminationFuture.setSuccess(null);
    }
  }
};

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

@Override
  protected void doResolveAll(
      SocketAddress unresolvedAddress, Promise<List<SocketAddress>> promise) throws Exception {
    promise.setSuccess(Collections.singletonList(unresolvedAddress));
  }
}

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

@Override
  public void operationComplete(Future<List<T>> future) throws Exception {
    if (future.isSuccess()) {
      promise.setSuccess(future.getNow());
    } else {
      doResolveAllRec(inetHost, promise, resolverIndex + 1, future.cause());
    }
  }
});

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

@Override
  public void operationComplete(Future<T> future) throws Exception {
    if (future.isSuccess()) {
      promise.setSuccess(future.getNow());
    } else {
      doResolveRec(inetHost, promise, resolverIndex + 1, future.cause());
    }
  }
});

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

/**
 * Mark the underlying {@link Promise} successfully and recycle this instance.
 */
public boolean successAndRecycle() {
  if (promise != null) {
    promise.setSuccess(null);
  }
  return recycle();
}

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

@Override
  public void operationComplete(Future<T> future) throws Exception {
    if (future.isSuccess()) {
      promise.setSuccess(future.getNow());
    } else {
      doResolveRec(inetHost, promise, resolverIndex + 1, future.cause());
    }
  }
});

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

@Override
  public void operationComplete(Future<List<T>> future) throws Exception {
    if (future.isSuccess()) {
      promise.setSuccess(future.getNow());
    } else {
      doResolveAllRec(inetHost, promise, resolverIndex + 1, future.cause());
    }
  }
});

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

@Override
  public void operationComplete(Future<InetAddress> future) throws Exception {
    if (future.isSuccess()) {
      promise.setSuccess(new InetSocketAddress(future.getNow(), unresolvedAddress.getPort()));
    } else {
      promise.setFailure(future.cause());
    }
  }
});

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

@Override
  public void operationComplete(Future<List<InetAddress>> future) throws Exception {
    if (future.isSuccess()) {
      List<InetAddress> inetAddresses = future.getNow();
      List<InetSocketAddress> socketAddresses =
          new ArrayList<InetSocketAddress>(inetAddresses.size());
      for (InetAddress inetAddress : inetAddresses) {
        socketAddresses.add(new InetSocketAddress(inetAddress, unresolvedAddress.getPort()));
      }
      promise.setSuccess(socketAddresses);
    } else {
      promise.setFailure(future.cause());
    }
  }
});

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

@Override
  public void operationComplete(Future<List<InetAddress>> future) throws Exception {
    if (future.isSuccess()) {
      List<InetAddress> inetAddresses = future.getNow();
      if (!inetAddresses.isEmpty()) {
        // create a copy to make sure that it's modifiable random access collection
        List<InetAddress> result = new ArrayList<InetAddress>(inetAddresses);
        // rotate by different distance each time to force round robin distribution
        Collections.rotate(result, randomIndex(inetAddresses.size()));
        promise.setSuccess(result);
      } else {
        promise.setSuccess(inetAddresses);
      }
    } else {
      promise.setFailure(future.cause());
    }
  }
});

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

@Override
  protected void doResolveAll(String inetHost, Promise<List<InetAddress>> promise) throws Exception {
    try {
      promise.setSuccess(Arrays.asList(SocketUtils.allAddressesByName(inetHost)));
    } catch (UnknownHostException e) {
      promise.setFailure(e);
    }
  }
}

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

@Override
protected void doResolve(String inetHost, Promise<InetAddress> promise) throws Exception {
  try {
    promise.setSuccess(SocketUtils.addressByName(inetHost));
  } catch (UnknownHostException e) {
    promise.setFailure(e);
  }
}

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

@Override
  public void operationComplete(Future<List<InetAddress>> future) throws Exception {
    if (future.isSuccess()) {
      List<InetAddress> inetAddresses = future.getNow();
      int numAddresses = inetAddresses.size();
      if (numAddresses > 0) {
        // if there are multiple addresses: we shall pick one by one
        // to support the round robin distribution
        promise.setSuccess(inetAddresses.get(randomIndex(numAddresses)));
      } else {
        promise.setFailure(new UnknownHostException(inetHost));
      }
    } else {
      promise.setFailure(future.cause());
    }
  }
});

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

@Override
  protected void doResolveAll(String inetHost, Promise<List<InetAddress>> promise) throws Exception {
    try {
      promise.setSuccess(Arrays.asList(SocketUtils.allAddressesByName(inetHost)));
    } catch (UnknownHostException e) {
      promise.setFailure(e);
    }
  }
}

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

@Override
  public Future<SslContext> map(String input, Promise<SslContext> promise) {
    final SslContext context;
    try {
      context = mapping.map(input);
    } catch (Throwable cause) {
      return promise.setFailure(cause);
    }
    return promise.setSuccess(context);
  }
}

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

private void releaseAndOffer(Channel channel, Promise<Void> promise) throws Exception {
  if (offerChannel(channel)) {
    handler.channelReleased(channel);
    promise.setSuccess(null);
  } else {
    closeAndFail(channel, FULL_EXCEPTION, promise);
  }
}

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

/**
 * Adds the channel back to the pool only if the channel is healthy.
 * @param channel the channel to put back to the pool
 * @param promise offer operation promise.
 * @param future the future that contains information fif channel is healthy or not.
 * @throws Exception in case when failed to notify handler about release operation.
 */
private void releaseAndOfferIfHealthy(Channel channel, Promise<Void> promise, Future<Boolean> future)
    throws Exception {
  if (future.getNow()) { //channel turns out to be healthy, offering and releasing it.
    releaseAndOffer(channel, promise);
  } else { //channel not healthy, just releasing it.
    handler.channelReleased(channel);
    promise.setSuccess(null);
  }
}

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

private void releaseAndOffer(Channel channel, Promise<Void> promise) throws Exception {
  if (offerChannel(channel)) {
    handler.channelReleased(channel);
    promise.setSuccess(null);
  } else {
    closeAndFail(channel, FULL_EXCEPTION, promise);
  }
}

相关文章