public void shutdown()

in apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/EventReportServiceClient.java [99:142]


    public void shutdown() throws Throwable {
        if (!CONNECTED.equals(status)) {
            return;
        }

        final CountDownLatch latch = new CountDownLatch(1);
        final Event.Builder shutdownEvent = Event.newBuilder()
                                                 .setUuid(UUID.randomUUID().toString())
                                                 .setName("Shutdown")
                                                 .setStartTime(System.currentTimeMillis())
                                                 .setEndTime(System.currentTimeMillis())
                                                 .setMessage("Shutting down Java Application")
                                                 .setType(Type.Normal)
                                                 .setSource(
                                                     Source.newBuilder()
                                                           .setService(Config.Agent.SERVICE_NAME)
                                                           .setServiceInstance(Config.Agent.INSTANCE_NAME)
                                                           .build()
                                                 )
                                                .setLayer(EVENT_LAYER_NAME);

        final StreamObserver<Event> collector = eventServiceStub.collect(new StreamObserver<Commands>() {
            @Override
            public void onNext(final Commands commands) {
                ServiceManager.INSTANCE.findService(CommandService.class).receiveCommand(commands);
            }

            @Override
            public void onError(final Throwable t) {
                LOGGER.error("Failed to report shutdown event.", t);
                // Ignore status change at shutting down stage.
                latch.countDown();
            }

            @Override
            public void onCompleted() {
                latch.countDown();
            }
        });

        collector.onNext(shutdownEvent.build());
        collector.onCompleted();
        latch.await();
    }