本文整理汇总了Java中io.netty.channel.ChannelFuture.cause方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelFuture.cause方法的具体用法?Java ChannelFuture.cause怎么用?Java ChannelFuture.cause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.ChannelFuture
的用法示例。
在下文中一共展示了ChannelFuture.cause方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void start() throws EmbeddedServletContainerException {
ServerBootstrap b = new ServerBootstrap();
groups(b);
servletExecutor = new DefaultEventExecutorGroup(50);
b.childHandler(new NettyEmbeddedServletInitializer(servletExecutor, context));
// Don't yet need the complexity of lifecycle state, listeners etc, so tell the context it's initialised here
context.setInitialised(true);
ChannelFuture future = b.bind(address).awaitUninterruptibly();
//noinspection ThrowableResultOfMethodCallIgnored
Throwable cause = future.cause();
if (null != cause) {
throw new EmbeddedServletContainerException("Could not start Netty server", cause);
}
logger.info(context.getServerInfo() + " started on port: " + getPort());
}
示例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: sendResponse
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public void sendResponse(ChannelHandlerContext ctx, ServiceResponse<?> resObj, int timeout)
throws JsonGenerationException, JsonMappingException, IOException {
StringWriter writer = new StringWriter();
this.objectMapper.writeValue(writer, resObj);
writer.write(Constants.PROTOCOL_REQUEST_DELIMITER);
ChannelFuture future = ctx.writeAndFlush(writer.toString());
try {
boolean success = future.await(timeout, TimeUnit.MILLISECONDS);
if (future.cause() != null) {
throw new NettoIOException("error response error ", future.cause());
} else if (!success) {
throw new NettoIOException("response error timeout");
}
} catch (InterruptedException e) {
throw new RemoteAccessException("await Interrupted", e);
} finally {
}
}
示例4: requestData
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public void requestData(String data) {
if (ctx != null) {
try {
ChannelFuture f = ctx.writeAndFlush(Unpooled.copiedBuffer(data, CharsetUtil.UTF_8)).sync();
if (!f.isSuccess())
try {
throw f.cause();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
示例5: channelRead
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ByteBuf in = (ByteBuf) msg;
String sentData = in.toString(CharsetUtil.UTF_8);
String returnee = sentData + "-::=::-" + "{}";
RequestProcessor reprocessor = EchoServer.process(sentData);
if (reprocessor != null)
returnee = sentData + "-::=::-" + reprocessor.getProcessedData();
ChannelFuture f = ctx.writeAndFlush(Unpooled.copiedBuffer(returnee, CharsetUtil.UTF_8)).sync();
if (!f.isSuccess())
try {
throw f.cause();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
示例6: 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());
}
}
示例7: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
removeFromMap(coordinationId);
if (future.channel().isActive()) {
if(future.cause() != null){
setException(future.cause());
} else {
setException(new RpcException("Unknown failure when sending message."));
}
} else {
setException(new ChannelClosedException());
}
}
}
示例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) throws Exception {
final String msg = String.format("[%s]: Channel closed %s", rpcConfig.getName(), clientConnection.getName());
final ChannelClosedException ex = future.cause() != null ? new ChannelClosedException(msg, future.cause()) : new ChannelClosedException(msg);
logger.info(msg);
clientConnection.channelClosed(ex);
}
示例10: operationComplete
import io.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
AsyncCall call = rpcChannel.removePendingCall(id);
if (call != null) {
if (future.cause() instanceof IOException) {
call.setFailed((IOException) future.cause());
} else {
call.setFailed(new IOException(future.cause()));
}
}
}
}