Class PGPropertyMaxResultBufferParser


  • public class PGPropertyMaxResultBufferParser
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.logging.Logger LOGGER  
      private static java.lang.String MANAGEMENT_FACTORY_CLASS_NAME
      Used only as a human-readable identifier in PSQLException messages — keep as a string constant so this class never has a verifier-visible reference to java.lang.management.ManagementFactory.
      private static double MAX_RESULT_BUFFER_HEAP_FRACTION  
      private static java.lang.String[] PERCENT_PHRASES  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static long adjustResultSize​(long value, java.util.function.LongSupplier maxHeapBytesSupplier)
      Method to adjust result memory limit size.
      private static long calculatePercentOfMemory​(java.lang.String value, int percentPhraseLength, java.util.function.LongSupplier maxHeapBytesSupplier)
      Method to calculate percent of given max heap memory.
      private static boolean checkIfValueContainsPercent​(java.lang.String value)
      Method to check if given value can contain percent declaration of size of max result buffer.
      private static long defaultMaxHeapBytesOrNegativeOne()
      Default heap-bytes source: routes through JvmHeapAccess, which lives in its own class so the verifier does not need to resolve java.lang.management.ManagementFactory unless this method is actually invoked.
      private static int getPercentPhraseLengthIfContains​(java.lang.String valueToCheck)
      Method to get length of percent phrase existing in given string, only if one of phrases exist on the length of string.
      private static int getPhraseLengthIfContains​(java.lang.String valueToCheck, java.lang.String phrase)
      Method to get length of given phrase in given string to check, method checks if phrase exist on the end of given string.
      private static long parseBytePercentValue​(java.lang.String value, java.util.function.LongSupplier maxHeapBytesSupplier)
      Method to get percent value of max result buffer size dependable on actual free memory.
      private static long parseByteValue​(java.lang.String value)
      Method to get size based on given string value.
      static long parseProperty​(java.lang.String value)
      Method to parse value of max result buffer size.
      (package private) static long parseProperty​(java.lang.String value, java.util.function.LongSupplier maxHeapBytesSupplier)  
      private static void throwExceptionAboutParsingError​(java.lang.String message, java.lang.Object... values)
      Method to throw message for parsing MaxResultBuffer.
      • Methods inherited from class java.lang.Object

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

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • MANAGEMENT_FACTORY_CLASS_NAME

        private static final java.lang.String MANAGEMENT_FACTORY_CLASS_NAME
        Used only as a human-readable identifier in PSQLException messages — keep as a string constant so this class never has a verifier-visible reference to java.lang.management.ManagementFactory.
        See Also:
        Constant Field Values
      • MAX_RESULT_BUFFER_HEAP_FRACTION

        private static final double MAX_RESULT_BUFFER_HEAP_FRACTION
        See Also:
        Constant Field Values
      • PERCENT_PHRASES

        private static final java.lang.String[] PERCENT_PHRASES
    • Constructor Detail

      • PGPropertyMaxResultBufferParser

        public PGPropertyMaxResultBufferParser()
    • Method Detail

      • parseProperty

        public static long parseProperty​(java.lang.String value)
                                  throws PSQLException
        Method to parse value of max result buffer size.
        Parameters:
        value - string containing size of bytes with optional multiplier (T, G, M or K) or percent value to declare max percent of heap memory to use.
        Returns:
        value of max result buffer size.
        Throws:
        PSQLException - Exception when given value can't be parsed.
      • parseProperty

        static long parseProperty​(java.lang.String value,
                                  java.util.function.LongSupplier maxHeapBytesSupplier)
                           throws PSQLException
        Throws:
        PSQLException
      • checkIfValueContainsPercent

        private static boolean checkIfValueContainsPercent​(java.lang.String value)
        Method to check if given value can contain percent declaration of size of max result buffer.
        Parameters:
        value - Value to check.
        Returns:
        Result if value contains percent.
      • parseBytePercentValue

        private static long parseBytePercentValue​(java.lang.String value,
                                                  java.util.function.LongSupplier maxHeapBytesSupplier)
                                           throws PSQLException
        Method to get percent value of max result buffer size dependable on actual free memory. This method doesn't check other possibilities of value declaration.
        Parameters:
        value - string containing percent used to define max result buffer.
        Returns:
        percent value of max result buffer size.
        Throws:
        PSQLException - Exception when given value can't be parsed.
      • getPercentPhraseLengthIfContains

        private static int getPercentPhraseLengthIfContains​(java.lang.String valueToCheck)
        Method to get length of percent phrase existing in given string, only if one of phrases exist on the length of string.
        Parameters:
        valueToCheck - String which is gonna be checked if contains percent phrase.
        Returns:
        Length of phrase inside string, returns -1 when no phrase found.
      • getPhraseLengthIfContains

        private static int getPhraseLengthIfContains​(java.lang.String valueToCheck,
                                                     java.lang.String phrase)
        Method to get length of given phrase in given string to check, method checks if phrase exist on the end of given string.
        Parameters:
        valueToCheck - String which gonna be checked if contains phrase.
        phrase - Phrase to be looked for on the end of given string.
        Returns:
        Length of phrase inside string, returns -1 when phrase wasn't found.
      • calculatePercentOfMemory

        private static long calculatePercentOfMemory​(java.lang.String value,
                                                     int percentPhraseLength,
                                                     java.util.function.LongSupplier maxHeapBytesSupplier)
                                              throws PSQLException
        Method to calculate percent of given max heap memory.
        Parameters:
        value - String which contains percent + percent phrase which gonna be used during calculations.
        percentPhraseLength - Length of percent phrase inside given value.
        Returns:
        Size of byte buffer based on percent of max heap memory.
        Throws:
        PSQLException
      • parseByteValue

        private static long parseByteValue​(java.lang.String value)
                                    throws PSQLException
        Method to get size based on given string value. String can contains just a number or number + multiplier sign (like T, G, M or K).
        Parameters:
        value - Given string to be parsed.
        Returns:
        Size based on given string.
        Throws:
        PSQLException - Exception when given value can't be parsed.
      • adjustResultSize

        private static long adjustResultSize​(long value,
                                             java.util.function.LongSupplier maxHeapBytesSupplier)
        Method to adjust result memory limit size. If given memory is larger than 90% of max heap memory then it gonna be reduced to 90% of max heap memory.
        Parameters:
        value - Size to be adjusted.
        Returns:
        Adjusted size (original size or 90% of max heap memory)
      • defaultMaxHeapBytesOrNegativeOne

        private static long defaultMaxHeapBytesOrNegativeOne()
        Default heap-bytes source: routes through JvmHeapAccess, which lives in its own class so the verifier does not need to resolve java.lang.management.ManagementFactory unless this method is actually invoked. On runtimes without java.lang.management (e.g., Android ART), loading JvmHeapAccess throws NoClassDefFoundError on the INVOKESTATIC below; we map that to -1 to signal "max heap unavailable".
      • throwExceptionAboutParsingError

        private static void throwExceptionAboutParsingError​(java.lang.String message,
                                                            java.lang.Object... values)
                                                     throws PSQLException
        Method to throw message for parsing MaxResultBuffer.
        Parameters:
        message - Message to be added to exception.
        values - Values to be put inside exception message.
        Throws:
        PSQLException - Exception when given value can't be parsed.