protected final byte[] newBytePage(int page) { if (recycler != null) { final Recycler.V<byte[]> v = recycler.bytePage(clearOnResize); return registerNewPage(v, page, PageCacheRecycler.BYTE_PAGE_SIZE); } else { return new byte[PageCacheRecycler.BYTE_PAGE_SIZE]; } }
/** * Allocate a new {@link ByteArray}. * @param size the initial length of the array * @param clearOnResize whether values should be set to 0 on initialization and resize */ public ByteArray newByteArray(long size, boolean clearOnResize) { if (size > PageCacheRecycler.BYTE_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigByteArray.estimateRamBytes(size), false); return new BigByteArray(size, this, clearOnResize); } else if (size >= PageCacheRecycler.BYTE_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<byte[]> page = recycler.bytePage(clearOnResize); return validate(new ByteArrayWrapper(this, page.v(), size, page, clearOnResize)); } else { return validate(new ByteArrayWrapper(this, new byte[(int) size], size, null, clearOnResize)); } }
protected final byte[] newBytePage(int page) { if (recycler != null) { final Recycler.V<byte[]> v = recycler.bytePage(clearOnResize); return registerNewPage(v, page, BigArrays.BYTE_PAGE_SIZE); } else { return new byte[BigArrays.BYTE_PAGE_SIZE]; } }
protected final byte[] newBytePage(int page) { if (recycler != null) { final Recycler.V<byte[]> v = recycler.bytePage(clearOnResize); return registerNewPage(v, page, BigArrays.BYTE_PAGE_SIZE); } else { return new byte[BigArrays.BYTE_PAGE_SIZE]; } }
protected final byte[] newBytePage(int page) { if (recycler != null) { final Recycler.V<byte[]> v = recycler.bytePage(clearOnResize); return registerNewPage(v, page, BigArrays.BYTE_PAGE_SIZE); } else { return new byte[BigArrays.BYTE_PAGE_SIZE]; } }
@Override public V<byte[]> bytePage(boolean clear) { final V<byte[]> page = super.bytePage(clear); if (!clear) { Arrays.fill(page.v(), 0, page.v().length, (byte)random.nextInt(1<<8)); } return wrap(page); }
private Consumer<NioSocketChannel> getContextSetter(String profileName) { return (c) -> { Supplier<InboundChannelBuffer.Page> pageSupplier = () -> { Recycler.V<byte[]> bytes = pageCacheRecycler.bytePage(false); return new InboundChannelBuffer.Page(ByteBuffer.wrap(bytes.v()), bytes); }; c.setContexts(new TcpReadContext(c, new TcpReadHandler(profileName, this), new InboundChannelBuffer(pageSupplier)), new TcpWriteContext(c), this::exceptionCaught); }; }
/** * Allocate a new {@link ByteArray}. * @param size the initial length of the array * @param clearOnResize whether values should be set to 0 on initialization and resize */ public ByteArray newByteArray(long size, boolean clearOnResize) { if (size > BYTE_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigByteArray.estimateRamBytes(size), false); return new BigByteArray(size, this, clearOnResize); } else if (size >= BYTE_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<byte[]> page = recycler.bytePage(clearOnResize); return validate(new ByteArrayWrapper(this, page.v(), size, page, clearOnResize)); } else { return validate(new ByteArrayWrapper(this, new byte[(int) size], size, null, clearOnResize)); } }
/** * Allocate a new {@link ByteArray}. * @param size the initial length of the array * @param clearOnResize whether values should be set to 0 on initialization and resize */ public ByteArray newByteArray(long size, boolean clearOnResize) { if (size > BYTE_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigByteArray.estimateRamBytes(size), false); return new BigByteArray(size, this, clearOnResize); } else if (size >= BYTE_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<byte[]> page = recycler.bytePage(clearOnResize); return validate(new ByteArrayWrapper(this, page.v(), size, page, clearOnResize)); } else { return validate(new ByteArrayWrapper(this, new byte[(int) size], size, null, clearOnResize)); } }
/** * Allocate a new {@link ByteArray}. * @param size the initial length of the array * @param clearOnResize whether values should be set to 0 on initialization and resize */ public ByteArray newByteArray(long size, boolean clearOnResize) { if (size > BYTE_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigByteArray.estimateRamBytes(size), false); return new BigByteArray(size, this, clearOnResize); } else if (size >= BYTE_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<byte[]> page = recycler.bytePage(clearOnResize); return validate(new ByteArrayWrapper(this, page.v(), size, page, clearOnResize)); } else { return validate(new ByteArrayWrapper(this, new byte[(int) size], size, null, clearOnResize)); } }