Search in sources :

Example 1 with StreamCode

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

the class ServerStreamChannel method handleStreamCreatePacket.

public void handleStreamCreatePacket(StreamCreatePacket packet) throws StreamException {
    changeStateTo(StreamChannelStateCode.CONNECT_ARRIVED, true);
    StreamCode result = streamChannelMessageHandler.handleStreamCreatePacket(this, packet);
    if (result != StreamCode.OK) {
        throw new StreamException(result);
    }
    changeStateConnected();
    sendCreateSuccess();
}
Also used : StreamCode(com.navercorp.pinpoint.rpc.packet.stream.StreamCode)

Example 2 with StreamCode

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

the class StreamRouteHandler method onRoute0.

private TCommandTransferResponse onRoute0(StreamEvent event) {
    TBase<?, ?> requestObject = event.getRequestObject();
    if (requestObject == null) {
        return createResponse(TRouteResult.EMPTY_REQUEST);
    }
    ClusterPoint<?> clusterPoint = findClusterPoint(event.getDeliveryCommand());
    if (clusterPoint == null) {
        return createResponse(TRouteResult.NOT_FOUND);
    }
    if (!clusterPoint.isSupportCommand(requestObject)) {
        logger.warn("Create StreamChannel failed. target:{}, message:{} is not supported command", clusterPoint, requestObject.getClass().getName());
        return createResponse(TRouteResult.NOT_SUPPORTED_REQUEST);
    }
    try {
        if (clusterPoint instanceof ThriftAgentConnection) {
            StreamRouteManager routeManager = new StreamRouteManager(event);
            ServerStreamChannel consumerStreamChannel = event.getStreamChannel();
            consumerStreamChannel.setAttributeIfAbsent(ATTACHMENT_KEY, routeManager);
            ClientStreamChannel producerStreamChannel = createStreamChannel((ThriftAgentConnection) clusterPoint, event.getDeliveryCommand().getPayload(), routeManager);
            routeManager.setProducer(producerStreamChannel);
            return createResponse(TRouteResult.OK);
        } else if (clusterPoint instanceof GrpcAgentConnection) {
            StreamRouteManager routeManager = new StreamRouteManager(event);
            ServerStreamChannel consumerStreamChannel = event.getStreamChannel();
            consumerStreamChannel.setAttributeIfAbsent(ATTACHMENT_KEY, routeManager);
            ClientStreamChannel producerStreamChannel = ((GrpcAgentConnection) clusterPoint).openStream(event.getRequestObject(), routeManager);
            routeManager.setProducer(producerStreamChannel);
            return createResponse(TRouteResult.OK);
        } else {
            return createResponse(TRouteResult.NOT_SUPPORTED_SERVICE);
        }
    } catch (StreamException e) {
        StreamCode streamCode = e.getStreamCode();
        return createResponse(TRouteResult.STREAM_CREATE_ERROR, streamCode.name());
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Create StreamChannel failed. target:{}, message:{}", clusterPoint, e.getMessage(), e);
        }
    }
    return createResponse(TRouteResult.UNKNOWN);
}
Also used : ThriftAgentConnection(com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection) GrpcAgentConnection(com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection) ClientStreamChannel(com.navercorp.pinpoint.rpc.stream.ClientStreamChannel) StreamCode(com.navercorp.pinpoint.rpc.packet.stream.StreamCode) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException) ServerStreamChannel(com.navercorp.pinpoint.rpc.stream.ServerStreamChannel) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Example 3 with StreamCode

use of com.navercorp.pinpoint.rpc.packet.stream.StreamCode 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

StreamCode (com.navercorp.pinpoint.rpc.packet.stream.StreamCode)3 ClientStreamChannel (com.navercorp.pinpoint.rpc.stream.ClientStreamChannel)2 StreamException (com.navercorp.pinpoint.rpc.stream.StreamException)2 GrpcAgentConnection (com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection)1 ThriftAgentConnection (com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection)1 ServerStreamChannel (com.navercorp.pinpoint.rpc.stream.ServerStreamChannel)1 StreamChannel (com.navercorp.pinpoint.rpc.stream.StreamChannel)1 TException (org.apache.thrift.TException)1