MCPcopy Create free account
hub / github.com/grpc/grpc-java / getByteBufAllocator

Method getByteBufAllocator

netty/src/main/java/io/grpc/netty/Utils.java:140–164  ·  view source on GitHub ↗
(boolean forceHeapBuffer)

Source from the content-addressed store, hash-verified

138 }
139
140 public static ByteBufAllocator getByteBufAllocator(boolean forceHeapBuffer) {
141 if (Boolean.parseBoolean(
142 System.getProperty("io.grpc.netty.useCustomAllocator", "true"))) {
143
144 String allocType = System.getProperty("io.netty.allocator.type", "pooled");
145 if (allocType.toLowerCase(Locale.ROOT).equals("unpooled")) {
146 logger.log(Level.FINE, "Using unpooled allocator");
147 return UnpooledByteBufAllocator.DEFAULT;
148 }
149
150 boolean defaultPreferDirect = PooledByteBufAllocator.defaultPreferDirect();
151 logger.log(
152 Level.FINE,
153 "Using custom allocator: forceHeapBuffer={0}, defaultPreferDirect={1}",
154 new Object[] { forceHeapBuffer, defaultPreferDirect });
155 if (forceHeapBuffer || !defaultPreferDirect) {
156 return ByteBufAllocatorPreferHeapHolder.allocator;
157 } else {
158 return ByteBufAllocatorPreferDirectHolder.allocator;
159 }
160 } else {
161 logger.log(Level.FINE, "Using default allocator");
162 return ByteBufAllocator.DEFAULT;
163 }
164 }
165
166 private static ByteBufAllocator createByteBufAllocator(boolean preferDirect) {
167 int maxOrder;

Callers 3

startMethod · 0.95
startMethod · 0.95

Calls 4

parseBooleanMethod · 0.80
getPropertyMethod · 0.80
equalsMethod · 0.45
logMethod · 0.45

Tested by 1