use of com.navercorp.pinpoint.io.request.Message in project pinpoint by naver.
the class ChunkHeaderTBaseDeserializer method deserialize.
public List<Message<TBase<?, ?>>> deserialize(byte[] bytes, int offset, int length) throws TException {
try {
trans.reset(bytes, offset, length);
Header header = readHeader();
if (locator.isSupport(header.getType())) {
List<Message<TBase<?, ?>>> list = new ArrayList<Message<TBase<?, ?>>>();
while (trans.getBytesRemainingInBuffer() > 0) {
final Message<TBase<?, ?>> request = readInternal();
list.add(request);
}
return list;
} else {
final Message<TBase<?, ?>> request = readInternal();
if (request == null) {
return Collections.emptyList();
}
List<Message<TBase<?, ?>>> list = new ArrayList<Message<TBase<?, ?>>>();
list.add(request);
return list;
}
} finally {
trans.clear();
protocol.reset();
}
}
use of com.navercorp.pinpoint.io.request.Message in project pinpoint by naver.
the class StatService method sendAgentStat.
@Override
public StreamObserver<PStatMessage> sendAgentStat(StreamObserver<Empty> responseObserver) {
StreamObserver<PStatMessage> observer = new StreamObserver<PStatMessage>() {
@Override
public void onNext(PStatMessage statMessage) {
if (isDebug) {
logger.debug("Send PAgentStat={}", MessageFormatUtils.debugLog(statMessage));
}
if (statMessage.hasAgentStat()) {
final Message<PAgentStat> message = newMessage(statMessage.getAgentStat(), DefaultTBaseLocator.AGENT_STAT);
send(message, responseObserver);
} else if (statMessage.hasAgentStatBatch()) {
final Message<PAgentStatBatch> message = newMessage(statMessage.getAgentStatBatch(), DefaultTBaseLocator.AGENT_STAT_BATCH);
send(message, responseObserver);
} else if (statMessage.hasAgentUriStat()) {
final Message<PAgentUriStat> message = newMessage(statMessage.getAgentUriStat(), DefaultTBaseLocator.AGENT_URI_STAT);
send(message, responseObserver);
} else {
if (isDebug) {
logger.debug("Found empty stat message {}", MessageFormatUtils.debugLog(statMessage));
}
}
}
@Override
public void onError(Throwable throwable) {
final StatusError statusError = StatusErrors.throwable(throwable);
if (statusError.isSimpleError()) {
logger.info("Failed to stat stream, cause={}", statusError.getMessage());
} else {
logger.warn("Failed to stat stream, cause={}", statusError.getMessage(), statusError.getThrowable());
}
}
@Override
public void onCompleted() {
com.navercorp.pinpoint.grpc.Header header = ServerContext.getAgentInfo();
logger.info("onCompleted {}", header);
responseObserver.onNext(Empty.newBuilder().build());
responseObserver.onCompleted();
}
};
return observer;
}
use of com.navercorp.pinpoint.io.request.Message in project pinpoint by naver.
the class ChunkHeaderTBaseDeserializerTest method deserialize.
@Test
public void deserialize() throws Exception {
final ChunkHeaderTBaseDeserializer deserializer = new ChunkHeaderTBaseDeserializer(DEFAULT_PROTOCOL_FACTORY, DEFAULT_TBASE_LOCATOR);
UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream();
ChunkHeaderBufferedTBaseSerializer serializer = new ChunkHeaderBufferedTBaseSerializer(out, DEFAULT_PROTOCOL_FACTORY, DEFAULT_TBASE_LOCATOR);
TSpanChunk chunk = new TSpanMockBuilder().buildChunk(3, 10);
serializer.add(chunk);
List<Message<TBase<?, ?>>> list = deserializer.deserialize(serializer.getTransport().getBuffer(), 0, serializer.getTransport().getBufferPosition());
assertEquals(1, list.size());
TSpanChunk result = (TSpanChunk) list.get(0).getData();
assertEquals(3, result.getSpanEventList().size());
}
use of com.navercorp.pinpoint.io.request.Message in project pinpoint by naver.
the class SpanService method sendSpan.
@Override
public StreamObserver<PSpanMessage> sendSpan(final StreamObserver<Empty> responseObserver) {
StreamObserver<PSpanMessage> observer = new StreamObserver<PSpanMessage>() {
@Override
public void onNext(PSpanMessage spanMessage) {
if (isDebug) {
logger.debug("Send PSpan={}", MessageFormatUtils.debugLog(spanMessage));
}
if (spanMessage.hasSpan()) {
final Message<PSpan> message = newMessage(spanMessage.getSpan(), DefaultTBaseLocator.SPAN);
send(message, responseObserver);
} else if (spanMessage.hasSpanChunk()) {
final Message<PSpanChunk> message = newMessage(spanMessage.getSpanChunk(), DefaultTBaseLocator.SPANCHUNK);
send(message, responseObserver);
} else {
if (isDebug) {
logger.debug("Found empty span message {}", MessageFormatUtils.debugLog(spanMessage));
}
}
}
@Override
public void onError(Throwable throwable) {
com.navercorp.pinpoint.grpc.Header header = ServerContext.getAgentInfo();
final StatusError statusError = StatusErrors.throwable(throwable);
if (statusError.isSimpleError()) {
logger.info("Failed to span stream, {} cause={}", header, statusError.getMessage(), statusError.getThrowable());
} else {
logger.warn("Failed to span stream, {} cause={}", header, statusError.getMessage(), statusError.getThrowable());
}
}
@Override
public void onCompleted() {
com.navercorp.pinpoint.grpc.Header header = ServerContext.getAgentInfo();
logger.info("onCompleted {}", header);
Empty empty = Empty.newBuilder().build();
responseObserver.onNext(empty);
responseObserver.onCompleted();
}
};
return observer;
}
Aggregations