当前位置: 首页>>代码示例>>Java>>正文


Java PooledByteBufAllocator类代码示例

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


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

示例1: createPooledByteBufAllocator

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
/**
 * Create a pooled ByteBuf allocator but disables the thread-local cache. Thread-local caches
 * are disabled for TransportClients because the ByteBufs are allocated by the event loop thread,
 * but released by the executor thread rather than the event loop thread. Those thread-local
 * caches actually delay the recycling of buffers, leading to larger memory usage.
 */
public static PooledByteBufAllocator createPooledByteBufAllocator(
    boolean allowDirectBufs,
    boolean allowCache,
    int numCores) {
  if (numCores == 0) {
    numCores = Runtime.getRuntime().availableProcessors();
  }
  return new PooledByteBufAllocator(
      allowDirectBufs && PlatformDependent.directBufferPreferred(),
      Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores),
      Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0),
      getPrivateStaticField("DEFAULT_PAGE_SIZE"),
      getPrivateStaticField("DEFAULT_MAX_ORDER"),
      allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0,
      allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0,
      allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0
  );
}
 
开发者ID:Tencent,项目名称:angel,代码行数:25,代码来源:NettyUtils.java

示例2: encode

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
/**
 * <b>一定要 {@link ByteBuf#release()}
 */
public static ByteBuf encode(RemotingCommand cmd) {
    int reqId = cmd.getOpaque();
    byte[] body = cmd.getBody();
    HashMap<String, String> msgs = cmd.getExtFields();
    byte[] append = JsonUtil.toBytes(msgs);
    int initialCapacity = 4 + 4 // total size+reqId
            + 4 + body.length // body
            + 4 + append.length;// apend
    ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(initialCapacity);
    buf.writeInt(initialCapacity);
    buf.writeInt(reqId);
    buf.writeInt(body.length);
    buf.writeBytes(body);
    buf.writeInt(append.length);
    buf.writeBytes(append);

    return buf;
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:22,代码来源:RemotingCommand.java

示例3: AbstractNettyServer

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
protected AbstractNettyServer(String serverName) {
	this.serverName = Objects.requireNonNull(serverName, "server name");
	bootstrap = new ServerBootstrap();
	if (Epoll.isAvailable()) {
		bootstrap.option(ChannelOption.SO_BACKLOG, 1024).channel(EpollServerSocketChannel.class)
				.childOption(ChannelOption.SO_LINGER, 0).childOption(ChannelOption.SO_REUSEADDR, true)
				.childOption(ChannelOption.SO_KEEPALIVE, true);
		log.info(serverName + " epoll init");
	} else {
		bootstrap.channel(NioServerSocketChannel.class);
		log.info(serverName + " nio init");
	}
	bootstrap.group(bossGroup, workerGroup).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
			.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
			.childOption(ChannelOption.TCP_NODELAY, true).childHandler(new ChannelInitializer<SocketChannel>() {

				@Override
				protected void initChannel(SocketChannel ch) throws Exception {
					initPipeline(ch.pipeline());
				}
			});
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:23,代码来源:AbstractNettyServer.java

示例4: BinaryClient

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
private BinaryClient(BinaryClientBuilder builder) throws Exception {
	this.clientName = builder.clientName;
	this.remoteAddress = Objects.requireNonNull(builder.remoteAddress, "remoteAddress");
	this.autoReconnect = builder.autoReconnect;
	this.decoder = Objects.requireNonNull(builder.decoder, "decoder");
	this.encoder = Objects.requireNonNull(builder.encoder, "encoder");
	this.factory = Objects.requireNonNull(builder.factory, "factory");
	this.onChannelStateChanged = builder.onChannelStateChanged;
	this.onExceptionCaught = builder.onExceptionCaught;
	this.onConnectionEffective = builder.onConnectionEffective;
	this.dispatchMessage = builder.dispatchMessage;
	this.heartIntervalSec = builder.heartIntervalSec;
	// 内部消息注册
	factory.registerMsg(new ConnectionValidateServerHandler())
			.registerMsg(new ConnectionValidateSuccessServerHandler()).registerMsg(new HeartServerHandler());
	decodeUtil = SymmetricEncryptionUtil.getDecodeInstance(remoteAddress.getPass());
	bootstrap = new Bootstrap();
	bootstrap.channel(NioSocketChannel.class);
	log.info(clientName + " nio init");
	bootstrap.group(group).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
			.handler(new ChannelInitializerImpl());
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:23,代码来源:BinaryClient.java

示例5: start

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
/**
 * 启动服务
 *
 * @throws Exception 异常
 */
public void start() throws Exception {
    try {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(channelInitializer)
                .option(ChannelOption.SO_BACKLOG, aceServerConfig.getBackSize())
                .childOption(ChannelOption.SO_KEEPALIVE, true)
                .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
        ChannelFuture future = bootstrap.bind(aceServerConfig.getPort()).sync();
        System.out.println("ace server starter on port : " + aceServerConfig.getPort());
        future.channel().closeFuture().sync();
    } finally {
        close();
    }


}
 
开发者ID:ChenXun1989,项目名称:ace,代码行数:24,代码来源:DefaultServer.java

示例6: createPooledByteBufAllocator

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
/**
 * Create a pooled ByteBuf allocator but disables the thread-local cache. Thread-local caches
 * are disabled for TransportClients because the ByteBufs are allocated by the event loop thread,
 * but released by the executor thread rather than the event loop thread. Those thread-local
 * caches actually delay the recycling of buffers, leading to larger memory usage.
 */
public static PooledByteBufAllocator createPooledByteBufAllocator(
    boolean allowDirectBufs,
    boolean allowCache,
    int numCores) {
  if (numCores == 0) {
    numCores = Runtime.getRuntime().availableProcessors();
  }
  return new PooledByteBufAllocator(
    allowDirectBufs && PlatformDependent.directBufferPreferred(),
    Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores),
    Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0),
    getPrivateStaticField("DEFAULT_PAGE_SIZE"),
    getPrivateStaticField("DEFAULT_MAX_ORDER"),
    allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0,
    allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0,
    allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0
  );
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:25,代码来源:NettyUtils.java

示例7: startAcceptingConnections

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
private void startAcceptingConnections() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
    b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
    b.option(ChannelOption.SO_RCVBUF, 1048576);
    b.option(ChannelOption.TCP_NODELAY, true);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.group(serverGroup, clientGroup);
    b.channel(serverChannelClass);
    if (enableNettyTls) {
        b.childHandler(new SslServerCommunicationChannelInitializer());
    } else {
        b.childHandler(new OnosCommunicationChannelInitializer());
    }
    b.option(ChannelOption.SO_BACKLOG, 128);
    b.childOption(ChannelOption.SO_KEEPALIVE, true);

    // Bind and start to accept incoming connections.
    b.bind(localEp.port()).sync().addListener(future -> {
        if (future.isSuccess()) {
            log.info("{} accepting incoming connections on port {}", localEp.host(), localEp.port());
        } else {
            log.warn("{} failed to bind to port {}", localEp.host(), localEp.port(), future.cause());
        }
    });
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:NettyMessagingManager.java

示例8: initChannel

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
@Override
        protected void initChannel(SocketChannel ch) throws Exception {
            try {
                ch.config().setOption(ChannelOption.IP_TOS, 0x18);
//                ch.config().setOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
//                ch.config().setOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
            } catch (ChannelException ex) {
                // IP_TOS not supported by platform, ignore
            }
            ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
            
            PacketRegistry r = new PacketRegistry();

            ch.pipeline().addLast(new HttpServerCodec());
            ch.pipeline().addLast(new HttpObjectAggregator(65536));
            ch.pipeline().addLast(new WebSocketHandler());
            ch.pipeline().addLast(new PacketDecoder(r));
            ch.pipeline().addLast(new PacketEncoder(r));
            ch.pipeline().addLast(new ClientHandler(server));
        }
 
开发者ID:AlexMog,项目名称:SurvivalMMO,代码行数:21,代码来源:NetworkManager.java

示例9: initChannel

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.TCP_NODELAY, true);
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
    
    PacketRegistry r = new PacketRegistry();

    ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(0, 0, 30));
    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder(r));
    ch.pipeline().addLast(new PacketEncoder(r));
    ch.pipeline().addLast(mExecutorGroup, "serverHandler", new ClientHandler(mServer));
}
 
开发者ID:FightForSub,项目名称:FFS-PubSub,代码行数:21,代码来源:NetworkManager.java

示例10: createClient

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
private void createClient(Listener listener, EventLoopGroup workerGroup, ChannelFactory<? extends Channel> channelFactory) {
    this.workerGroup = workerGroup;
    this.bootstrap = new Bootstrap();
    bootstrap.group(workerGroup)//
            .option(ChannelOption.SO_REUSEADDR, true)//
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)//
            .channelFactory(channelFactory);
    bootstrap.handler(new ChannelInitializer<Channel>() { // (4)
        @Override
        public void initChannel(Channel ch) throws Exception {
            initPipeline(ch.pipeline());
        }
    });
    initOptions(bootstrap);
    listener.onSuccess();
}
 
开发者ID:mpusher,项目名称:mpush,代码行数:17,代码来源:NettyTCPClient.java

示例11: initChannel

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder());
    ch.pipeline().addLast(new PacketEncoder());
    ch.pipeline().addLast(new ClientHandler(server));
}
 
开发者ID:CalypsoToolz,项目名称:FPAgar,代码行数:17,代码来源:NetworkManager.java

示例12: initChannel

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new Handshaker());
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder());
    ch.pipeline().addLast(new PacketEncoder());
    ch.pipeline().addLast(new ClientHandler(server));
}
 
开发者ID:ClitherProject,项目名称:Clither-Server,代码行数:18,代码来源:NetworkManager.java

示例13: newBootstrap

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
private Bootstrap newBootstrap() {
	Bootstrap boot = new Bootstrap();
	boot.channel(NettyPlatformIndependent.channelClass());
	boot.option(ChannelOption.TCP_NODELAY, true);
	// replace by heart beat
	boot.option(ChannelOption.SO_KEEPALIVE, false);
	// default is pooled direct
	// ByteBuf(io.netty.util.internal.PlatformDependent.DIRECT_BUFFER_PREFERRED)
	boot.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
	// 32kb(for massive long connections, See
	// http://www.infoq.com/cn/articles/netty-million-level-push-service-design-points)
	// 64kb(RocketMq remoting default value)
	boot.option(ChannelOption.SO_SNDBUF, 32 * 1024);
	boot.option(ChannelOption.SO_RCVBUF, 32 * 1024);
	// temporary settings, need more tests
	boot.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024));
	//default is true, reduce thread context switching
	boot.option(ChannelOption.SINGLE_EVENTEXECUTOR_PER_GROUP, true);
	return boot;
}
 
开发者ID:spccold,项目名称:sailfish,代码行数:21,代码来源:AbstractConfigurableExchangeChannelGroup.java

示例14: newServerBootstrap

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
private ServerBootstrap newServerBootstrap() {
	ServerBootstrap serverBoot = new ServerBootstrap();
	serverBoot.channel(NettyPlatformIndependent.serverChannelClass());
	// connections wait for accept
	serverBoot.option(ChannelOption.SO_BACKLOG, 1024);
	serverBoot.option(ChannelOption.SO_REUSEADDR, true);
	// replace by heart beat
	serverBoot.childOption(ChannelOption.SO_KEEPALIVE, false);
	serverBoot.childOption(ChannelOption.TCP_NODELAY, true);
	serverBoot.childOption(ChannelOption.SO_SNDBUF, 32 * 1024);
	serverBoot.childOption(ChannelOption.SO_RCVBUF, 32 * 1024);
	// temporary settings, need more tests
	serverBoot.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024));
	serverBoot.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
	//default is true, reduce thread context switching
	serverBoot.childOption(ChannelOption.SINGLE_EVENTEXECUTOR_PER_GROUP, true);
	return serverBoot;
}
 
开发者ID:spccold,项目名称:sailfish,代码行数:19,代码来源:DefaultServer.java

示例15: initChannel

import io.netty.buffer.PooledByteBufAllocator; //导入依赖的package包/类
@Override
public void initChannel(Channel ch) throws Exception
{
    try
    {
        ch.config().setOption( ChannelOption.IP_TOS, 0x18 );
    } catch ( ChannelException ex )
    {
        // IP_TOS is not supported (Windows XP / Windows Server 2003)
    }
    ch.config().setOption( ChannelOption.TCP_NODELAY, true );
    ch.config().setAllocator( PooledByteBufAllocator.DEFAULT );

    ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
    ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );
    ch.pipeline().addLast( FRAME_PREPENDER, framePrepender );

    ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
}
 
开发者ID:WaterfallMC,项目名称:Waterfall-Old,代码行数:20,代码来源:PipelineUtils.java


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