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
23 stars 36 forks source link

Restore Emitter callbacks for success and failure (close #339) #348

Closed mscwilson closed 2 years ago

mscwilson commented 2 years ago

For issue #339.

Allows users to provide callbacks to BatchEmitter. The success callback will be called after a request is successfully sent. The failure callback will be called after a request gets a response code other than 2xx, or if the emitter's storage is full.

A new EmitterCallback interface is provided for the callbacks, along with a new enum, FailureType, for the failure callback. The three possible failures are: CONNECTION_FAILURE (exceptions during event sending); REJECTED_BY_COLLECTOR (non-2xx HTML request codes); or TRACKER_STORAGE_FULL.

Events are added to the storage in two places, therefore the TRACKER_STORAGE_FULL can occur in two places. The standard occasion is when new events are added to the BatchEmitter by the Tracker object. However, if events fail to send and should be retried, they are added back into the storage queue inside the InMemoryEventStore. If the queue is full, newer events are removed and deleted to make space for the returning older events.

This means that the EmitterCallback should be shared across BatchEmitter and InMemoryEventStore. I added a Builder to InMemoryEventStore to avoid having a confusing collection of constructors.