use of com.navercorp.pinpoint.rpc.stream.StreamException in project pinpoint by naver.
the class GrpcClientStreamChannelTest method connect.
private CountDownLatch connect(GrpcClientStreamChannel grpcClientStreamChannel, CountDownLatch connectCompleteLatch) {
CountDownLatch threadCompleteLatch = new CountDownLatch(1);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
grpcClientStreamChannel.connect(new Runnable() {
@Override
public void run() {
connectCompleteLatch.countDown();
}
}, 1000);
} catch (StreamException e) {
e.printStackTrace();
} finally {
threadCompleteLatch.countDown();
}
}
});
thread.setDaemon(true);
thread.start();
return threadCompleteLatch;
}
use of com.navercorp.pinpoint.rpc.stream.StreamException 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.rpc.stream.StreamException 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;
}
}
use of com.navercorp.pinpoint.rpc.stream.StreamException in project pinpoint by naver.
the class PinpointGrpcServer method openStream.
// 1st message : client(collector) -> server(agent)
public ClientStreamChannel openStream(GeneratedMessageV3 message, ClientStreamChannelEventHandler streamChannelEventHandler) throws StreamException {
if (!state.checkState(SocketStateCode.RUN_DUPLEX)) {
throw new StreamException(StreamCode.STATE_NOT_CONNECTED);
}
PCmdRequest request = createRequest(message);
if (request == null) {
throw new StreamException(StreamCode.TYPE_UNSUPPORT);
}
GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(remoteAddress, request.getRequestId(), streamChannelRepository, streamChannelEventHandler);
try {
grpcClientStreamChannel.init();
grpcClientStreamChannel.connect(new Runnable() {
@Override
public void run() {
requestObserver.onNext(request);
}
}, 1000);
} catch (StreamException e) {
grpcClientStreamChannel.close(e.getStreamCode());
throw e;
}
return grpcClientStreamChannel;
}
use of com.navercorp.pinpoint.rpc.stream.StreamException in project pinpoint by naver.
the class GrpcClientStreamChannel method connect.
public void connect(Runnable connectRunnable, long timeout) throws StreamException {
changeStateTo(StreamChannelStateCode.CONNECT_AWAIT, true);
try {
connectRunnable.run();
} catch (RuntimeException e) {
changeStateTo(StreamChannelStateCode.CLOSED);
throw new StreamException(StreamCode.CONNECTION_ERRROR, e.getMessage());
}
boolean connected = awaitOpen(timeout);
if (connected) {
logger.info("Open streamChannel initialization completed. streamChannel:{} ", this);
} else {
changeStateTo(StreamChannelStateCode.CLOSED);
throw new StreamException(StreamCode.CONNECTION_TIMEOUT);
}
}
Aggregations