Support for creating TrackerPayload asynchronously (close #222)#226
Conversation
|
There are two possible options for Option 1: Will block on Option 2: Will not block on I've switched to Option 2, whilst either scenario is unlikely, I believe this is most similar to previous behaviour and the risk of tracking impacting the main purpose of the application doesn't feel like the right choice. |
|
Made the changes based on your suggestions. Nice ideas! Removing the payload cache also had an unintended consequence in that that cache accidently made the BatchEmiiterTests pass, as the STM parameter was added to the cached payload reference when in reality it shouldn't have been added to these caches payloads. I've also removed the ability to mutate the tracker properties once the tracker has been constructed (small breaking API change but this is 0.x). This seems particularly important now that the payloads are created asynchronously and changing tracker parameters could lead to events already passed to the tracker ended up being created based on parameters that have been adjusted after they have been passed to the tradcker. If users want to change tracker parameters, we will suggest constructing a new instance of Tracker using the TrackerBuilder. |
Ian Streeter (istreeter)
left a comment
There was a problem hiding this comment.
Looks very neat now. No more comments to add 👍
This PR was initially based on and takes inspiration from the fork within issue #222.
I've removed the need for a new API method and I've made the async payload creation the default behaviour when using
Tracker.track().I've also gone a little beyond simply moving the payload, I've also improved the asynchronous behaviour of the Tracker so that we can remove the syhconrized keyword from the
BatchEmiiter.emit()method. This was tricky to solve due to the relationship betweenemit(),flushBufferandclose(), in the end I've ended up with two LinkedBlockingQueues, in a producer (emit()) and consumer (getBufferConsumerRunnable()) model, that I believe will give better throughput and if nothing else allows theemit()method to return much quicker, so the host application can continue with it's work and not have to wait for thejava-tracker. I've done quite a bit of testing of this but if you see (or even fear) any potential pitfalls then please let me know.There is also one breaking API change with the release. Rather than exposing the internal
TrackerPayloadon the API, I now have the ability to return the originalEventso that is what I've done. This means the standardtrack(Event)method can be used to retry failed sends.I've left my commit stream intact, I'll rebase this before merging into the release branch.