Class DefaultModelObjectPool

java.lang.Object
org.apache.maven.impl.model.DefaultModelObjectPool
All Implemented Interfaces:
ModelObjectProcessor

public class DefaultModelObjectPool extends Object implements ModelObjectProcessor
Default implementation of ModelObjectProcessor that provides memory optimization through object pooling and interning.

This implementation can pool any model object type based on configuration. By default, it pools Dependency objects, which are frequently duplicated in large Maven projects. Other model objects are passed through unchanged unless explicitly configured for pooling.

The pool uses configurable reference types and provides thread-safe access through ConcurrentHashMap-based caches.

Since:
4.0.0
  • Constructor Details

    • DefaultModelObjectPool

      public DefaultModelObjectPool()
  • Method Details

    • process

      public <T> T process(T object)
      Description copied from interface: ModelObjectProcessor
      Process a model object, potentially returning a pooled or optimized version.

      This method is called during model building for various model objects. Implementations can:

      • Return the same object if no processing is desired
      • Return a pooled equivalent object to reduce memory usage
      • Return a modified or optimized version of the object

      The implementation must ensure that the returned object is functionally equivalent to the input object from the perspective of the Maven model.

      Specified by:
      process in interface ModelObjectProcessor
      Type Parameters:
      T - the type of the model object
      Parameters:
      object - the model object to process
      Returns:
      the processed object (may be the same instance, a pooled instance, or a modified instance)
    • getStatistics

      public static String getStatistics(Class<?> objectType)
      Get statistics for a specific object type. Useful for monitoring and debugging.
    • getAllStatistics

      public static String getAllStatistics()
      Get statistics for all pooled object types.