• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ByteArrayEncoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.netty.handler.codec.bytes.ByteArrayEncoder的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayEncoder类的具体用法?Java ByteArrayEncoder怎么用?Java ByteArrayEncoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ByteArrayEncoder类属于io.netty.handler.codec.bytes包,在下文中一共展示了ByteArrayEncoder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: start

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
public void start() throws Exception {
	EventLoopGroup group = new NioEventLoopGroup();
	try {
		Bootstrap b = new Bootstrap();
		b.group(group)
				.channel(NioSocketChannel.class)
				.remoteAddress(new InetSocketAddress(this.host, this.port))
				.handler(new ChannelInitializer<SocketChannel>() {
					@Override
					protected void initChannel(SocketChannel ch) throws Exception {
						System.out.println("connected server...");
						ch.pipeline().addLast(new ByteArrayEncoder());
						ch.pipeline().addLast(new ByteArrayDecoder());
						ch.pipeline().addLast(new EchoClientHandler());
					}
				});

		ChannelFuture cf = b.connect().sync();

		cf.channel().closeFuture().sync();
	} finally {
		group.shutdownGracefully().sync();
	}
}
 
开发者ID:Him188,项目名称:JPRE,代码行数:25,代码来源:TestClient.java


示例2: initChannel

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
  final ChannelPipeline p = ch.pipeline();

  final UUID uuid = UUID.randomUUID();

  LOG.debug("KaaTcpServerInitializer Initializing Channel {} connection from {}:{}",
          uuid, ch.remoteAddress().getAddress().toString(), ch.remoteAddress().getPort());

  Attribute<UUID> uuidAttr = ch.attr(AbstractNettyServer.UUID_KEY);
  uuidAttr.set(uuid);

  p.addLast("binaryDecoder", new ByteArrayDecoder());
  p.addLast("kaaTcpDecoder", getDecoder());
  p.addLast("binaryEncoder", new ByteArrayEncoder());
  p.addLast("kaaTcpEncoder", new KaaTcpEncoder());
  p.addLast("mainHandler", getMainHandler(uuid));
  p.addLast("kaaTcpExceptionHandler", new KaaTcpExceptionHandler());
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:20,代码来源:AbstractKaaTcpServerInitializer.java


示例3: start

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
@Override
public synchronized void start() {
    bossGroup = new NioEventLoopGroup(); // (1)
    workerGroup = new NioEventLoopGroup();
    try {
        b = new ServerBootstrap(); // (2)
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class) // (3)
                .childHandler(new ChannelInitializer<SocketChannel>() { // (4)
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {

                        ch.pipeline().addLast(new ByteArrayDecoder());
                        ch.pipeline().addLast(new ByteArrayEncoder());

                        ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));

                        ch.pipeline().addLast(new IdleStateHandler(heartTime, heartTime, heartTime, TimeUnit.SECONDS));

                        ch.pipeline().addLast(new DeliveryHandler(deliveryService));

                    }
                })
                .option(ChannelOption.SO_BACKLOG, 128)          // (5)
                .childOption(ChannelOption.SO_KEEPALIVE, true); // (6)

        // Bind and start to accept incoming connections.
        b.bind(settingService.getDeliveryPort());

        logger.info("socket: "+settingService.getDeliveryPort()+" starting....");
        // Wait until the server socket is closed.
        // In this example, this does not happen, but you can do that to gracefully
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:1991wangliang,项目名称:sds,代码行数:37,代码来源:NettyServerServiceImpl.java


示例4: newByteArrayEncoder

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
public static ChannelHandlerFactory newByteArrayEncoder(String protocol) {
    if ("udp".equals(protocol)) {
        return new ShareableChannelHandlerFactory(new DatagramPacketByteArrayEncoder());
    } else {
        return new ShareableChannelHandlerFactory(new ByteArrayEncoder());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:ChannelHandlerFactories.java


示例5: open

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
public void open(EventLoopGroup eventLoopGroup) throws Exception {
	if (openned.compareAndSet(false, true)) {
		eventloopGroop = eventLoopGroup == null ? new NioEventLoopGroup()
				: eventLoopGroup;
		Bootstrap bootstrap = new Bootstrap();
		final BlockingByteArrayClientHandler handler = new BlockingByteArrayClientHandler(
				this);
		this.clientHandler = handler;
		bootstrap.group(eventloopGroop).channel(NioSocketChannel.class)
				.handler(new ChannelInitializer<SocketChannel>() {
					@Override
					protected void initChannel(SocketChannel ch)
							throws Exception {
						ChannelPipeline pipeline = ch.pipeline();
						SSLEngine engine = SecureSocketSslContextFactory
								.getClientContext().createSSLEngine();
						engine.setUseClientMode(true);
						pipeline.addLast("ssl", new SslHandler(engine));
						pipeline.addLast("length-decoder",
								new LengthFieldBasedFrameDecoder(
										Integer.MAX_VALUE, 0, 4, 0, 4));
						pipeline.addLast("bytearray-decoder",
								new ByteArrayDecoder());
						pipeline.addLast("length-encoder",
								new LengthFieldPrepender(4));
						pipeline.addLast("bytearray-encoder",
								new ByteArrayEncoder());
						pipeline.addLast("handler", handler);
					}

				});
		channelFuture = bootstrap.connect(this.remoteHost, this.remotePort)
				.sync();
	}
}
 
开发者ID:devsunny,项目名称:netty-ssl-example,代码行数:36,代码来源:NettySocketClient.java


示例6: initChannel

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    SSLEngine engine =
        SecureSocketSslContextFactory.getServerContext().createSSLEngine();
    engine.setUseClientMode(false);
    pipeline.addLast("ssl", new SslHandler(engine));  
    pipeline.addLast("length-decoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4)); 
    pipeline.addLast("bytearray-decoder", new ByteArrayDecoder());
    pipeline.addLast("length-encoder", new LengthFieldPrepender(4));  
    pipeline.addLast("bytearray-encoder", new ByteArrayEncoder());
    pipeline.addLast("handler", new SecureSocketServerhandler2());
}
 
开发者ID:devsunny,项目名称:netty-ssl-example,代码行数:14,代码来源:SecureSocketServerLengthFrameInitializer.java


示例7: GossipServerThread

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
public GossipServerThread() {
    gossipBossGroup = new NioEventLoopGroup(GOSSIP_BOSS_THREADS);
    gossipWorkerGroup = new NioEventLoopGroup(GOSSIP_WORKER_THREADS);
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(gossipBossGroup, gossipWorkerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.config().setAllocator(UnpooledByteBufAllocator.DEFAULT);
                        ch.pipeline().addLast(new GossipMessageDecoder());
                        ch.pipeline().addLast("encoder", new ByteArrayEncoder());
                        ch.pipeline().addLast("decoder", new ByteArrayDecoder());
                        ch.pipeline().addLast(new GossipMessageHandler());
                        if(LOG.isTraceEnabled()) {
                            ch.pipeline().addLast(new LoggingHandler(LogLevel.TRACE));
                        }
                    }

                    @Override
                    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
                        LOG.error("Cannot initialize gossip server.", cause);
                    }
                })
                .option(ChannelOption.SO_BACKLOG, 128)
                .childOption(ChannelOption.SO_KEEPALIVE, true);

        // Bind and start to accept incoming connections.
        f = b.bind(getIp(), getGossipPort()).sync();
    } catch (InterruptedException ex) {
        LOG.error("Gossip server interrupted.", ex);
    }
}
 
开发者ID:Archarithms,项目名称:bigio,代码行数:35,代码来源:MeMemberTCP.java


示例8: GossipServerThread

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
public GossipServerThread() {
    gossipBossGroup = new NioEventLoopGroup(GOSSIP_BOSS_THREADS);
    gossipWorkerGroup = new NioEventLoopGroup(GOSSIP_WORKER_THREADS);
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(gossipBossGroup, gossipWorkerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.config().setAllocator(UnpooledByteBufAllocator.DEFAULT);
                        ch.pipeline().addLast(new GossipMessageDecoder());
                        ch.pipeline().addLast("encoder", new ByteArrayEncoder());
                        ch.pipeline().addLast("decoder", new ByteArrayDecoder());
                        ch.pipeline().addLast(new GossipMessageHandler());
                        if (LOG.isTraceEnabled()) {
                            ch.pipeline().addLast(new LoggingHandler(LogLevel.TRACE));
                        }
                    }

                    @Override
                    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
                        LOG.error("Cannot initialize gossip server.", cause);
                    }
                })
                .option(ChannelOption.SO_BACKLOG, 128)
                .childOption(ChannelOption.SO_KEEPALIVE, true);

        // Bind and start to accept incoming connections.
        f = b.bind(getIp(), getGossipPort()).sync();
    } catch (InterruptedException ex) {
        LOG.error("Gossip server interrupted.", ex);
    }
}
 
开发者ID:Archarithms,项目名称:bigio,代码行数:35,代码来源:MeMemberUDP.java


示例9: initChannel

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
@Override
protected void initChannel(final SocketChannel ch) throws Exception {
  ch.pipeline()
      .addLast("frameDecoder", new LengthFieldBasedFrameDecoder(MAXFRAMELENGTH, 0, 4, 0, 4))
      .addLast("bytesDecoder", new ByteArrayDecoder())
      .addLast("frameEncoder", new LengthFieldPrepender(4))
      .addLast("bytesEncoder", new ByteArrayEncoder())
      .addLast("chunker", new ChunkedReadWriteHandler())
      .addLast("handler", handlerFactory.createChannelInboundHandler());
}
 
开发者ID:apache,项目名称:reef,代码行数:11,代码来源:NettyChannelInitializer.java


示例10: initializeGossipClient

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
private void initializeGossipClient() {
    LOG.trace("Initializing gossip client");

    gossipWorkerGroup = new NioEventLoopGroup(GOSSIP_WORKER_THREADS);
        
    Bootstrap b = new Bootstrap();
    b.group(gossipWorkerGroup);
    b.channel(NioSocketChannel.class);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout);
    b.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ch.config().setAllocator(UnpooledByteBufAllocator.DEFAULT);
            ch.pipeline().addLast("encoder", new ByteArrayEncoder());
            ch.pipeline().addLast("decoder", new ByteArrayDecoder());
            ch.pipeline().addLast(new GossipExceptionHandler());
            if(LOG.isTraceEnabled()) {
                ch.pipeline().addLast(new LoggingHandler(LogLevel.TRACE));
            }
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            LOG.error("Cannot initialize gossip client.", cause);
            ctx.close();
        }
    });

    // Start the client.
    ChannelFuture future = b.connect(getIp(), getGossipPort()).awaitUninterruptibly();

    if(future.isCancelled()) {
        gossipChannel = null;
    } else if(!future.isSuccess()) {
        gossipChannel = null;
        retryGossipConnection();
    } else {
        gossipChannel = future.channel();
        setStatus(MemberStatus.Alive);
        updateMember();
    }
}
 
开发者ID:Archarithms,项目名称:bigio,代码行数:44,代码来源:RemoteMemberTCP.java


示例11: initializeDataClient

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
private void initializeDataClient() {
    LOG.trace("Initializing data client");

    dataWorkerGroup = new NioEventLoopGroup(DATA_WORKER_THREADS);
        
    Bootstrap b = new Bootstrap();
    b.group(dataWorkerGroup)
     .channel(NioSocketChannel.class)
     .option(ChannelOption.SO_SNDBUF, 262144)
     .option(ChannelOption.SO_RCVBUF, 262144)
     .option(ChannelOption.SO_KEEPALIVE, true)
     .option(ChannelOption.TCP_NODELAY, true)
     .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout)
     .handler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ch.config().setAllocator(UnpooledByteBufAllocator.DEFAULT);
            if(useSSL) {
                ch.pipeline().addLast(sslContext.newHandler(ch.alloc(), ip, dataPort));
            }
            ch.pipeline().addLast("encoder", new ByteArrayEncoder());
            ch.pipeline().addLast("decoder", new ByteArrayDecoder());
            ch.pipeline().addLast(new DataExceptionHandler());
            if(LOG.isTraceEnabled()) {
                ch.pipeline().addLast(new LoggingHandler(LogLevel.TRACE));
            }
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            LOG.error("Cannot initialize data client.", cause);
            ctx.close();
        }
    });

    // Start the client.
    ChannelFuture future = b.connect(getIp(), getDataPort()).awaitUninterruptibly();

    if(future.isCancelled()) {
        dataChannel = null;
    } else if(!future.isSuccess()) {
        dataChannel = null;
        retryDataConnection();
    } else {
        dataChannel = future.channel();

        try {
            dataChannel.closeFuture().sync();
        } catch (InterruptedException ex) {
            LOG.debug("Interrupted waiting for client to shutdown.", ex);
        }
    }
}
 
开发者ID:Archarithms,项目名称:bigio,代码行数:54,代码来源:RemoteMemberTCP.java


示例12: initializeGossipClient

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
private void initializeGossipClient() {
    LOG.trace("Initializing gossip client");

    gossipWorkerGroup = new NioEventLoopGroup(GOSSIP_WORKER_THREADS);

    Bootstrap b = new Bootstrap();
    b.group(gossipWorkerGroup);
    b.channel(NioSocketChannel.class);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout);
    b.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ch.config().setAllocator(UnpooledByteBufAllocator.DEFAULT);
            ch.pipeline().addLast("encoder", new ByteArrayEncoder());
            ch.pipeline().addLast("decoder", new ByteArrayDecoder());
            ch.pipeline().addLast(new GossipExceptionHandler());
            if (LOG.isTraceEnabled()) {
                ch.pipeline().addLast(new LoggingHandler(LogLevel.TRACE));
            }
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            LOG.error("Cannot initialize gossip client.", cause);
            ctx.close();
        }
    });

    // Start the client.
    ChannelFuture future = b.connect(getIp(), getGossipPort()).awaitUninterruptibly();

    if (future.isCancelled()) {
        gossipChannel = null;
    } else if (!future.isSuccess()) {
        gossipChannel = null;
        retryGossipConnection();
    } else {
        gossipChannel = future.channel();
        setStatus(MemberStatus.Alive);
        updateMember();
    }
}
 
开发者ID:Archarithms,项目名称:bigio,代码行数:44,代码来源:RemoteMemberUDP.java


示例13: initChannel

import io.netty.handler.codec.bytes.ByteArrayEncoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {

    logger.debug("initChannel-start");

    ProtocolDecoderService protocolDecoderService = null;
    ProtocolEncoderService protocolEncoderService = null;

    try{
        protocolDecoderService = applicationContext.getBean(ProtocolDecoderService.class);
        protocolEncoderService = applicationContext.getBean(ProtocolEncoderService.class);

    }catch (Exception e){
        protocolDecoderService = new DefaultProtocolDecoderService();
        protocolEncoderService = new DefaultProtocolEncoderService();
    }

    logger.debug("initChannel->protocolDecoderService:"+protocolDecoderService);
    logger.debug("initChannel->protocolEncoderService:"+protocolEncoderService);


    ch.pipeline().addLast(ByteArrayDecoder,new ByteArrayDecoder());
    ch.pipeline().addLast(ByteArrayEncoder,new ByteArrayEncoder());

    ch.pipeline().addLast(LengthFieldBasedFrameDecoder,new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));

    ch.pipeline().addLast(ProtocolDecoderHandler,new ProtocolDecoderHandler(protocolDecoderService));
    ch.pipeline().addLast(ProtocolEncoderHandler,new ProtocolEncoderHandler(protocolEncoderService));


    ch.pipeline().addLast(SystemTimeOut,new IdleStateHandler(heartTime, heartTime, heartTime, TimeUnit.SECONDS));

    ch.pipeline().addLast(SocketHandler,new SocketHandler(socketService));

    logger.debug("initChannel-end");
}
 
开发者ID:1991wangliang,项目名称:sds,代码行数:37,代码来源:SocketServerChannelInitializer.java



注:本文中的io.netty.handler.codec.bytes.ByteArrayEncoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java State类代码示例发布时间:2022-05-23
下一篇:
Java XMLCharacterRecognizer类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap