/*
 * Copyright 2013 Rackspace
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.rackspacecloud.blueflood.service;

import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.rackspacecloud.blueflood.io.AstyanaxWriter;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Histogram;
import com.yammer.metrics.core.Timer;
import com.yammer.metrics.core.TimerContext;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

public class RollupBatchWriteRunnable  implements Runnable {
    private final RollupExecutionContext executionContext;
    private final ArrayList<SingleRollupWriteContext> writeContexts;
    private static final Histogram rollupsPerBatch = Metrics.newHistogram(RollupService.class, "Rollups Per Batch");
    private static final Timer batchWriteTimer = Metrics.newTimer(RollupService.class, "Rollup Batch Write", TimeUnit.MILLISECONDS, TimeUnit.SECONDS);

    public RollupBatchWriteRunnable(ArrayList<SingleRollupWriteContext> writeContexts, RollupExecutionContext executionContext) {
        this.writeContexts = writeContexts;
        this.executionContext = executionContext;
    }

    @Override
    public void run() {
        TimerContext ctx = batchWriteTimer.time();
        try {
            AstyanaxWriter.getInstance().insertRollups(writeContexts);
        } catch (ConnectionException e) {
            executionContext.markUnsuccessful(e);
        }
        executionContext.decrementWriteCounter(writeContexts.size());
        rollupsPerBatch.update(writeContexts.size());
        RollupService.lastRollupTime.set(System.currentTimeMillis());
        ctx.stop();
    }
}

@@ -661,16 +661,90 @@
 rvice;%0A%0A
+import com.codahale.metrics.Histogram;%0Aimport com.codahale.metrics.Timer;%0A
 import c
@@ -880,221 +880,74 @@
 com.
-yammer.metrics.Metrics;%0Aimport com.yammer.metrics.core.Histogram;%0Aimport com.yammer.metrics.core.Timer;%0Aimport com.yammer.metrics.core.TimerContext;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.concurrent.TimeUni
+rackspacecloud.blueflood.utils.Metrics;%0A%0Aimport java.util.ArrayLis
 t;%0A%0A
@@ -1200,12 +1200,9 @@
 ics.
-newH
+h
 isto
@@ -1310,12 +1310,9 @@
 ics.
-newT
+t
 imer
@@ -1357,49 +1357,8 @@
 ite%22
-, TimeUnit.MILLISECONDS, TimeUnit.SECONDS
 );%0A%0A
@@ -1639,16 +1639,17 @@
    Timer
+.
 Context 

update metrics in file added during upstream merge