| 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; |