List of usage examples for io.netty.channel.socket SocketChannel id
ChannelId id();
From source file:com.heliosapm.tsdblite.Server.java
License:Apache License
/** * {@inheritDoc}//from w w w . ja v a 2s . c o m * @see io.netty.channel.ChannelInitializer#initChannel(io.netty.channel.Channel) */ @Override protected void initChannel(final SocketChannel ch) throws Exception { createdChannels.increment(); channelGroup.add(ch); ch.closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() { @Override public void operationComplete(Future<? super Void> future) throws Exception { log.info( "\n\t==============================\n\tChannel Closed [{}]\n\t==============================", ch.id()); // log.error("Close Back trace", new Exception()); // if(future.cause()!=null) { // log.error("Close fail", future.cause()); // } } }); ch.pipeline().addLast("IdleState", new IdleStateHandler(0, 0, 60)); ch.pipeline().addLast("ProtocolSwitch", new ProtocolSwitch()); }
From source file:de.felix_klauke.pegasus.client.network.NettyClientChannelHandler.java
License:Apache License
/** * Netty will call this method whenever a new Channel has to get initialized. * The ChannelPipeline will be filled in this Method. Basically with this structure: * <p>//from w ww .ja va 2s .c o m * <ol> * <li>{@link de.felix_klauke.pegasus.protocol.encoder.PacketEncoder}</li> * <li>{@link de.felix_klauke.pegasus.protocol.decoder.PacketDecoder}</li> * <li>{@link de.felix_klauke.pegasus.client.handler.PacketHandler}</li> * </ol> * <p> * In a future Version a two new Elements will be added. Especially: * The {@link io.netty.handler.codec.LengthFieldPrepender} and * {@link io.netty.handler.codec.LengthFieldBasedFrameDecoder} to ensure all data is * received before the decoding starts. * * @param socketChannel the cocketChannel that is getting initialized * @throws Exception will be thrown when an error occured during creating the pipeline. */ @Override protected void initChannel(SocketChannel socketChannel) throws Exception { logger.info("A new Channel has been initialized.\n" + "Channel: " + socketChannel.id().asShortText()); logger.info("Preparing a new Channelpipeline."); socketChannel.pipeline().addLast(new PacketEncoder(), new PacketDecoder(), packetHandler); logger.info("Channelpipeline has been created."); }
From source file:me.hrps.rp.preview.chat.service.WebSocketServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { System.out.println(ch.id()); ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new WebSocketServerCompressionHandler()); pipeline.addLast((WebSocketServerHandler) SpringContextHolder.getBean("chatHandler")); verifyChannel(ch);/*from w w w. j a va 2 s .com*/ }
From source file:me.hrps.rp.preview.chat.service.WebSocketServerInitializer.java
License:Apache License
/** * ?channel,channel//w w w.jav a2 s.com */ public void verifyChannel(SocketChannel ch) { for (Map.Entry<String, Channel> channel : chs.entrySet()) { Channel chn = channel.getValue(); String id = channel.getKey(); if (!chn.isActive()) { chs.remove(id); mds.remove(id); } else { //? chn.writeAndFlush(new TextWebSocketFrame("{\"name\":\"json\"}")); } } chs.put(ch.id().toString(), ch); }
From source file:srebrinb.messagebroker.websocket.WebSocketServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); }//w w w . jav a2s .co m pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new WebSocketServerCompressionHandler()); pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true)); // pipeline.addLast(new UtsHeadersChannelHandler()); pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH)); pipeline.addLast(new WebSocketFrameHandler()); allChannels.add(ch.read()); String shortID = ch.id().asShortText(); System.out.println(shortID); ch.read().writeAndFlush(new TextWebSocketFrame("Hello " + shortID)); }