use of com.navercorp.pinpoint.profiler.sender.SpanStreamSendData in project pinpoint by naver.
the class AbstractSpanStreamSendDataPlaner method getSendDataIterator.
@Override
public Iterator<SpanStreamSendData> getSendDataIterator(SpanStreamSendData spanStreamSendData, HeaderTBaseSerializer serializer) throws IOException {
logger.info("process");
List<SpanStreamSendData> spanStreamSendDataList = new ArrayList<SpanStreamSendData>();
SpanStreamSendData currentSpanStreamSendData = spanStreamSendData;
FlushMode mode = plan(spanStreamSendData);
if (mode == FlushMode.FLUSH_FIRST) {
spanStreamSendDataList.add(currentSpanStreamSendData);
currentSpanStreamSendData.setFlushMode(SpanStreamSendDataMode.WAIT_BUFFER_AND_FLUSH);
currentSpanStreamSendData = spanStreamSendDataFactory.create();
}
int byteBufferCapacity = partitionedByteBufferLocator.getTotalByteBufferCapacity();
if (currentSpanStreamSendData.isAvailableBufferCapacity(byteBufferCapacity)) {
if (currentSpanStreamSendData.getAvailableGatheringComponentsCount() < 2) {
currentSpanStreamSendData.setFlushMode();
}
currentSpanStreamSendData.addBuffer(partitionedByteBufferLocator.getByteBuffer(), serializer);
spanStreamSendDataList.add(currentSpanStreamSendData);
} else {
int markFromPartitionIndex = 0;
int markToPartitionIndex = -1;
int flushBufferCapacity = 0;
for (int i = 0; i < partitionedByteBufferLocator.getPartitionedCount(); i++) {
int appendBufferSize = 0;
if (!partitionedByteBufferLocator.isLastPartitionIndex(i)) {
appendBufferSize = getSpanChunkLength();
}
flushBufferCapacity += partitionedByteBufferLocator.getByteBufferCapacity(i);
if (needFlush(currentSpanStreamSendData, flushBufferCapacity, appendBufferSize)) {
ByteBuffer addBuffer = getByteBuffer(partitionedByteBufferLocator, markFromPartitionIndex, markToPartitionIndex);
if (addBuffer != null) {
ByteBuffer[] byteBufferArray = new ByteBuffer[2];
byteBufferArray[0] = addBuffer;
byteBufferArray[1] = getSpanChunkBuffer();
currentSpanStreamSendData.addBuffer(byteBufferArray);
}
currentSpanStreamSendData.setFlushMode();
spanStreamSendDataList.add(currentSpanStreamSendData);
currentSpanStreamSendData = spanStreamSendDataFactory.create();
markFromPartitionIndex = i;
flushBufferCapacity = partitionedByteBufferLocator.getByteBufferCapacity(i);
}
markToPartitionIndex = i;
if (partitionedByteBufferLocator.isLastPartitionIndex(i)) {
ByteBuffer addBuffer = getByteBuffer(partitionedByteBufferLocator, markFromPartitionIndex, markToPartitionIndex);
currentSpanStreamSendData.addBuffer(addBuffer, serializer);
spanStreamSendDataList.add(currentSpanStreamSendData);
}
}
}
return spanStreamSendDataList.iterator();
}
use of com.navercorp.pinpoint.profiler.sender.SpanStreamSendData in project pinpoint by naver.
the class SpanChunkStreamSendDataPlanerTest method getSpanEventList.
private List<TSpanEvent> getSpanEventList(PartitionedByteBufferLocator spanData, SpanStreamSendDataFactory factory) throws Exception {
List<TSpanEvent> spanEventList = new ArrayList<TSpanEvent>();
SpanChunkStreamSendDataPlaner planer = new SpanChunkStreamSendDataPlaner(spanData, factory);
Iterator<SpanStreamSendData> iterator = planer.getSendDataIterator();
while (iterator.hasNext()) {
SpanStreamSendData data = iterator.next();
ByteBuffer[] sendBuffers = data.getSendBuffers();
byte[] relatedBuffer = getSpanRelatedBuffer(sendBuffers);
List<TSpanEvent> result = deserialize(relatedBuffer);
for (TSpanEvent spanEvent : result) {
spanEventList.add(spanEvent);
}
}
return spanEventList;
}
use of com.navercorp.pinpoint.profiler.sender.SpanStreamSendData in project pinpoint by naver.
the class SpanStreamSendDataPlanerTest method getSpanEventList.
private List<TSpanEvent> getSpanEventList(PartitionedByteBufferLocator partitionedByteBufferLocator, SpanStreamSendDataFactory factory) throws Exception {
List<TSpanEvent> spanEventList = new ArrayList<TSpanEvent>();
SpanChunkStreamSendDataPlaner planer = new SpanChunkStreamSendDataPlaner(partitionedByteBufferLocator, factory);
Iterator<SpanStreamSendData> iterator = planer.getSendDataIterator();
while (iterator.hasNext()) {
SpanStreamSendData data = iterator.next();
ByteBuffer[] sendBuffers = data.getSendBuffers();
byte[] relatedBuffer = getSpanRelatedBuffer(sendBuffers);
List<TSpanEvent> result = deserialize(relatedBuffer);
for (TSpanEvent spanEvent : result) {
spanEventList.add(spanEvent);
}
}
return spanEventList;
}
Aggregations