Java Code Examples for io.netty.util.internal.PlatformDependent#directBufferPreferred()

The following examples show how to use io.netty.util.internal.PlatformDependent#directBufferPreferred() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BufferPool.java    From tajo with Apache License 2.0 6 votes vote down vote up
/**
 * borrowed from Spark
 */
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
  );
}
 
Example 2
Source File: BufferPool.java    From tajo with Apache License 2.0 6 votes vote down vote up
/**
 * borrowed from Spark
 */
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
  );
}
 
Example 3
Source File: CacheClientBuilderTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsePooledByteBuffers() {
    ByteBufAllocator alloc = new PooledByteBufAllocator(PlatformDependent.directBufferPreferred());
    try (CacheClient client = CacheClient
            .newBuilder()
            .serverLocator(serverLocator)
            .allocator(alloc)
            .build();) {
        assertSame(alloc, client.getAllocator());
    }
}
 
Example 4
Source File: ThriftSerializer.java    From tchannel-java with MIT License 5 votes vote down vote up
@VisibleForTesting
static void init()
{
    // We should always prefer direct buffers by default if Netty prefers it and not explicitly prohibited.
    DIRECT_BUFFER_PREFERRED = PlatformDependent.directBufferPreferred()
        && !SystemPropertyUtil.getBoolean("com.uber.tchannel.thrift_serializer.noPreferDirect", false);
    if (logger.isDebugEnabled()) {
        logger.debug("-Dcom.uber.tchannel.thrift_serializer.noPreferDirect: {}", !DIRECT_BUFFER_PREFERRED);
    }
}
 
Example 5
Source File: PooledByteBufAllocator.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
/**
 * Default prefer direct - System Property: io.netty.noPreferDirect - default false
 */
public static boolean defaultPreferDirect() {
    return PlatformDependent.directBufferPreferred();
}