Search in sources :

Example 6 with StatusError

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;
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StatusError(com.navercorp.pinpoint.grpc.StatusError) PPing(com.navercorp.pinpoint.grpc.trace.PPing)

Aggregations

StatusError (com.navercorp.pinpoint.grpc.StatusError)6 StreamObserver (io.grpc.stub.StreamObserver)3 DefaultMessage (com.navercorp.pinpoint.io.request.DefaultMessage)2 Message (com.navercorp.pinpoint.io.request.Message)2 Empty (com.google.protobuf.Empty)1 PAgentStat (com.navercorp.pinpoint.grpc.trace.PAgentStat)1 PAgentUriStat (com.navercorp.pinpoint.grpc.trace.PAgentUriStat)1 PPing (com.navercorp.pinpoint.grpc.trace.PPing)1 PSpan (com.navercorp.pinpoint.grpc.trace.PSpan)1 PSpanMessage (com.navercorp.pinpoint.grpc.trace.PSpanMessage)1 PStatMessage (com.navercorp.pinpoint.grpc.trace.PStatMessage)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1