Example usage for io.netty.util.internal PlatformDependent directBufferPreferred

List of usage examples for io.netty.util.internal PlatformDependent directBufferPreferred

Introduction

In this page you can find the example usage for io.netty.util.internal PlatformDependent directBufferPreferred.

Prototype

public static boolean directBufferPreferred() 

Source Link

Document

Returns true if the platform has reliable low-level direct buffer access API and a user has not specified -Dio.netty.noPreferDirect option.

Usage

From source file:com.github.milenkovicm.kafka.util.Allocator.java

License:Apache License

public static PooledByteBufAllocator createPooledByteBufAllocator(boolean allowCache, int numCores) {
    if (numCores == 0) {
        numCores = Runtime.getRuntime().availableProcessors();
    }/*  ww w.  ja  v a  2  s . c  o  m*/
    return new PooledByteBufAllocator(PlatformDependent.directBufferPreferred(),
            Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores),
            Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"),
                    PlatformDependent.directBufferPreferred() ? 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);
}

From source file:com.github.sparkfy.network.util.NettyUtils.java

License:Apache License

/**
 * 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.
 *///w  w  w. j a v  a2s. c  o  m
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);
}

From source file:org.jupiter.transport.netty.NettyAcceptor.java

License:Apache License

protected void setOptions() {
    JConfig parent = configGroup().parent(); // parent options
    JConfig child = configGroup().child(); // child options

    setIoRatio(parent.getOption(JOption.IO_RATIO), child.getOption(JOption.IO_RATIO));

    boolean direct = child.getOption(JOption.PREFER_DIRECT);
    if (child.getOption(JOption.USE_POOLED_ALLOCATOR)) {
        if (direct) {
            allocator = new PooledByteBufAllocator(PlatformDependent.directBufferPreferred());
        } else {/*www .  ja  v  a2  s .c  o  m*/
            allocator = new PooledByteBufAllocator(false);
        }
    } else {
        if (direct) {
            allocator = new UnpooledByteBufAllocator(PlatformDependent.directBufferPreferred());
        } else {
            allocator = new UnpooledByteBufAllocator(false);
        }
    }
    bootstrap.childOption(ChannelOption.ALLOCATOR, allocator).childOption(ChannelOption.MESSAGE_SIZE_ESTIMATOR,
            JMessageSizeEstimator.DEFAULT);
}

From source file:org.jupiter.transport.netty.NettyConnector.java

License:Apache License

protected void setOptions() {
    JConfig child = config();/*from   ww  w.  j a v a  2  s  .co m*/

    setIoRatio(child.getOption(JOption.IO_RATIO));

    boolean direct = child.getOption(JOption.PREFER_DIRECT);
    if (child.getOption(JOption.USE_POOLED_ALLOCATOR)) {
        if (direct) {
            allocator = new PooledByteBufAllocator(PlatformDependent.directBufferPreferred());
        } else {
            allocator = new PooledByteBufAllocator(false);
        }
    } else {
        if (direct) {
            allocator = new UnpooledByteBufAllocator(PlatformDependent.directBufferPreferred());
        } else {
            allocator = new UnpooledByteBufAllocator(false);
        }
    }
    bootstrap.option(ChannelOption.ALLOCATOR, allocator).option(ChannelOption.MESSAGE_SIZE_ESTIMATOR,
            JMessageSizeEstimator.DEFAULT);
}