Search in sources :

Example 1 with StreamResponsePacket

use of com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket in project pinpoint by naver.

the class PinpointGrpcServer method handleStreamMessage.

public void handleStreamMessage(int streamId, GeneratedMessageV3 message) throws StreamException {
    if (logger.isDebugEnabled()) {
        logger.debug("handleStreamMessage() streamId:{}, message:{}", streamId, MessageFormatUtils.debugLog(message));
    }
    GrpcClientStreamChannel streamChannel = (GrpcClientStreamChannel) streamChannelRepository.getStreamChannel(streamId);
    if (streamChannel == null) {
        throw new StreamException(StreamCode.ID_NOT_FOUND, "Can't find suitable streamChannel.(streamId:" + streamId + ")");
    }
    TBase<?, ?> tBase = messageConverter.toMessage(message);
    if (tBase == null) {
        throw new StreamException(StreamCode.TYPE_ERROR, "Failed to convert message.(message:" + MessageFormatUtils.debugLog(message).toString() + ")");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("handleStreamMessage() streamId:{}, message:{}", streamId, tBase);
    }
    try {
        byte[] serialize = SerializationUtils.serialize(tBase, commandHeaderTBaseSerializerFactory);
        streamChannel.handleStreamResponsePacket(new StreamResponsePacket(streamId, serialize));
    } catch (TException t) {
        throw new StreamException(StreamCode.TYPE_UNKNOWN, "Failed to serialize message.(tBase:" + tBase + ")");
    } catch (StreamException e) {
        throw e;
    }
}
Also used : TException(org.apache.thrift.TException) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException) StreamResponsePacket(com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket)

Example 2 with StreamResponsePacket

use of com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket in project pinpoint by pinpoint-apm.

the class ServerStreamChannel method sendData.

public void sendData(byte[] payload) {
    StreamResponsePacket packet = new StreamResponsePacket(getStreamId(), payload);
    write(StreamChannelStateCode.CONNECTED, packet);
}
Also used : StreamResponsePacket(com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket)

Example 3 with StreamResponsePacket

use of com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket in project pinpoint by pinpoint-apm.

the class PinpointGrpcServer method handleStreamMessage.

public void handleStreamMessage(int streamId, GeneratedMessageV3 message) throws StreamException {
    if (logger.isDebugEnabled()) {
        logger.debug("handleStreamMessage() streamId:{}, message:{}", streamId, MessageFormatUtils.debugLog(message));
    }
    GrpcClientStreamChannel streamChannel = (GrpcClientStreamChannel) streamChannelRepository.getStreamChannel(streamId);
    if (streamChannel == null) {
        throw new StreamException(StreamCode.ID_NOT_FOUND, "Can't find suitable streamChannel.(streamId:" + streamId + ")");
    }
    TBase<?, ?> tBase = messageConverter.toMessage(message);
    if (tBase == null) {
        throw new StreamException(StreamCode.TYPE_ERROR, "Failed to convert message.(message:" + MessageFormatUtils.debugLog(message).toString() + ")");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("handleStreamMessage() streamId:{}, message:{}", streamId, tBase);
    }
    try {
        byte[] serialize = SerializationUtils.serialize(tBase, commandHeaderTBaseSerializerFactory);
        streamChannel.handleStreamResponsePacket(new StreamResponsePacket(streamId, serialize));
    } catch (TException t) {
        throw new StreamException(StreamCode.TYPE_UNKNOWN, "Failed to serialize message.(tBase:" + tBase + ")");
    } catch (StreamException e) {
        throw e;
    }
}
Also used : TException(org.apache.thrift.TException) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException) StreamResponsePacket(com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket)

Example 4 with StreamResponsePacket

use of com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket in project pinpoint by naver.

the class GrpcClientStreamChannelTest method simpleTest.

@Test
public void simpleTest() throws StreamException, InterruptedException {
    StreamChannelRepository streamChannelRepository = new StreamChannelRepository();
    RecordClientStreamChannelEventHandler recordStreamChannelHandler = new RecordClientStreamChannelEventHandler();
    GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(mockRemoteAddress, 20, streamChannelRepository, recordStreamChannelHandler);
    Assert.assertEquals(StreamChannelStateCode.NEW, grpcClientStreamChannel.getCurrentState());
    grpcClientStreamChannel.init();
    Assert.assertEquals(StreamChannelStateCode.OPEN, grpcClientStreamChannel.getCurrentState());
    Assert.assertEquals(1, streamChannelRepository.size());
    CountDownLatch connectCompleteLatch = new CountDownLatch(1);
    CountDownLatch threadCompleteLatch = connect(grpcClientStreamChannel, connectCompleteLatch);
    final AtomicInteger callCompletedCount = new AtomicInteger(0);
    grpcClientStreamChannel.setConnectionObserver(new StreamObserver<Empty>() {

        @Override
        public void onNext(Empty value) {
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onCompleted() {
            callCompletedCount.incrementAndGet();
        }
    });
    Assert.assertTrue(connectCompleteLatch.await(1000, TimeUnit.MILLISECONDS));
    Assert.assertEquals(StreamChannelStateCode.CONNECT_AWAIT, grpcClientStreamChannel.getCurrentState());
    grpcClientStreamChannel.changeStateConnected();
    Assert.assertEquals(StreamChannelStateCode.CONNECTED, grpcClientStreamChannel.getCurrentState());
    Assert.assertTrue(threadCompleteLatch.await(1000, TimeUnit.MILLISECONDS));
    String message = "hello";
    grpcClientStreamChannel.handleStreamResponsePacket(new StreamResponsePacket(1, message.getBytes()));
    Assert.assertEquals(message, new String(recordStreamChannelHandler.getLastStreamResponsePacket().getPayload()));
    Assert.assertEquals(0, callCompletedCount.get());
    grpcClientStreamChannel.handleStreamClosePacket(new StreamClosePacket(1, StreamCode.STATE_CLOSED));
    Assert.assertEquals(0, streamChannelRepository.size());
    Assert.assertEquals(StreamChannelStateCode.CLOSED, grpcClientStreamChannel.getCurrentState());
    Assert.assertEquals(1, callCompletedCount.get());
    // do nothing
    grpcClientStreamChannel.disconnect();
    Assert.assertEquals(1, callCompletedCount.get());
    grpcClientStreamChannel.close();
    Assert.assertEquals(1, callCompletedCount.get());
}
Also used : Empty(com.google.protobuf.Empty) StreamClosePacket(com.navercorp.pinpoint.rpc.packet.stream.StreamClosePacket) StreamChannelRepository(com.navercorp.pinpoint.rpc.stream.StreamChannelRepository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) StreamResponsePacket(com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket) Test(org.junit.Test)

Example 5 with StreamResponsePacket

use of com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket in project pinpoint by naver.

the class ServerStreamChannel method sendData.

public void sendData(byte[] payload) {
    StreamResponsePacket packet = new StreamResponsePacket(getStreamId(), payload);
    write(StreamChannelStateCode.CONNECTED, packet);
}
Also used : StreamResponsePacket(com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket)

Aggregations

StreamResponsePacket (com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket)6 Empty (com.google.protobuf.Empty)2 StreamClosePacket (com.navercorp.pinpoint.rpc.packet.stream.StreamClosePacket)2 StreamChannelRepository (com.navercorp.pinpoint.rpc.stream.StreamChannelRepository)2 StreamException (com.navercorp.pinpoint.rpc.stream.StreamException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 TException (org.apache.thrift.TException)2 Test (org.junit.Test)2