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

Add close() to Emitter interface and Tracker #357

Closed mscwilson closed 2 years ago

mscwilson commented 2 years ago

A Snowplow interface was added in #340. This class contains static methods for creating and managing Trackers, without needing to create other objects first. The internal classes of the tracker - BatchEmitter or Subject - can be created behind-the-scenes, or via Configuration objects.

The BatchEmitter is the default Emitter; it uses a thread pool to asynchronously process and send events. The threads are non-daemon threads. To safely shut down the tracker, the BatchEmitter contains a close() method, which attempts to send all remaining buffered events and then terminates the thread pool executor.

The close() method is not part of the Emitter interface. This makes it clumsy and non-intuitive to stop a tracker:

BatchEmitter emitter = (BatchEmitter) tracker.getEmitter();
emitter.close();

Ideally it would be:

tracker.getEmitter().close();

Or even better:

tracker.close();

This can be achieved by updating the Emitter interface and also adding close() to the Tracker class.