List of usage examples for io.netty.handler.codec.protobuf ProtobufDecoder ProtobufDecoder
public ProtobufDecoder(MessageLite prototype)
From source file:WorldClockClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline();/* ww w .j a v a 2 s . com*/ p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder()); p.addLast("protobufDecoder", new ProtobufDecoder(NetworkMessage.PackageInformation.getDefaultInstance())); p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender()); p.addLast("protobufEncoder", new ProtobufEncoder()); p.addLast("handler", new WorldClockClientHandler()); }
From source file:WorldClockServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline();/*from w ww. j av a2 s. c om*/ p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder()); p.addLast("protobufDecoder", new ProtobufDecoder(NetworkMessage.PackageInformation.getDefaultInstance())); p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender()); p.addLast("protobufEncoder", new ProtobufEncoder()); p.addLast("handler", new WorldClockServerHandler()); }
From source file:books.netty.codec.protobuf.SubReqClient.java
License:Apache License
public void connect(int port, String host) throws Exception { // ?NIO//from www . j a v a 2 s .c o m EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { ch.pipeline().addLast(new ProtobufVarint32FrameDecoder()); ch.pipeline().addLast( new ProtobufDecoder(SubscribeRespProto.SubscribeResp.getDefaultInstance())); ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender()); ch.pipeline().addLast(new ProtobufEncoder()); ch.pipeline().addLast(new SubReqClientHandler()); } }); // ?? ChannelFuture f = b.connect(host, port).sync(); // f.channel().closeFuture().sync(); } finally { // NIO group.shutdownGracefully(); } }
From source file:books.netty.codec.protobuf.SubReqServer.java
License:Apache License
public void bind(int port) throws Exception { // ??NIO/*from w w w . j av a2s. co m*/ EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { ch.pipeline().addLast(new ProtobufVarint32FrameDecoder()); ch.pipeline().addLast( new ProtobufDecoder(SubscribeReqProto.SubscribeReq.getDefaultInstance())); ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender()); ch.pipeline().addLast(new ProtobufEncoder()); ch.pipeline().addLast(new SubReqServerHandler()); } }); // ??? ChannelFuture f = b.bind(port).sync(); // ??? f.channel().closeFuture().sync(); } finally { // ? bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:bridgempp.bot.wrapper.BotWrapper.java
private static void botInitialize(File botConfig) { try {// w w w . ja v a 2s .c o m Properties botProperties = new Properties(); if (!botConfig.exists()) { botConfig.createNewFile(); } botProperties.load(new FileInputStream(botConfig)); String botClass = botProperties.getProperty("botClass"); if (botClass == null) { writeDefaultConfig(botProperties); throw new UnsupportedOperationException( "Bot Class is null, cannot execute BridgeMPP server commands"); } Bot bot = (Bot) Class.forName(botClass).newInstance(); bot.initializeBot(); String serverAddress = botProperties.getProperty("serverAddress"); int portNumber = Integer.parseInt(botProperties.getProperty("serverPort")); if (serverAddress == null) { writeDefaultConfig(botProperties); throw new UnsupportedOperationException( "Server Address is null, cannot execute BridgeMPP server commands"); } ChannelFuture channelFuture = bootstrap.connect(new InetSocketAddress(serverAddress, portNumber)); byte[] protocol = new byte[1]; protocol[0] = 0x32; channelFuture.await(); channelFuture.channel().writeAndFlush(Unpooled.wrappedBuffer(protocol)); channelFuture.channel().pipeline().addLast("frameDecoder", new ProtobufVarint32FrameDecoder()); channelFuture.channel().pipeline().addLast("protobufDecoder", new ProtobufDecoder(ProtoBuf.Message.getDefaultInstance())); channelFuture.channel().pipeline().addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender()); channelFuture.channel().pipeline().addLast("protobufEncoder", new ProtobufEncoder()); channelFuture.channel().pipeline().addLast(new IncommingMessageHandler(bot)); bot.channelFuture = channelFuture; bot.setProperties(botProperties); String serverKey = botProperties.getProperty("serverKey"); if (serverKey == null) { writeDefaultConfig(botProperties); throw new UnsupportedOperationException( "Server Key is null, cannot execute BridgeMPP server commands"); } printCommand("!usekey " + serverKey, bot); String botAlias = botProperties.getProperty("botname"); if (botAlias != null) { printCommand("!createalias " + botAlias, bot); } bot.name = botAlias; String[] groups = botProperties.getProperty("groups").split("; "); for (int i = 0; i < groups.length; i++) { printCommand("!subscribegroup " + groups[i], bot); } System.out.println("Joined " + groups.length + " groups"); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | InterruptedException ex) { Logger.getLogger(BotWrapper.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:club.jmint.crossing.client.ClientChannelInitializer.java
License:Apache License
@Override protected void initChannel(SocketChannel ch) throws Exception { // TODO Auto-generated method stub ChannelPipeline p = ch.pipeline();//from ww w .ja v a 2s . co m if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new ProtobufVarint32FrameDecoder()); p.addLast(new ProtobufDecoder(CrossingRespProto.CrossingResp.getDefaultInstance())); p.addLast(new ProtobufVarint32LengthFieldPrepender()); p.addLast(new ProtobufEncoder()); p.addLast(handler); }
From source file:club.jmint.crossing.server.ServerChannelInitializer.java
License:Apache License
@Override protected void initChannel(SocketChannel ch) throws Exception { // TODO Auto-generated method stub ChannelPipeline p = ch.pipeline();/*ww w. j av a 2 s . c o m*/ if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new ProtobufVarint32FrameDecoder()); p.addLast(new ProtobufDecoder(CrossingReqProto.CrossingReq.getDefaultInstance())); p.addLast(new ProtobufVarint32LengthFieldPrepender()); p.addLast(new ProtobufEncoder()); p.addLast(new ServerHandler()); }
From source file:com.bdtools.doxecute.WorldClockClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline();//from w w w . jav a 2 s . c om p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder()); p.addLast("protobufDecoder", new ProtobufDecoder(WorldClockProtocol.LocalTimes.getDefaultInstance())); p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender()); p.addLast("protobufEncoder", new ProtobufEncoder()); p.addLast("handler", new WorldClockClientHandler()); }
From source file:com.bdtools.doxecute.WorldClockServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline();/*from w w w . ja v a2 s . co m*/ p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder()); p.addLast("protobufDecoder", new ProtobufDecoder(WorldClockProtocol.Locations.getDefaultInstance())); p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender()); p.addLast("protobufEncoder", new ProtobufEncoder()); p.addLast("handler", new WorldClockServerHandler()); }
From source file:com.changxx.phei.netty.codec.protobuf.SubReqClient.java
License:Apache License
public void connect(int port, String host) throws Exception { // ?NIO//from www. j a v a 2 s. c o m EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ProtobufVarint32FrameDecoder()); ch.pipeline().addLast( new ProtobufDecoder(SubscribeRespProto.SubscribeResp.getDefaultInstance())); ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender()); ch.pipeline().addLast(new ProtobufEncoder()); ch.pipeline().addLast(new SubReqClientHandler()); } }); // ?? ChannelFuture f = b.connect(host, port).sync(); // f.channel().closeFuture().sync(); } finally { // NIO group.shutdownGracefully(); } }