use of com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection 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);
}
use of com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection in project pinpoint by naver.
the class DefaultRouteHandler method onRoute0.
private TCommandTransferResponse onRoute0(RequestEvent 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)) {
return createResponse(TRouteResult.NOT_SUPPORTED_REQUEST);
}
Future<ResponseMessage> future;
if (clusterPoint instanceof ThriftAgentConnection) {
ThriftAgentConnection thriftAgentConnection = (ThriftAgentConnection) clusterPoint;
future = thriftAgentConnection.request(event.getDeliveryCommand().getPayload());
} else if (clusterPoint instanceof GrpcAgentConnection) {
GrpcAgentConnection grpcAgentConnection = (GrpcAgentConnection) clusterPoint;
future = grpcAgentConnection.request(event.getRequestObject());
} else {
return createResponse(TRouteResult.NOT_ACCEPTABLE);
}
boolean isCompleted = future.await();
if (!isCompleted) {
return createResponse(TRouteResult.TIMEOUT);
}
if (future.getCause() != null) {
return createResponse(TRouteResult.UNKNOWN, future.getCause().getMessage());
}
ResponseMessage responseMessage = future.getResult();
if (responseMessage == null) {
return createResponse(TRouteResult.EMPTY_RESPONSE);
}
final byte[] responsePayload = responseMessage.getMessage();
if (ArrayUtils.isEmpty(responsePayload)) {
return createResponse(TRouteResult.EMPTY_RESPONSE, new byte[0]);
}
return createResponse(TRouteResult.OK, responsePayload);
}
Aggregations