Log Per Bucketing Strategy
Provides a strategy for "bucketing" a potentially unbounded set of log aggregation keys used by the LoggingApi.per(T, LogPerBucketingStrategy<T>) method.
When implementing new strategies not provided by this class, it is important to ensure that the apply() method returns values from a bounded set of instances wherever possible.
This is important because the returned values are held persistently for potentially many different log sites. If a different instance is returned each time apply() is called, a different instance will be held in each log site. This multiplies the amount of memory that is retained indefinitely by any use of LoggingApi.per(T, LogPerBucketingStrategy<T>).
One way to handle arbitrary key types would be to create a strategy which "interns" instances in some way, to produce singleton identifiers. Unfortunately interning can itself be a cause of unbounded memory leaks, so a bucketing strategy wishing to perform interning should probably support a user defined maximum capacity to limit the overall risk. If too many instances are seen, the strategy should begin to return null (and log an appropriate warning).
The additional complexity created by this approach really tells us that types which require interning in order to be used as aggregation keys should be considered unsuitable, and callers should seek alternatives.
See also
Original Java code of Google Flogger
Constructors
Functions
Class of the given key for log aggregation.Class name of the given key for log aggregation.hashCode() of a given key, modulo maxBuckets, for log aggregation.