Class DefaultIoEventSizeEstimator

  • All Implemented Interfaces:
    IoEventSizeEstimator

    public class DefaultIoEventSizeEstimator
    extends java.lang.Object
    implements IoEventSizeEstimator
    A default IoEventSizeEstimator implementation.

    Martin's Java Notes was used for estimation. For unknown types, it inspects declaring fields of the class of the specified event and the parameter of the event. The size of unknown declaring fields are approximated to the specified averageSizePerField (default: 64).

    All the estimated sizes of classes are cached for performance improvement.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.ConcurrentMap<java.lang.Class<?>,​java.lang.Integer> class2size
      A map containing the estimated size of each Java objects we know for
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultIoEventSizeEstimator()
      Create a new instance of this class, injecting the known size of basic java types.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static int align​(int size)  
      private int estimateSize​(java.lang.Class<?> clazz, java.util.Set<java.lang.Class<?>> visitedClasses)  
      int estimateSize​(java.lang.Object message)
      Estimate the size of an Object in number of bytes
      int estimateSize​(IoEvent event)
      Estimate the IoEvent size in number of bytes
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • class2size

        private final java.util.concurrent.ConcurrentMap<java.lang.Class<?>,​java.lang.Integer> class2size
        A map containing the estimated size of each Java objects we know for
    • Constructor Detail

      • DefaultIoEventSizeEstimator

        public DefaultIoEventSizeEstimator()
        Create a new instance of this class, injecting the known size of basic java types.
    • Method Detail

      • estimateSize

        public int estimateSize​(IoEvent event)
        Estimate the IoEvent size in number of bytes
        Specified by:
        estimateSize in interface IoEventSizeEstimator
        Parameters:
        event - The event we want to estimate the size of
        Returns:
        The estimated size of this event
      • estimateSize

        public int estimateSize​(java.lang.Object message)
        Estimate the size of an Object in number of bytes
        Parameters:
        message - The object to estimate
        Returns:
        The estimated size of the object
      • estimateSize

        private int estimateSize​(java.lang.Class<?> clazz,
                                 java.util.Set<java.lang.Class<?>> visitedClasses)
      • align

        private static int align​(int size)