List of usage examples for io.netty.channel ChannelFutureListener ChannelFutureListener
ChannelFutureListener
From source file:lunarion.cluster.coordinator.server.TaskRedirectMessage.java
License:Open Source License
public void run() { execute(request);//from w w w . j av a 2s .com if (ctx != null) { int len = response.size(); ByteBuf response_buff = Unpooled.buffer(4 + len); response_buff.writeInt(len); response.write(response_buff); ctx.writeAndFlush(response_buff).addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture channelFuture) throws Exception { //System.out.println("[NODE INFO]: LunarNode responds the request with message id:" + request.getUUID()); } }); } }
From source file:lunarion.node.requester.LunarDBClient.java
License:Open Source License
public ChannelFuture connect(String host, int port) throws Exception { group = new NioEventLoopGroup(); client_handler = new ClientHandler(internal); try {/*from www. ja va2s. c o m*/ Bootstrap client_bootstrap = new Bootstrap(); client_bootstrap.group(group).channel(NioSocketChannel.class) .option(ChannelOption.SO_SNDBUF, 1024 * 1024) .option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(64, 1024, 65536 * 512)) //.option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_KEEPALIVE, true).handler(new ClientChannelInitializer(client_handler)); //ChannelFuture cf = client_bootstrap.connect(host, port).sync(); ChannelFuture cf = client_bootstrap.connect(host, port); channel_list.add(cf); cf.addListener(new ChannelFutureListener() { public void operationComplete(final ChannelFuture channelFuture) throws Exception { if (channelFuture.isSuccess()) { ClientHandler handler = channelFuture.channel().pipeline().get(ClientHandler.class); client_handler = handler; } } }); connected.set(true); connected_host_ip = host; connected_port = port; return cf; } finally { // group.shutdownGracefully(); } }
From source file:lunarion.node.TaskHandlingMessage.java
License:Open Source License
public void run() { response = node_tc.dispatch(request); if (ctx != null) { int len = response.size(); ByteBuf response_buff = Unpooled.buffer(4 + len); response_buff.writeInt(len);/*from w w w .jav a 2 s . c o m*/ response.write(response_buff); ctx.writeAndFlush(response_buff).addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture channelFuture) throws Exception { //System.out.println("[NODE INFO]: LunarNode responsed the request with message id:" + request.getUUID()); } }); } }
From source file:lunarion.node.TaskHandlingMessageVOld.java
License:Open Source License
public void run() { //execute(request); response = node_tc.dispatch(request); if (ctx != null) { int len = response.size(); ByteBuf response_buff = Unpooled.buffer(4 + len); response_buff.writeInt(len);/* ww w .java 2 s . co m*/ response.write(response_buff); ctx.writeAndFlush(response_buff).addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture channelFuture) throws Exception { //System.out.println("[NODE INFO]: LunarNode responsed the request with message id:" + request.getUUID()); } }); } }
From source file:me.bigteddy98.mcproxy.protocol.handlers.ClientSideHandler.java
License:Open Source License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { incomingChannel = ctx.channel();/*from w w w.ja v a2 s . c o m*/ networkManager.clientsidePipeline = ctx.pipeline(); Bootstrap bootstrab = new Bootstrap(); bootstrab.group(incomingChannel.eventLoop()); bootstrab.channel(ctx.channel().getClass()); bootstrab.handler(serverboundConnectionInitializer = new ServerboundConnectionInitializer(networkManager, incomingChannel)); bootstrab.option(ChannelOption.AUTO_READ, false); ChannelFuture f = bootstrab.connect(hostname, port); outgoingChannel = f.channel(); f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { incomingChannel.read(); } else { incomingChannel.close(); } } }); }
From source file:me.bigteddy98.mcproxy.protocol.handlers.ClientSideHandler.java
License:Open Source License
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { if (outgoingChannel.isActive()) { ByteBuf bufferOriginal = (ByteBuf) msg; ByteBuf bufferClone = Unpooled.copiedBuffer(bufferOriginal); final List<Packet> packets = this.networkManager.handleServerBoundPackets((ByteBuf) msg, bufferClone); bufferClone.release();/*w w w.ja va 2 s. c om*/ outgoingChannel.writeAndFlush(msg).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { for (Packet packet : packets) { packet.onSend(networkManager); } if (future.isSuccess()) { ctx.channel().read(); } else { future.channel().close(); } } }); } }
From source file:me.bigteddy98.mcproxy.protocol.handlers.ServerSideHandler.java
License:Open Source License
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf bufferOriginal = (ByteBuf) msg; ByteBuf bufferClone = Unpooled.copiedBuffer(bufferOriginal); final List<Packet> packets = this.networkManager.handleClientBoundPackets((ByteBuf) msg, bufferClone); bufferClone.release();// w ww. java 2s . com inboundChannel.writeAndFlush(msg).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { for (Packet packet : packets) { packet.onSend(networkManager); } if (future.isSuccess()) { ctx.channel().read(); } else { future.channel().close(); } } }); }
From source file:me.bigteddy98.movingmotd.ClientSideConnection.java
License:Open Source License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { this.networkManager.incomingChannel = ctx.channel(); this.networkManager.clientsidePipeline = ctx.pipeline(); Bootstrap bootstrab = new Bootstrap(); bootstrab.group(networkManager.incomingChannel.eventLoop()); bootstrab.channel(ctx.channel().getClass()); bootstrab.handler(new ServerSideConnectionInitialization(networkManager)); bootstrab.option(ChannelOption.AUTO_READ, false); ChannelFuture f = bootstrab.connect(this.toHostname, this.toPort); f.addListener(new ChannelFutureListener() { @Override/*from www. j a va 2 s .com*/ public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { networkManager.incomingChannel.read(); } else { networkManager.incomingChannel.close(); } } }); this.outgoingChannel = f.channel(); }
From source file:me.bigteddy98.movingmotd.ClientSideConnection.java
License:Open Source License
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf clonedBuf = Unpooled.copiedBuffer((ByteBuf) msg); ByteBuf originalBuf = (ByteBuf) msg; int packetSize = PacketUtils.readVarInt(originalBuf); if (originalBuf.readableBytes() < packetSize) { System.out.println("Packet was smaller than the lenght."); }//from www . j a v a 2 s. com int id = PacketUtils.readVarInt(originalBuf); if (this.stage == Stage.HANDSHAKE) { if (id != 0x00) { System.out.println("Handshake ID was not equal to 0x00."); } // followed by varint, string, unsigned short and another varint PacketUtils.readVarInt(originalBuf); PacketUtils.readString(originalBuf); originalBuf.readUnsignedShort(); int nextStage = PacketUtils.readVarInt(originalBuf); this.stage = Stage.fromId(nextStage); } else if (this.stage == Stage.LOGIN) { // just sent it } else if (this.stage == Stage.STATUS) { // TODO someone is pinging! originalBuf.release(); return; } originalBuf.release(); this.outgoingChannel.writeAndFlush(clonedBuf).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { ctx.channel().read(); } else { future.channel().close(); } } }); }
From source file:me.bigteddy98.movingmotd.ServerSideConnection.java
License:Open Source License
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { this.incomingChannel.writeAndFlush(msg).addListener(new ChannelFutureListener() { @Override//from w ww. ja v a 2s. c o m public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { ctx.channel().read(); } else { future.channel().close(); } } }); }