keenlabs / KeenClient-Java

Official Java client for the Keen IO API. Build analytics features directly into your Java apps.
https://keen.io/docs
MIT License
74 stars 43 forks source link

Add shutdown method to shutdown the thread pool. #4

Closed karlvr closed 11 years ago

karlvr commented 11 years ago

Fixes issue #3.

karlvr commented 11 years ago

To use this in a webapp you should have a class like follows:

@WebListener
public class Tracking implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent evt) {
        KeenClient.client().shutdown(20000);
    }

    @Override
    public void contextInitialized(ServletContextEvent evt) {

    }
}
dkador commented 11 years ago

A couple things:

1.) Can you fix the formatting / tabs of the shutdown() method? Looks a bit wonky. 2.) Don't swallow the InterruptedException. Either throw it or wrap it in a new exception. Or, at the very very least, log it. 3.) Can we get a unit test for this?

karlvr commented 11 years ago

There's some updates for you. To get good testing going suggested that KeenClient would need to recover from a shutdown. So I've implemented that. That has resulted in some more invasive changes than I like to make to other people's code. It is a result of the static nature of EXECUTOR_SERVICE.

dkador commented 11 years ago

Merged.