Search in sources :

Example 11 with AgentStatDataPointCodec

use of com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec in project pinpoint by naver.

the class TransactionCodecTest method encodeValuesTest.

@Test
public void encodeValuesTest() {
    final String id = "test_app";
    final long currentTime = new Date().getTime();
    TransactionCodec transactionCodec = new TransactionCodec(new AgentStatDataPointCodec());
    final Buffer encodedValueBuffer = new AutomaticBuffer();
    final List<JoinStatBo> joinTransactionBoList = createJoinTransactionBoList(currentTime);
    encodedValueBuffer.putByte(transactionCodec.getVersion());
    transactionCodec.encodeValues(encodedValueBuffer, joinTransactionBoList);
    final Buffer valueBuffer = new FixedBuffer(encodedValueBuffer.getBuffer());
    final long baseTimestamp = AgentStatUtils.getBaseTimestamp(currentTime);
    final long timestampDelta = currentTime - baseTimestamp;
    final ApplicationStatDecodingContext decodingContext = new ApplicationStatDecodingContext();
    decodingContext.setApplicationId(id);
    decodingContext.setBaseTimestamp(baseTimestamp);
    decodingContext.setTimestampDelta(timestampDelta);
    assertEquals(valueBuffer.readByte(), transactionCodec.getVersion());
    List<JoinStatBo> decodedJoinTransactionBoList = transactionCodec.decodeValues(valueBuffer, decodingContext);
    for (int i = 0; i < decodedJoinTransactionBoList.size(); i++) {
        assertEquals(decodedJoinTransactionBoList.get(i), joinTransactionBoList.get(i));
    }
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) ApplicationStatDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.stat.ApplicationStatDecodingContext) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) JoinStatBo(com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo) Date(java.util.Date) AgentStatDataPointCodec(com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec) Test(org.junit.Test)

Example 12 with AgentStatDataPointCodec

use of com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec in project pinpoint by naver.

the class AgentStatCodecV2 method decodeValues.

@Override
public List<T> decodeValues(Buffer valueBuffer, AgentStatDecodingContext decodingContext) {
    final String agentId = decodingContext.getAgentId();
    final long baseTimestamp = decodingContext.getBaseTimestamp();
    final long timestampDelta = decodingContext.getTimestampDelta();
    final long initialTimestamp = baseTimestamp + timestampDelta;
    int numValues = valueBuffer.readVInt();
    final AgentStatDataPointCodec codec = codecFactory.getCodec();
    List<Long> startTimestamps = codec.decodeValues(valueBuffer, UnsignedLongEncodingStrategy.REPEAT_COUNT, numValues);
    List<Long> timestamps = codec.decodeTimestamps(initialTimestamp, valueBuffer, numValues);
    CodecDecoder<T> codecDecoder = codecFactory.createCodecDecoder();
    // decode headers
    final byte[] header = valueBuffer.readPrefixedBytes();
    AgentStatHeaderDecoder headerDecoder = new BitCountingHeaderDecoder(header);
    codecDecoder.decode(valueBuffer, headerDecoder, numValues);
    List<T> result = new ArrayList<T>(numValues);
    for (int i = 0; i < numValues; i++) {
        T newObject = codecDecoder.getValue(i);
        newObject.setAgentId(agentId);
        newObject.setStartTimestamp(startTimestamps.get(i));
        newObject.setTimestamp(timestamps.get(i));
        result.add(newObject);
    }
    return result;
}
Also used : BitCountingHeaderDecoder(com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderDecoder) ArrayList(java.util.ArrayList) AgentStatDataPoint(com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint) AgentStatDataPointCodec(com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec) AgentStatHeaderDecoder(com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder)

Aggregations

AgentStatDataPointCodec (com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec)12 AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)10 Buffer (com.navercorp.pinpoint.common.buffer.Buffer)10 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)10 ApplicationStatDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.stat.ApplicationStatDecodingContext)10 JoinStatBo (com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo)10 Date (java.util.Date)10 Test (org.junit.Test)10 AgentStatDataPoint (com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint)2 ArrayList (java.util.ArrayList)2 AgentStatHeaderDecoder (com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder)1 BitCountingHeaderDecoder (com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderDecoder)1