use of io.netty.util.concurrent.GenericFutureListener in project SMSGate by Lihuanghe.
the class CmppTerminateRequestMessageHandler method channelRead0.
/*
* (non-Javadoc)
*
* @see
* org.jboss.netty.channel.SimpleChannelUpstreamHandler#messageReceived(
* org.jboss.netty.channel.ChannelHandlerContext,
* org.jboss.netty.channel.MessageEvent)
*/
@Override
public void channelRead0(final ChannelHandlerContext ctx, CmppTerminateRequestMessage e) throws Exception {
CmppTerminateResponseMessage responseMessage = new CmppTerminateResponseMessage(e.getHeader().getSequenceId());
ChannelFuture future = ctx.channel().writeAndFlush(responseMessage);
final ChannelHandlerContext finalctx = ctx;
future.addListeners(new GenericFutureListener() {
@Override
public void operationComplete(Future future) throws Exception {
ctx.executor().schedule(new Runnable() {
@Override
public void run() {
finalctx.channel().close();
}
}, 500, TimeUnit.MILLISECONDS);
}
});
}
use of io.netty.util.concurrent.GenericFutureListener in project SMSGate by Lihuanghe.
the class MessageLogHandler method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
final Object finalmsg = msg;
ctx.write(msg, promise);
promise.addListener(new GenericFutureListener() {
@Override
public void operationComplete(Future future) throws Exception {
// 如果发送消息失败,记录失败日志
if (!future.isSuccess()) {
logger.error("ErrSend:{},cause by", finalmsg, future.cause());
} else {
logger.debug("Send:{}", finalmsg);
}
}
});
}
use of io.netty.util.concurrent.GenericFutureListener in project SMSGate by Lihuanghe.
the class SMGPExitMessageHandler method channelRead0.
@Override
protected void channelRead0(final ChannelHandlerContext ctx, SMGPExitMessage msg) throws Exception {
SMGPExitRespMessage resp = new SMGPExitRespMessage();
resp.setSequenceNo(msg.getSequenceNo());
ChannelFuture future = ctx.channel().writeAndFlush(resp);
final ChannelHandlerContext finalctx = ctx;
future.addListeners(new GenericFutureListener() {
@Override
public void operationComplete(Future future) throws Exception {
ctx.executor().schedule(new Runnable() {
@Override
public void run() {
finalctx.channel().close();
}
}, 500, TimeUnit.MILLISECONDS);
}
});
}
use of io.netty.util.concurrent.GenericFutureListener in project DuoDuo by qiunet.
the class DSession method connect.
/**
* 连接
*/
private void connect() {
Preconditions.checkNotNull(connectParam);
if (!connecting.compareAndSet(false, true)) {
return;
}
GenericFutureListener<ChannelFuture> listener = f -> {
if (!f.isSuccess()) {
throw new CustomException("Tcp Connect fail!");
}
try {
sessionLock.lock();
DMessageContentFuture msg = queue.poll();
if (msg != null) {
// 第一个协议一般是鉴权协议. 先发送. 等发送成功再发送后面的协议.
IDSessionFuture future = this.doSendMessage(msg.getMessage(), true);
future.addListener(f0 -> {
if (f0.isSuccess()) {
msg.complete(f0);
DMessageContentFuture msg0;
while ((msg0 = queue.poll()) != null) {
if (msg0.isCanceled()) {
continue;
}
IDSessionFuture future1 = this.doSendMessage(msg0.getMessage(), false);
DMessageContentFuture finalMsg = msg0;
future1.addListener(f1 -> {
if (f1.isSuccess()) {
finalMsg.complete(f1);
}
});
}
}
this.flush0();
});
}
connecting.set(false);
} finally {
sessionLock.unlock();
}
};
ChannelFuture connectFuture = connectParam.connect();
connectFuture.channel().attr(ServerConstants.SESSION_KEY).set(this);
this.setChannel(connectFuture.channel());
connectFuture.addListener(listener);
}
use of io.netty.util.concurrent.GenericFutureListener in project qpid-protonj2 by apache.
the class WebSocketTransport method write.
@Override
public WebSocketTransport write(ProtonBuffer output, Runnable onComplete) throws IOException {
checkConnected();
int length = output.getReadableBytes();
if (length == 0) {
return this;
}
LOG.trace("Attempted write of: {} bytes", length);
if (onComplete == null) {
channel.write(new BinaryWebSocketFrame(toOutputBuffer(output)), channel.voidPromise());
} else {
channel.write(new BinaryWebSocketFrame(toOutputBuffer(output)), channel.newPromise().addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if (future.isSuccess()) {
onComplete.run();
}
}
}));
}
return this;
}
Aggregations