Provide a much cheaper, counter-based way of figuring out when we have to add null samples to an accumulator
Rename getInMemoryTimelineChunk to the more accurate getInMemoryTimelineChunks
Rename getInMemoryTimelineChunk to the more accurate getInMemoryTimelineChunks
This checkin makes batched background db writes work, which we need to
achieve an adequate db insert rate, required for prod deployment.  It
also spreads writes out over the entire collection period, rather than
burst-writing at a single point in the hour.

It also eliminates use of LoadableCache from TimelineEventHandler.  We
don't want the accumulators for a host to ever be evicted, and there
is a downside to the opacity imposed by Loadable cache.

With this checkin, all the unit tests pass.  However, we don't yet
have unit tests for the new background writing functionality, because
all the tests currently write in the foreground.

collector/src/main/java/com/ning/arecibo/collector/guice/CollectorConfig.java:

    Add the attributes that control the background writing:
        int backgroundWriteBatchSize
        TimeSpan backgroundWriteCheckInterval
        TimeSpan backgroundWriteMaxDelay.
        boolean performForegroundWrites

collector/src/main/java/com/ning/arecibo/collector/guice/CollectorModule.java:

    Add method configureBackgroundDBChunkWriter() which hooks up the
    background writer to the lifecycle.

collector/src/main/java/com/ning/arecibo/collector/persistent/TimelineEventHandler.java:

    Make accumulators a ConcurrentHashMap rather than a cache,
    supported by new synchronized method getOrAddHostEventAccumulator(),
    and use the new method in processSamples()

    Remove bogus accumulatorsMonitor, which was only protecting some
    accumulators accesses.

    Use eventCategoryIds in the maps; they are cheaper than the
    strings.

    In getInMemoryTimelineChunks(), include the pending chunks in the
    chunks returned if they fit in the time window.

    Replace the LoadingCache metrics with CounterMetrics, and also
    provide counters for the rest of the functionality.

collector/src/main/java/com/ning/arecibo/collector/resources/HostDataResource.java:

    Log an error if we get an exception writing the StreamingOutput.

collector/src/test/java/com/ning/arecibo/collector/MockTimelineDAO.java:

    The first hostId should be 1, not 0.

collector/src/test/java/com/ning/arecibo/collector/TestEventCollectorServer.java:

    Use the injected BackgroundDBChunkWriter.

collector/src/test/java/com/ning/arecibo/collector/TestModulesFactory.java:

    Cause the BackgroundDBChunkWriter to write in the foreground for
    tests, if the relevant property is not set, because otherwise the
    tests have to have sleeps in them.

collector/src/test/java/com/ning/arecibo/collector/TestTimelineHostEventAccumulator.java:

    Import change for the move of TimelineHostEventAccumulator.

collector/src/test/java/com/ning/arecibo/collector/persistent/TestTimelineAggregator.java:
collector/src/test/java/com/ning/arecibo/collector/process/TestSamplesReplayer.java:

    Call accumulator method extractAndQueueTimelineChunks()
    rather than extractAndSaveTimelineChunks()

collector/src/test/java/com/ning/arecibo/collector/persistent/TestTimelineEventHandler.java:
collector/src/test/java/com/ning/arecibo/collector/process/TestInMemoryCollectorEventProcessor.java:
collector/src/test/java/com/ning/arecibo/collector/process/TestFileBackedBuffer.java:

    Supply new BackgroundDBChunkWriter arg to TimlineEventHandler
    constructor.

collector/src/test/java/com/ning/arecibo/collector/process/TestCollectorEventProcessor.java:

    Supply new BackgroundDBChunkWriter arg to TimlineEventHandler
    constructor.

    Comment out a few asserts that only make sense in the face of
    cache eviction of accumulators, which we no longer do.

collector/src/test/java/com/ning/arecibo/collector/resources/TestHostDataResource.java

    Supply BackgroundDBChunkWriter arg; use extractAndQueueTimelineChunks();
    in sendSamples(), call getOrAddHostEventAccumulator() rather than new'ing one.

util/src/main/java/com/ning/arecibo/util/timeline/HostTimelines.java:

    Unused; deleted.

util/src/main/java/com/ning/arecibo/util/timeline/TimelineChunkAccumulator.java:

    Add some debug logging.

util/src/main/java/com/ning/arecibo/util/timeline/TimelineHostEventAccumulator.java:
collector/src/main/java/com/ning/arecibo/collector/persistent/TimelineHostEventAccumulator.java:

    Move TimelineHostEventAccumulator from util to collector, because it needs
    to access the background writer.

util/src/main/resources/com/ning/arecibo/util/timeline/persistent/TimelineDAOQueries.sql.stg:

    Fix bug in bulkInsertTimelineChunks template.

collector/src/main/java/com/ning/arecibo/collector/persistent/BackgroundDBChunkWriter.java:

    New unit

collector/src/main/java/com/ning/arecibo/collector/persistent/PendingChunkMap.java:

    New class to hold the TimelineChunks for one host event category
    and time.