Search in sources :

Example 1 with Recycler

use of org.apache.logging.log4j.layout.template.json.util.Recycler in project logging-log4j2 by apache.

the class CounterResolver method createStringifiedLongResolver.

private static Consumer<JsonWriter> createStringifiedLongResolver(final BigInteger start, final Recycler<StringBuilder> stringBuilderRecycler) {
    final long effectiveStart = start.longValue();
    final AtomicLong counter = new AtomicLong(effectiveStart);
    return (jsonWriter) -> {
        final long number = counter.getAndIncrement();
        final StringBuilder stringBuilder = stringBuilderRecycler.acquire();
        try {
            stringBuilder.append(number);
            jsonWriter.writeString(stringBuilder);
        } finally {
            stringBuilderRecycler.release(stringBuilder);
        }
    };
}
Also used : LockSupport(java.util.concurrent.locks.LockSupport) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) BigInteger(java.math.BigInteger) Recycler(org.apache.logging.log4j.layout.template.json.util.Recycler) LogEvent(org.apache.logging.log4j.core.LogEvent) JsonWriter(org.apache.logging.log4j.layout.template.json.util.JsonWriter) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

BigInteger (java.math.BigInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LockSupport (java.util.concurrent.locks.LockSupport)1 Consumer (java.util.function.Consumer)1 LogEvent (org.apache.logging.log4j.core.LogEvent)1 JsonWriter (org.apache.logging.log4j.layout.template.json.util.JsonWriter)1 Recycler (org.apache.logging.log4j.layout.template.json.util.Recycler)1