snowplow / snowplow-java-tracker

Snowplow event tracker for Java. Add analytics to your Java desktop and server apps, servlets and games. (See also: snowplow-android-tracker)
http://snowplowanalytics.com
Apache License 2.0
24 stars 36 forks source link

Extract event storage from Emitter (close #290) #292

Closed mscwilson closed 2 years ago

mscwilson commented 2 years ago

I created an EventStore interface, and an InMemoryEventStore implementation. I moved the two event buffer queues from Emitter into InMemoryEventStore.

The Emitter previously had a thread (bufferConsumer) with two functions: transferring events from the first queue into the eventsToSend queue, and then checking the size of eventsToSend against bufferSize to see if there was a whole batch's worth of events yet. I moved the first part of this functionality into a bufferConsumer thread in InMemoryEventStore. The size checking stayed in Emitter, but the thread is now called areThereEventsToSend.

I also found the queue names eventsBuffer and eventsToSend confusing, since many Emitter methods referred to buffer but meant eventsToSend. I renamed them eventInitialBuffer and eventStagingBuffer. There're still some places where it would be good to get more clarity. In the Android tracker, which uses an SQLite database, instead of "initialBuffer" there's eventWaitingList. But that is an actual (Array)List.

Currently the InMemoryEventStore bufferConsumer thread can't be stopped.

Also I have accidentally included some changes in Tracker! I was initially playing around with stuff for a different Issue.