Search in sources :

Example 1 with Message

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();
    }
}
Also used : Header(com.navercorp.pinpoint.io.header.Header) Message(com.navercorp.pinpoint.io.request.Message) DefaultMessage(com.navercorp.pinpoint.io.request.DefaultMessage) ArrayList(java.util.ArrayList) TBase(org.apache.thrift.TBase)

Example 2 with Message

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;
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Message(com.navercorp.pinpoint.io.request.Message) DefaultMessage(com.navercorp.pinpoint.io.request.DefaultMessage) PStatMessage(com.navercorp.pinpoint.grpc.trace.PStatMessage) PAgentStat(com.navercorp.pinpoint.grpc.trace.PAgentStat) PAgentUriStat(com.navercorp.pinpoint.grpc.trace.PAgentUriStat) PStatMessage(com.navercorp.pinpoint.grpc.trace.PStatMessage) StatusError(com.navercorp.pinpoint.grpc.StatusError)

Example 3 with Message

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());
}
Also used : TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) Message(com.navercorp.pinpoint.io.request.Message) Test(org.junit.Test)

Example 4 with Message

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;
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Empty(com.google.protobuf.Empty) PSpanMessage(com.navercorp.pinpoint.grpc.trace.PSpanMessage) PSpan(com.navercorp.pinpoint.grpc.trace.PSpan) Message(com.navercorp.pinpoint.io.request.Message) DefaultMessage(com.navercorp.pinpoint.io.request.DefaultMessage) PSpanMessage(com.navercorp.pinpoint.grpc.trace.PSpanMessage) StatusError(com.navercorp.pinpoint.grpc.StatusError)

Aggregations

Message (com.navercorp.pinpoint.io.request.Message)4 DefaultMessage (com.navercorp.pinpoint.io.request.DefaultMessage)3 StatusError (com.navercorp.pinpoint.grpc.StatusError)2 StreamObserver (io.grpc.stub.StreamObserver)2 Empty (com.google.protobuf.Empty)1 PAgentStat (com.navercorp.pinpoint.grpc.trace.PAgentStat)1 PAgentUriStat (com.navercorp.pinpoint.grpc.trace.PAgentUriStat)1 PSpan (com.navercorp.pinpoint.grpc.trace.PSpan)1 PSpanMessage (com.navercorp.pinpoint.grpc.trace.PSpanMessage)1 PStatMessage (com.navercorp.pinpoint.grpc.trace.PStatMessage)1 Header (com.navercorp.pinpoint.io.header.Header)1 TSpanChunk (com.navercorp.pinpoint.thrift.dto.TSpanChunk)1 ArrayList (java.util.ArrayList)1 TBase (org.apache.thrift.TBase)1 Test (org.junit.Test)1