Packages

package storage

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. class BufferAllocationException extends Exception

    Exception thrown when it's impossible to allocate another buffer

  2. class BytesStorage extends AnyRef

    A linear, indexed storage of bytes.

    A linear, indexed storage of bytes. Based on the java NIO ByteBuffer for performance. This class isn't thread-safe.

  3. class NoCorrespondingStageException extends Exception

    Thrown when a StagedPools object cannot return a result because there is no stage that corresponds to the requested capacity.

  4. final class StagedPools extends StorageProvider

    A group of StoragePool, organized in stages.

    A group of StoragePool, organized in stages.

    Example

    val pool = StagedPools().directStage(100, 5, true)    // 1st stage
                            .directStage(1000, 10, false) // 2nd stage
                            .defaultAllocateHeap()        // default handler
                            .build()
    
    val storage = pool.getStorage(512)
    val buffer = new CircularBuffer(storage)

    This code creates a new group of staged pools and uses it to create a CircularBuffer with a capacity of at least 512 bytes.

    When getStorage(capacity) is called:

    • If capacity <= 100, a storage from the 1st stage is returned. Up to 5 storages are kept in the pool, but more storages can be created as needed (isMoreAllocationAllowed=true).
    • If capacity <= 1000, a storage from the 2nd stage is returned. Up to 10 storages are kept in the pool. If 10 storages from this stage are already being used, and more storages are requested, an exception is thrown.
    • If capacity > 1000, the default handler is called. In this case, defaultAllocateHeap allocates a new heap buffer of the requested capacity.
  5. class StoragePool extends AnyRef

    A pool of BytesStorages.

    A pool of BytesStorages.

    Automatic storage return

    The pool uses java.lang.ref.SoftReferences to track the ByteStorages. When a storage is collected by the GC, its underlying java.nio.ByteBuffer is returned to the pool. Thus, a ByteStorage is nothing more than a thin wrapper around a java ByteBuffer, with automatic pooling management.

    Manual storage return

    You can force a ByteStorage to return to the pool by calling its method BytesStorage.discardNow.

  6. trait StorageProvider extends AnyRef

    Provides com.electronwill.niol.buffer.storage.BytesStorages

  7. class StorageReference extends PhantomReference[BytesStorage]

    A java.lang.ref.PhantomReference that stores a java.nio.ByteBuffer in order to return it to the StoragePool when the referent BytesStorage gets collected by the GC.

Value Members

  1. object BytesStorage

    Companion of BytesStorage

  2. object StagedPools

Ungrouped