Search in sources :

Example 6 with StreamException

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

the class GrpcClientStreamChannelTest method connectTimeoutTest.

@Test
public void connectTimeoutTest() throws StreamException {
    GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(mockRemoteAddress, 20, new StreamChannelRepository(), ClientStreamChannelEventHandler.DISABLED_INSTANCE);
    grpcClientStreamChannel.init();
    StreamException streamException = null;
    try {
        grpcClientStreamChannel.connect(new Runnable() {

            @Override
            public void run() {
            }
        }, 500);
    } catch (StreamException e) {
        streamException = e;
    }
    Assert.assertEquals(StreamCode.CONNECTION_TIMEOUT, streamException.getStreamCode());
    Assert.assertEquals(StreamChannelStateCode.CLOSED, grpcClientStreamChannel.getCurrentState());
}
Also used : StreamChannelRepository(com.navercorp.pinpoint.rpc.stream.StreamChannelRepository) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException) Test(org.junit.Test)

Example 7 with StreamException

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

the class GrpcClientStreamChannelTest method connectFailTest.

@Test
public void connectFailTest() throws StreamException {
    GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(mockRemoteAddress, 20, new StreamChannelRepository(), ClientStreamChannelEventHandler.DISABLED_INSTANCE);
    grpcClientStreamChannel.init();
    StreamException streamException = null;
    try {
        grpcClientStreamChannel.connect(new Runnable() {

            @Override
            public void run() {
                throw new IllegalStateException("fail");
            }
        }, 500);
    } catch (StreamException e) {
        streamException = e;
    }
    Assert.assertEquals(StreamCode.CONNECTION_ERRROR, streamException.getStreamCode());
    Assert.assertEquals(StreamChannelStateCode.CLOSED, grpcClientStreamChannel.getCurrentState());
}
Also used : StreamChannelRepository(com.navercorp.pinpoint.rpc.stream.StreamChannelRepository) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException) Test(org.junit.Test)

Example 8 with StreamException

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

the class AgentServiceImpl method openStreamAndAwait.

@Override
public ClientStreamChannel openStreamAndAwait(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException {
    assertClusterEnabled();
    TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
    List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
    if (CollectionUtils.nullSafeSize(socketList) == 1) {
        PinpointSocket socket = socketList.get(0);
        return socket.openStreamAndAwait(serializeRequest(transferObject), streamChannelEventHandler, timeout);
    } else if (CollectionUtils.isEmpty(socketList)) {
        throw new StreamException(StreamCode.CONNECTION_NOT_FOUND);
    } else {
        throw new StreamException(StreamCode.CONNECTION_DUPLICATED);
    }
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Example 9 with StreamException

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

the class AgentServiceImpl method openStream.

@Override
public ClientStreamChannel openStream(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException {
    assertClusterEnabled();
    TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
    List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
    if (CollectionUtils.nullSafeSize(socketList) == 1) {
        PinpointSocket socket = socketList.get(0);
        return socket.openStream(serializeRequest(transferObject), streamChannelEventHandler);
    } else if (CollectionUtils.isEmpty(socketList)) {
        throw new StreamException(StreamCode.CONNECTION_NOT_FOUND);
    } else {
        throw new StreamException(StreamCode.CONNECTION_DUPLICATED);
    }
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Example 10 with StreamException

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

the class ActiveThreadCountWorker method connect.

@Override
public StreamChannel connect(AgentInfo agentInfo) {
    if (!applicationName.equals(agentInfo.getApplicationName())) {
        return null;
    }
    if (!agentId.equals(agentInfo.getAgentId())) {
        return null;
    }
    synchronized (lock) {
        if (!started) {
            started = true;
            logger.info("ActiveThreadCountWorker start. applicationName:{}, agentId:{}", applicationName, agentId);
            StreamChannel streamChannel = null;
            try {
                streamChannel = connect0(agentInfo);
                return streamChannel;
            } catch (StreamException streamException) {
                if (streamChannel != null) {
                    streamChannel.close(streamException.getStreamCode());
                }
                StreamCode streamCode = streamException.getStreamCode();
                if (streamCode == StreamCode.CONNECTION_NOT_FOUND) {
                    workerActiveManager.addReactiveWorker(agentInfo);
                }
                setDefaultErrorMessage(streamCode.name());
            } catch (TException exception) {
                if (streamChannel != null) {
                    streamChannel.close(StreamCode.TYPE_UNKNOWN);
                }
                setDefaultErrorMessage(TRouteResult.NOT_SUPPORTED_REQUEST.name());
            }
        }
    }
    return null;
}
Also used : TException(org.apache.thrift.TException) ClientStreamChannel(com.navercorp.pinpoint.rpc.stream.ClientStreamChannel) StreamChannel(com.navercorp.pinpoint.rpc.stream.StreamChannel) StreamCode(com.navercorp.pinpoint.rpc.packet.stream.StreamCode) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Aggregations

StreamException (com.navercorp.pinpoint.rpc.stream.StreamException)10 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)2 StreamCode (com.navercorp.pinpoint.rpc.packet.stream.StreamCode)2 ClientStreamChannel (com.navercorp.pinpoint.rpc.stream.ClientStreamChannel)2 StreamChannelRepository (com.navercorp.pinpoint.rpc.stream.StreamChannelRepository)2 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)2 TException (org.apache.thrift.TException)2 Test (org.junit.Test)2 GrpcAgentConnection (com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection)1 ThriftAgentConnection (com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection)1 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)1 StreamResponsePacket (com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket)1 ServerStreamChannel (com.navercorp.pinpoint.rpc.stream.ServerStreamChannel)1 StreamChannel (com.navercorp.pinpoint.rpc.stream.StreamChannel)1 CountDownLatch (java.util.concurrent.CountDownLatch)1