On Wed, Oct 24, 2018 at 5:35 AM Volkan Yazıcı <volkan.yaz...@gmail.com> wrote:
>
> I am at the edge of making log4j2-logstash-layout gc-free. And at
> this stage my only (GC) obstacle is the aforementioned two classes.
> I need to instantiate them at each encode(LogEvent) call and this
> spoils the entire gc-free magic.
>
> What I can do is create a ThreadLocal parade of 
> ByteBufferOutputStream->JsonGenerator->FilteringGeneratorDelegate.
> This allows me to implement encode() as follows:
>
> get ThreadLocal resources
> reset BBOS
> writeStartObject()
> encode fields
> writeEndObject()
> flip and drain the BBOS to the Log4j BB sink
>
> Though this approach has an unfortunate showstopper: If the 4th step
> leaves the JsonGenerator and/or the FilteringGeneratorDelegate in a
> dirty state -- consider exceeding BBOS capacity, etc. -- all the
> subsequent calls will fail.
>
> I will deeply appreciate any kind of help on this issue.

Ah ok. Thank you for providing more information. This sounds like an
interesting and useful challenge. :)
I like to ask these things ("is that really necessary") first as I
often learn something new.

One thing that may be worth mentioning in case you weren't aware: you
can just leave `JsonGenerator` open:
it does not enforce that content consists of just a single JSON Value.
In fact this is how many stream data generation
(and parsing, via JsonParser) systems work.
There is separate "root value separator" that is used between root
values: it defaults to " " (single space), but may be
reconfigured to, for example, linefeed.

Whether this will work with FilteringGeneratorDelegate is bit
different question.

But do you think that reuse by not closing would work from processing
perspective.

-+ Tatu +-




>
> Best.
>
> On Monday, October 22, 2018 at 6:59:02 AM UTC+2, Tatu Saloranta wrote:
>>
>> On Sun, Oct 21, 2018 at 2:02 PM Volkan Yazıcı <volkan...@gmail.com> wrote:
>> >
>> > Hi,
>> >
>> > I have a JsonGenerator and FilteringGeneratorDelegate usage as follows:
>> >
>> > ByteArrayOutputStream outputStream = threadLocalOutputStreamRef.get();
>> > try (JsonGenerator jsonGenerator = 
>> > jsonFactory.createGenerator(outputStream)) {
>> >     try (JsonGenerator jsonGeneratorDelegate = new 
>> > FilteringGeneratorDelegate(jsonGenerator, tokenFilter, true, true)) {
>> >         // ...
>> >     }
>> > }
>> >
>> > Is it possible to reuse JsonGenerator and FilteringGeneratorDelegate 
>> > instances in a way attached to the local thread context?
>>
>> No, JsonGenerator is designed for use-once life-cycle and does not
>> support reuse.
>> Instances are light-weight so there shouldn't usually be much benefit
>> from attempting to reuse instances; same goes with
>> FilteringGeneratorDelegate.
>>
>> -+ Tatu +-
>
> --
> You received this message because you are subscribed to the Google Groups 
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to