use of com.navercorp.pinpoint.grpc.StatusError in project pinpoint by naver.
the class AgentService method pingSession.
@Override
public StreamObserver<PPing> pingSession(final StreamObserver<PPing> responseObserver) {
final StreamObserver<PPing> request = new StreamObserver<PPing>() {
private final AtomicBoolean first = new AtomicBoolean(false);
private final long id = nextSessionId();
@Override
public void onNext(PPing ping) {
if (first.compareAndSet(false, true)) {
// Only first
if (isDebug) {
logger.debug("PingSession:{} start:{}", id, MessageFormatUtils.debugLog(ping));
}
AgentService.this.pingEventHandler.connect();
} else {
AgentService.this.pingEventHandler.ping();
}
if (isDebug) {
logger.debug("PingSession:{} onNext:{}", id, MessageFormatUtils.debugLog(ping));
}
PPing replay = newPing();
responseObserver.onNext(replay);
}
private PPing newPing() {
PPing.Builder builder = PPing.newBuilder();
return builder.build();
}
@Override
public void onError(Throwable t) {
final StatusError statusError = StatusErrors.throwable(t);
if (statusError.isSimpleError()) {
logger.info("Failed to ping stream, id={}, cause={}", id, statusError.getMessage());
} else {
logger.warn("Failed to ping stream, id={}, cause={}", id, statusError.getMessage(), statusError.getThrowable());
}
disconnect();
}
@Override
public void onCompleted() {
if (isDebug) {
logger.debug("PingSession:{} onCompleted()", id);
}
responseObserver.onCompleted();
disconnect();
}
private void disconnect() {
AgentService.this.pingEventHandler.close();
}
};
return request;
}
Aggregations