// Path: src/main/java/org/killbill/billing/plugin/meter/timeline/samples/SampleBase.java
// public abstract class SampleBase {
// 
//     protected final SampleOpcode opcode;
// 
//     public SampleBase(final SampleOpcode opcode) {
//         this.opcode = opcode;
//     }
// 
//     public SampleOpcode getOpcode() {
//         return opcode;
//     }
// }


import java.io.IOException;
import org.joda.time.DateTime;
import org.killbill.billing.plugin.meter.timeline.chunks.TimelineChunk;
import org.killbill.billing.plugin.meter.timeline.samples.SampleBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
 * Copyright 2010-2014 Ning, Inc.
 * Copyright 2014 The Billing Project, LLC
 *
 * Ning licenses this file to you 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 org.killbill.billing.plugin.meter.timeline.codec;



/**
 * This class represents a sequence of values for a single attribute,
 * e.g., "TP99 Response Time", for one source and one specific time range,
 * as the object is being accumulated.  It is not used to represent
 * past timeline sequences; they are held in TimelineChunk objects.
 * <p/>
 * It accumulates samples in a byte array object. Readers can call
 * getEncodedSamples() at any time to get the latest data.
 */
public class TimelineChunkAccumulator extends SampleAccumulator {

    private static final Logger log = LoggerFactory.getLogger(TimelineChunkAccumulator.class);
    private final int sourceId;
    private final int metricId;

    public TimelineChunkAccumulator(final int sourceId, final int metricId, final SampleCoder sampleCoder) {
        super(sampleCoder);
        this.sourceId = sourceId;
        this.metricId = metricId;
    }

// Path: src/main/java/org/killbill/billing/plugin/meter/timeline/samples/SampleBase.java
// public abstract class SampleBase {
// 
//     protected final SampleOpcode opcode;
// 
//     public SampleBase(final SampleOpcode opcode) {
//         this.opcode = opcode;
//     }
// 
//     public SampleOpcode getOpcode() {
//         return opcode;
//     }
// }


// Path: src/main/java/org/killbill/billing/plugin/meter/timeline/codec/TimelineChunkAccumulator.java
import java.io.IOException;
import org.joda.time.DateTime;
import org.killbill.billing.plugin.meter.timeline.chunks.TimelineChunk;
import org.killbill.billing.plugin.meter.timeline.samples.SampleBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * Copyright 2010-2014 Ning, Inc.
 * Copyright 2014 The Billing Project, LLC
 *
 * Ning licenses this file to you 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 org.killbill.billing.plugin.meter.timeline.codec;



/**
 * This class represents a sequence of values for a single attribute,
 * e.g., "TP99 Response Time", for one source and one specific time range,
 * as the object is being accumulated.  It is not used to represent
 * past timeline sequences; they are held in TimelineChunk objects.
 * <p/>
 * It accumulates samples in a byte array object. Readers can call
 * getEncodedSamples() at any time to get the latest data.
 */
public class TimelineChunkAccumulator extends SampleAccumulator {

    private static final Logger log = LoggerFactory.getLogger(TimelineChunkAccumulator.class);
    private final int sourceId;
    private final int metricId;

    public TimelineChunkAccumulator(final int sourceId, final int metricId, final SampleCoder sampleCoder) {
        super(sampleCoder);
        this.sourceId = sourceId;
        this.metricId = metricId;
    }

    private TimelineChunkAccumulator(final int sourceId, final int metricId, final byte[] bytes, final SampleBase lastSample, final int sampleCount, final SampleCoder sampleCoder) throws IOException {