use of com.navercorp.pinpoint.grpc.trace.PCmdRequest in project pinpoint by naver.
the class GrpcCommandService method handleCommand.
@Override
public StreamObserver<PCmdMessage> handleCommand(StreamObserver<PCmdRequest> requestObserver) {
final Long transportId = getTransportId();
final AgentInfo agentInfo = getAgentInfo();
logger.info("{} => local. handleCommand(). transportId:{}.", agentInfo, transportId);
final List<Integer> supportCommandCodeList = getSupportCommandCodeList();
if (supportCommandCodeList != Header.SUPPORT_COMMAND_CODE_LIST_NOT_EXIST) {
logger.warn("handleCommand() not support included Header:{}. Connection will be disconnected.", Header.SUPPORT_COMMAND_CODE.name());
requestObserver.onError(new StatusException(Status.INVALID_ARGUMENT));
return DisabledStreamObserver.instance();
}
final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, agentInfo, transportId);
if (pinpointGrpcServer == null) {
return handleServerRegistrationFailed(requestObserver, agentInfo, transportId);
}
final ServerCallStreamObserver<PCmdRequest> serverCallStreamObserver = (ServerCallStreamObserver<PCmdRequest>) requestObserver;
serverCallStreamObserver.setOnReadyHandler(new Runnable() {
public void run() {
if (serverCallStreamObserver.isReady()) {
logger.info("{} => local. ready() transportId:{}", agentInfo.getAgentKey(), transportId);
pinpointGrpcServer.connected();
}
pinpointGrpcServer.setOnCloseHandler(new Runnable() {
@Override
public void run() {
unregisterPinpointGrpcServer(transportId);
}
});
}
});
final StreamObserver<PCmdMessage> responseObserver = new StreamObserver<PCmdMessage>() {
@Override
public void onNext(PCmdMessage value) {
// old operation for handshake
if (value.hasHandshakeMessage()) {
List<Integer> supportCommandServiceKeyList = value.getHandshakeMessage().getSupportCommandServiceKeyList();
registerAgentCommandList(pinpointGrpcServer, supportCommandServiceKeyList);
} else if (value.hasFailMessage()) {
PCmdResponse failMessage = value.getFailMessage();
pinpointGrpcServer.handleFail(failMessage);
}
}
@Override
public void onError(Throwable t) {
handleOnError(t, pinpointGrpcServer, agentInfo);
}
@Override
public void onCompleted() {
handleOnCompleted(pinpointGrpcServer, agentInfo);
}
};
return responseObserver;
}
Aggregations