List of usage examples for io.netty.channel ChannelFutureListener CLOSE
ChannelFutureListener CLOSE
To view the source code for io.netty.channel ChannelFutureListener CLOSE.
Click Source Link
From source file:com.cats.version.httpserver.HttpStaticFileServerHandler.java
License:Apache License
private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) { FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, status, Unpooled.copiedBuffer("Failure: " + status + "\r\n", CharsetUtil.UTF_8)); response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8"); // Close the connection as soon as the error message is sent. ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); }
From source file:com.cats.version.httpserver.HttpStaticFileServerHandler.java
License:Apache License
public static void sendWarningInfo(ChannelHandlerContext ctx) { FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK); response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8"); StringBuffer buf = new StringBuffer(); buf.append("<!DOCTYPE html>\r\n<html>"); buf.append("<br/><br/><br/><br/><br/><br/>"); buf.append("<center><font size='5px'>"); buf.append(// w ww.j a va 2 s. co m "Access denied, because this is version monitor service server</br></br> CTAS@Intel 2016~2026 All rights reserved"); buf.append("</font></center>"); buf.append("<html>"); ByteBuf buffer = Unpooled.copiedBuffer(buf, CharsetUtil.UTF_8); response.content().writeBytes(buffer); buffer.release(); // Close the connection as soon as the error message is sent. ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); }
From source file:com.cats.version.httpserver.msg.IMsgHandler.java
License:Apache License
public void sendMessageToClient(String strRsp, ChannelHandlerContext ctx) { if (null == strRsp) { return;//w w w . j a v a2 s . c om } FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK); response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8"); ByteBuf buffer = Unpooled.copiedBuffer(strRsp, CharsetUtil.UTF_8); response.content().writeBytes(buffer); buffer.release(); // Close the connection as soon as the error message is sent. ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); }
From source file:com.chen.opensourceframework.netty.copy.DiscardServerHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ChannelFuture f = ctx.writeAndFlush(new UnixTime()); f.addListener(ChannelFutureListener.CLOSE); }
From source file:com.chenyang.proxy.http.HttpRelayHandler.java
License:Apache License
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { if (relayChannel != null && relayChannel.isActive()) { relayChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); }// w w w . j a v a 2s . c om ctx.fireChannelInactive(); }
From source file:com.chenyang.proxy.http.HttpUserAgentTunnelHandler.java
License:Apache License
@Override public void channelRead(final ChannelHandlerContext uaChannelCtx, Object msg) throws Exception { if (msg instanceof HttpRequest) { // Channel uaChannel = uaChannelCtx.channel(); // connect remote Bootstrap bootstrap = new Bootstrap(); bootstrap.group(uaChannelCtx.channel().eventLoop()).channel(NioSocketChannel.class) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.AUTO_READ, false) .handler(new HttpTunnelChannelInitializer(uaChannelCtx.channel())); final HttpRemote apnProxyRemote = uaChannelCtx.channel().attr(HttpConnectionAttribute.ATTRIBUTE_KEY) .get().getRemote();//w w w . j av a2s . c o m bootstrap .connect(apnProxyRemote.getInetSocketAddress(), new InetSocketAddress(NetworkUtils.getCyclicLocalIp().getHostAddress(), 0)) .addListener(new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture future1) throws Exception { if (future1.isSuccess()) { HttpResponse proxyConnectSuccessResponse = new DefaultFullHttpResponse( HttpVersion.HTTP_1_1, new HttpResponseStatus(200, "Connection established")); uaChannelCtx.writeAndFlush(proxyConnectSuccessResponse) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future2) throws Exception { // remove handlers uaChannelCtx.pipeline().remove("codec"); uaChannelCtx.pipeline().remove(HttpPreHandler.HANDLER_NAME); uaChannelCtx.pipeline() .remove(HttpUserAgentTunnelHandler.HANDLER_NAME); uaChannelCtx.pipeline() .addLast(new HttpRelayHandler( "UA --> " + apnProxyRemote.getRemoteAddr(), future1.channel())); } }); } else { if (uaChannelCtx.channel().isActive()) { uaChannelCtx.channel().writeAndFlush(Unpooled.EMPTY_BUFFER) .addListener(ChannelFutureListener.CLOSE); } } } }); } ReferenceCountUtil.release(msg); }
From source file:com.chiorichan.http.HttpResponseWrapper.java
License:Mozilla Public License
public void finishMultipart() throws IOException { if (stage == HttpResponseStage.CLOSED) throw new IllegalStateException( "You can't access closeMultipart unless you start MULTIPART with sendMultipart."); stage = HttpResponseStage.CLOSED;/*from ww w .j av a 2 s . c om*/ // Write the end marker ChannelFuture lastContentFuture = request.getChannel().writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); // Decide whether to close the connection or not. // if ( !isKeepAlive( request ) ) { // Close the connection when the whole content is written out. lastContentFuture.addListener(ChannelFutureListener.CLOSE); } }
From source file:com.chiorichan.net.query.QueryServerHandler.java
License:Mozilla Public License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { context = ctx;//from www. j a v a2 s.c om persistence = new NetworkPersistence(this); console = InteractiveConsole.createInstance(this, persistence); console.displayWelcomeMessage(); QueryEvent queryEvent = new QueryEvent(ctx, QueryType.CONNECTED, null); try { Loader.getEventBus().callEventWithException(queryEvent); } catch (EventException ex) { throw new IOException( "Exception encountered during query event call, most likely the fault of a plugin.", ex); } if (queryEvent.isCancelled()) { ChannelFuture future = ctx.write(parseColor((queryEvent.getReason().isEmpty()) ? "We're sorry, you've been disconnected from the server by a Cancelled Event." : queryEvent.getReason())); future.addListener(ChannelFutureListener.CLOSE); ctx.flush(); return; } console.resetPrompt(); }
From source file:com.chiorichan.net.query.QueryServerHandler.java
License:Mozilla Public License
public void disconnect(String msg) { ChannelFuture future = context.write(parseColor(msg)); future.addListener(ChannelFutureListener.CLOSE); }
From source file:com.chiorichan.net.query.QueryServerTerminal.java
License:Mozilla Public License
public boolean disconnect(String msg) { NetworkManager.getLogger().info(EnumColor.YELLOW + "The connection to Query Client `" + getIpAddr() + "` is being disconnected with message `" + msg + "`."); ChannelFuture future = context.writeAndFlush("\r" + parseColor(msg) + "\r\n"); future.addListener(ChannelFutureListener.CLOSE); return true;//from www . j a va 2s . c o m }