本文整理汇总了Java中io.netty.channel.ChannelFuture.isSuccess方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelFuture.isSuccess方法的具体用法?Java ChannelFuture.isSuccess怎么用?Java ChannelFuture.isSuccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.ChannelFuture
的用法示例。
在下文中一共展示了ChannelFuture.isSuccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture cf) throws Exception {
if (!cf.isSuccess()) {
synchronized (connections) {
NodeConnection c = connections.remove(node.getNodeId());
if (c != null) c.nuke();
cf.channel().close();
}
String message = "[unknown error]";
if (cf.isCancelled()) message = "Timed out on connect";
if (cf.cause() != null) message = cf.cause().getMessage();
logger.debug("[{}->{}] Could not connect to RPC " +
"node: {}",
new Object[]{syncManager.getLocalNodeId(),
node.getNodeId(),
message});
} else {
logger.trace("[{}->{}] Channel future successful",
syncManager.getLocalNodeId(),
node.getNodeId());
}
}
示例2: reply
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
/**
* 通知消息
*
* @param channel
* @param socketMessage
*/
static void reply(Channel channel, SocketMessage socketMessage) {
ChannelFuture future = channel.writeAndFlush(socketMessage);
if (future.isSuccess()) {
// 成功
} else if (future.cause() != null) {
// FIXME: 2017/8/8 全部转换为领域模型
// 异常
LOGGER.error("{}", future.cause());
} else {
// 取消
// throw new Exception("客户端取消执行");
LOGGER.error("Client cancel receive message.");
}
}
示例3: 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;
}
示例4: write
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public ProtocolFuture write(byte[] data) {
this.lastActive = System.currentTimeMillis();
if (!isClosed()) {
ChannelFuture future = channel.write(data);
return new ProtocolFuture() {
@Override
public boolean isSuccess() {
return future.isSuccess();
}
@Override
public boolean isDone() {
return future.isDone();
}
};
} else {
return ProtocolFuture.ERRORFUTURE;
}
}
示例5: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (!channelFuture.isSuccess()) {
channelFuture.channel().close();
if (count.incrementAndGet() < MAX_RETRY) {
final EventLoop loop = channelFuture.channel().eventLoop();
loop.schedule(() -> {
controller.connectRetry(this.ip, this.port, this);
}, 1L, TimeUnit.SECONDS);
} else {
log.info("Connection to the ovsdb {}:{} failed",
this.ip.toString(), this.port.toString());
}
} else {
handleNewNodeConnection(channelFuture.channel());
}
}
示例6: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture f) throws Exception {
final long et = System.nanoTime() - mark;
if (!f.isSuccess()) {
if (configuration.isAutoReconnect())
reconnect(configuration.getReconnectInterval(), future, host, port);
else {
logger.debug("failed to connected to host: " + host + ", port: " + port + ", elapsed createTime: " + NANOSECONDS.toMillis(et) + " ms");
future.failure(f.cause());
}
} else {
transport.setChannel(f.channel());
future.success(null);
logger.debug("connected to host: " + host + ", port: " + port + ", elapsed createTime: " + NANOSECONDS.toMillis(et) + " ms");
}
}
示例7: 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;
}
示例8: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isDone() && future.isSuccess()) {
set(new NettyRpcChannel(future.channel()));
} else if (future.isDone() && future.cause() != null) {
setException(future.cause());
} else if (future.isDone() && future.isCancelled()) {
cancel(false);
}
}
示例9: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) {
if (!future.isSuccess()) {
Throwable ex = future.cause();
if(ex == null){
sendFailure(new UserRpcException(null, "Unknown failure when sending message.", null));
} else {
sendFailure(new UserRpcException(null, "Failure when sending message.", ex));
}
}
}
示例10: messageSent
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
private void messageSent(ChannelHandlerContext context, ChannelFuture future, RequestHandler requestHandler)
{
try {
if (!future.isSuccess()) {
onError(context, new TTransportException("Sending request failed", future.cause()));
return;
}
requestHandler.onRequestSent();
}
catch (Throwable t) {
onError(context, t);
}
}
示例11: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) throws Exception {
connectComplete = true;
if (future.isSuccess()) {
if (future.channel().isOpen()) {
if (trace) {
log.trace("Channel connect future completed successfully [to={}]", id);
}
} else {
// Channel was disconnect()'ed while we were connecting.
becomeDisconnected();
}
} else if (firstError == null) {
if (trace) {
log.trace("Notifying on connect future failure [to={}]", id, future.cause());
}
firstError = NettyErrorUtils.unwrap(future.cause());
ChannelPipeline pipeline = future.channel().pipeline();
if (pipeline.names().contains(NettyClientStateHandler.class.getName())) {
pipeline.fireExceptionCaught(firstError);
} else {
becomeDisconnected();
}
}
}
示例12: sendResponse
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
default void sendResponse(ChannelHandlerContext ctx, Object msg) {
ChannelFuture f = ctx.writeAndFlush(msg);
LOG.trace(Constants.LOG_RETURNING_RESPONSE, msg);
if (!f.isSuccess()) {
LOG.error(Constants.ERR_WRITING_RESPONSE, f.cause());
}
}
示例13: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) {
if (future.isSuccess()) {
log.info("Successfully connected with remote server ...");
inbound.read();
} else {
log.error("Failed establishing connection with remote server ...");
inbound.close();
}
}
示例14: open
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
/**
* Opens the connection to the given serial port.
*
* @param address The serial port, must not be null.
* @throws IOException if opening of the channel fails.
*/
public void open(RxtxDeviceAddress address) throws IOException {
requireNonNull(address);
lock.lock();
try {
checkIfChannelIsClose();
Log.debug(SERIAL, "Opening channel at serial port '" + address.value() + "'.");
ChannelFuture future = bootstrap.connect(address).syncUninterruptibly();
if (!future.isSuccess()) {
fireOnError();
throw new IOException("Serial channel couldn't be opened!");
}
Log.debug(SERIAL, "Serial channel was successfully opened.");
currentChannel = future.channel();
} catch (Exception e) {
throw new IOException("Can not connect to '"+address.value()+"'!", e);
} finally {
lock.unlock();
}
}
示例15: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public void operationComplete(ChannelFuture future) {
if (!future.isSuccess()) {
future.channel().close();
}
}