Interface JPPoolableListenerType<K,T,C>

Type Parameters:
K - The type of keys used to fetch objects
T - The type of objects within pools
C - The type of contextual values used to create objects

public interface JPPoolableListenerType<K,T,C>
The type of listeners used to manipulate objects within pools.
  • Method Summary

    Modifier and Type
    Method
    Description
    onCreate(C c, K key)
    Called when an object is to be created.
    void
    onDelete(C c, K key, T value)
    Called when an object is to be deleted.
    void
    onError(C c, K key, Optional<T> value, Throwable e)
    Called on errors.
    long
    onEstimateSize(C c, K key)
    Estimate the size of the object that will be created for key.
    long
    onGetSize(C c, K key, T value)
    Called when the size of value is required.
    void
    onReuse(C c, K key, T value)
    Called when an existing object is to be reused.
  • Method Details

    • onEstimateSize

      long onEstimateSize(C c, K key)
      Estimate the size of the object that will be created for key. If the object size cannot be estimated, the function should return 0. The purpose of estimation is to avoid having to allocate an object and then finding out afterwards that the object is too large for the cache. If the sizes are known ahead of time, allocations can be avoided.
      Parameters:
      c - A context value
      key - A key
      Returns:
      The estimated size of the object
    • onCreate

      T onCreate(C c, K key)
      Called when an object is to be created.
      Parameters:
      c - A context value
      key - A key
      Returns:
      A new object
    • onGetSize

      long onGetSize(C c, K key, T value)
      Called when the size of value is required.
      Parameters:
      c - A context value
      key - A key
      value - The object to be measured
      Returns:
      The size of value
    • onReuse

      void onReuse(C c, K key, T value)
      Called when an existing object is to be reused.
      Parameters:
      c - A context value
      key - A key
      value - The object to be reused
    • onDelete

      void onDelete(C c, K key, T value)
      Called when an object is to be deleted. The method should delete any resourced associated with value.
      Parameters:
      c - A context value
      key - A key
      value - The object to be deleted
    • onError

      void onError(C c, K key, Optional<T> value, Throwable e)
      Called on errors.
      Parameters:
      c - A context value
      key - A key
      value - The value associated with the error, if any
      e - The exception raised