Class CounterResolver

  • All Implemented Interfaces:
    EventResolver, TemplateResolver<LogEvent>

    public class CounterResolver
    extends java.lang.Object
    implements EventResolver
    Resolves a number from an internal counter.

    Configuration

     config      = [ start ] , [ overflowing ] , [ stringified ]
     start       = "start" -> number
     overflowing = "overflowing" -> boolean
     stringified = "stringified" -> boolean
     
    Unless provided, start and overflowing are respectively set to zero and true by default.

    When overflowing is set to true, the internal counter is created using a long, which is subject to overflow while incrementing, though garbage-free. Otherwise, a BigInteger is used, which does not overflow, but incurs allocation costs.

    When stringified is enabled, which is set to false by default, the resolved number will be converted to a string.

    Examples

    Resolves a sequence of numbers starting from 0. Once Long.MAX_VALUE is reached, counter overflows to Long.MIN_VALUE.
     {
       "$resolver": "counter"
     }
     
    Resolves a sequence of numbers starting from 1000. Once Long.MAX_VALUE is reached, counter overflows to Long.MIN_VALUE.
     {
       "$resolver": "counter",
       "start": 1000
     }
     
    Resolves a sequence of numbers starting from 0 and keeps on doing as long as JVM heap allows.
     {
       "$resolver": "counter",
       "overflowing": false
     }
     
    • Field Detail

      • delegate

        private final java.util.function.Consumer<JsonWriter> delegate
    • Method Detail

      • createLongResolver

        private static java.util.function.Consumer<JsonWriter> createLongResolver​(java.math.BigInteger start)
      • createBigIntegerResolver

        private static java.util.function.Consumer<JsonWriter> createBigIntegerResolver​(java.math.BigInteger start)
      • createStringBuilderRecycler

        private static Recycler<java.lang.StringBuilder> createStringBuilderRecycler​(EventResolverContext context)
      • trimStringBuilder

        private static void trimStringBuilder​(java.lang.StringBuilder stringBuilder,
                                              int maxLength)
      • createStringifiedLongResolver

        private static java.util.function.Consumer<JsonWriter> createStringifiedLongResolver​(java.math.BigInteger start,
                                                                                             Recycler<java.lang.StringBuilder> stringBuilderRecycler)
      • createStringifiedBigIntegerResolver

        private static java.util.function.Consumer<JsonWriter> createStringifiedBigIntegerResolver​(java.math.BigInteger start,
                                                                                                   Recycler<java.lang.StringBuilder> stringBuilderRecycler)
      • getName

        static java.lang.String getName()