Class HeapMemoryManager

    • Constructor Detail

      • HeapMemoryManager

        public HeapMemoryManager()
      • HeapMemoryManager

        public HeapMemoryManager​(int maxBufferSize)
    • Method Detail

      • allocateAtLeast

        public HeapBuffer allocateAtLeast​(int size)
        Allocated Buffer at least of the provided size. This could be useful for usecases like Socket.read(...), where we're not sure how many bytes are available, but want to read as much as possible.
        Specified by:
        allocateAtLeast in interface MemoryManager<HeapBuffer>
        Parameters:
        size - the min Buffer size to be allocated.
        Returns:
        allocated Buffer.
      • reallocate

        public HeapBuffer reallocate​(HeapBuffer oldBuffer,
                                     int newSize)
        Reallocate Buffer to a required size. Implementation may choose the way, how reallocation could be done, either by allocating new Buffer of required size and copying old Buffer content there, or perform more complex logic related to memory pooling etc.
        Specified by:
        reallocate in interface MemoryManager<HeapBuffer>
        Parameters:
        oldBuffer - old Buffer to be reallocated.
        newSize - new Buffer required size.
        Returns:
        reallocated Buffer.
      • release

        public void release​(HeapBuffer buffer)
        Release Buffer. Implementation may ignore releasing and let JVM Garbage collector to take care about the Buffer, or return Buffer to pool, in case of more complex MemoryManager implementation.
        Specified by:
        release in interface MemoryManager<HeapBuffer>
        Parameters:
        buffer - Buffer to be released.
      • wrap

        public HeapBuffer wrap​(byte[] data)
        Returns Buffer, which wraps the byte array.
        Specified by:
        wrap in interface WrapperAware
        Parameters:
        data - byte array to wrap
        Returns:
        Buffer wrapper on top of passed byte array.
      • wrap

        public HeapBuffer wrap​(byte[] data,
                               int offset,
                               int length)
        Returns Buffer, which wraps the part of byte array with specific offset and length.
        Specified by:
        wrap in interface WrapperAware
        Parameters:
        data - byte array to wrap
        offset - byte buffer offset
        length - byte buffer length
        Returns:
        Buffer wrapper on top of passed byte array.
      • wrap

        public HeapBuffer wrap​(java.lang.String s)
        Returns Buffer, which wraps the String.
        Specified by:
        wrap in interface WrapperAware
        Parameters:
        s - String
        Returns:
        Buffer wrapper on top of passed String.
      • wrap

        public HeapBuffer wrap​(java.lang.String s,
                               java.nio.charset.Charset charset)
        Returns Buffer, which wraps the String with the specific Charset.
        Specified by:
        wrap in interface WrapperAware
        Parameters:
        s - String
        charset - Charset, which will be used, when converting String to byte array.
        Returns:
        Buffer wrapper on top of passed String.
      • wrap

        public Buffer wrap​(java.nio.ByteBuffer byteBuffer)
        Returns Buffer, which wraps the ByteBuffer.
        Specified by:
        wrap in interface WrapperAware
        Parameters:
        byteBuffer - ByteBuffer to wrap
        Returns:
        Buffer wrapper on top of passed ByteBuffer.
      • allocateHeapBuffer

        protected HeapBuffer allocateHeapBuffer​(int size)
        Creates a new HeapBuffer with a a specified size.
        Parameters:
        size - size of buffer created
        Returns:
      • allocateHeapBufferAtLeast

        protected HeapBuffer allocateHeapBufferAtLeast​(int size)
      • reallocateHeapBuffer

        protected HeapBuffer reallocateHeapBuffer​(HeapBuffer oldHeapBuffer,
                                                  int newSize)
      • releaseHeapBuffer

        protected final void releaseHeapBuffer​(HeapBuffer heapBuffer)