Package org.apache.parquet.bytes
Class ReusingByteBufferAllocator
- java.lang.Object
-
- org.apache.parquet.bytes.ReusingByteBufferAllocator
-
- All Implemented Interfaces:
AutoCloseable,ByteBufferAllocator
public abstract class ReusingByteBufferAllocator extends Object implements ByteBufferAllocator, AutoCloseable
A specialByteBufferAllocatorimplementation that keeps oneByteBufferobject and reuses it at the nextallocate(int)call. Theclose()shall be called when this allocator is not needed anymore to really release the one buffer.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteBufferallocate(int size)voidclose()ByteBufferReleasergetReleaser()A convenience method to get aByteBufferReleaserinstance already created for this allocator.booleanisDirect()Indicates if this allocator will produce ByteBuffers backed by direct memory.voidrelease(ByteBuffer b)For RefCounted implementations using direct memory, the release method needs to be called to free references to the allocated memory.static ReusingByteBufferAllocatorstrict(ByteBufferAllocator allocator)Creates a new strictReusingByteBufferAllocatorobject with the specified "parent" allocator to be used for allocating/releasing the one buffer.static ReusingByteBufferAllocatorunsafe(ByteBufferAllocator allocator)Creates a new unsafeReusingByteBufferAllocatorobject with the specified "parent" allocator to be used for allocating/releasing the one buffer.
-
-
-
Method Detail
-
strict
public static ReusingByteBufferAllocator strict(ByteBufferAllocator allocator)
Creates a new strictReusingByteBufferAllocatorobject with the specified "parent" allocator to be used for allocating/releasing the one buffer.Strict means it is enforced that
release(ByteBuffer)is invoked before a newallocate(int)can be called.- Parameters:
allocator- the allocator to be used for allocating/releasing the one buffer- Returns:
- a new strict
ReusingByteBufferAllocatorobject
-
unsafe
public static ReusingByteBufferAllocator unsafe(ByteBufferAllocator allocator)
Creates a new unsafeReusingByteBufferAllocatorobject with the specified "parent" allocator to be used for allocating/releasing the one buffer.Unsafe means it is not enforced that
release(ByteBuffer)is invoked before a newallocate(int)can be called, i.e. no exceptions will be thrown atallocate(int).- Parameters:
allocator- the allocator to be used for allocating/releasing the one buffer- Returns:
- a new unsafe
ReusingByteBufferAllocatorobject
-
getReleaser
public ByteBufferReleaser getReleaser()
A convenience method to get aByteBufferReleaserinstance already created for this allocator.- Returns:
- a releaser for this allocator
-
allocate
public ByteBuffer allocate(int size)
- Specified by:
allocatein interfaceByteBufferAllocator- Throws:
IllegalStateException- if strict and the one buffer was not released yet- See Also:
strict(ByteBufferAllocator),unsafe(ByteBufferAllocator)
-
release
public void release(ByteBuffer b)
For RefCounted implementations using direct memory, the release method needs to be called to free references to the allocated memory.- Specified by:
releasein interfaceByteBufferAllocator- Parameters:
b- a ByteBuffer- Throws:
IllegalStateException- if the one buffer has already been released or never allocatedIllegalArgumentException- if the specified buffer is not the one allocated by this allocator
-
isDirect
public boolean isDirect()
Description copied from interface:ByteBufferAllocatorIndicates if this allocator will produce ByteBuffers backed by direct memory.- Specified by:
isDirectin interfaceByteBufferAllocator- Returns:
- true if direct memory backed buffers will be created by this allocator, else false
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
-