本文整理汇总了Java中io.netty.channel.ChannelFuture.awaitUninterruptibly方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelFuture.awaitUninterruptibly方法的具体用法?Java ChannelFuture.awaitUninterruptibly怎么用?Java ChannelFuture.awaitUninterruptibly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.ChannelFuture
的用法示例。
在下文中一共展示了ChannelFuture.awaitUninterruptibly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bootstrap
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public boolean bootstrap(HostAndPort seed,
Node localNode) throws SyncException {
this.localNode = localNode;
succeeded = false;
SocketAddress sa =
new InetSocketAddress(seed.getHostText(), seed.getPort());
ChannelFuture future = bootstrap.connect(sa);
future.awaitUninterruptibly();
if (!future.isSuccess()) {
logger.debug("Could not connect to " + seed, future.cause());
return false;
}
Channel channel = future.channel();
logger.debug("[{}] Connected to {}",
localNode != null ? localNode.getNodeId() : null,
seed);
try {
channel.closeFuture().await();
} catch (InterruptedException e) {
logger.debug("Interrupted while waiting for bootstrap");
return succeeded;
}
return succeeded;
}
示例2: connect
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
protected boolean connect(String hostname, int port) {
ready = false;
if (channel == null || !channel.isActive()) {
SocketAddress sa =
new InetSocketAddress(hostname, port);
ChannelFuture future = clientBootstrap.connect(sa);
future.awaitUninterruptibly();
if (!future.isSuccess()) {
logger.error("Could not connect to " + hostname +
":" + port, future.cause());
return false;
}
channel = future.channel();
}
while (!ready && channel != null && channel.isActive()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) { }
}
if (!ready || channel == null || !channel.isActive()) {
logger.warn("Timed out connecting to {}:{}", hostname, port);
return false;
}
logger.debug("Connected to {}:{}", hostname, port);
return true;
}