Kaa:当onStarted()在main中调用时?

时间:2017-05-31 02:38:50

标签: kaa

想了解如何调用onStarted()。 kaaClient.start()是否在onStarted()上执行?我尝试使用ecplise进行调试,发现它总是执行“sleepForSeconds(MAX_SECONDS_TO_INIT_KAA);”在去“LOG.info(” - = Kaa client started = - “)之前”但我无法判断onStarted()何时被执行。

   public static void main(String[] args) {
        LOG.info("--= Data collection demo started =--");

        /*
         * Create a Kaa client with the Kaa desktop context.
         */
        KaaClient kaaClient = Kaa.newClient(new DesktopKaaPlatformContext(), new SimpleKaaClientStateListener() {
            @Override
            public void onStarted() {
                LOG.info("--= Kaa client started =--");
            }

            @Override
            public void onStopped() {
                LOG.info("--= Kaa client stopped =--");
            }
        }, true);

        /*
         * Set record count strategy for uploading every log record as soon as it is created.
         */
        kaaClient.setLogUploadStrategy(new RecordCountLogUploadStrategy(LOGS_DEFAULT_THRESHOLD));

        /*
         * Displays endpoint's configuration and change sampling period each time configuration will be updated.
         */
        kaaClient.addConfigurationListener(new ConfigurationListener() {
            @Override
            public void onConfigurationUpdate(Configuration configuration) {
                LOG.info("--= Endpoint configuration was updated =--");
                displayConfiguration(configuration);

                Integer newSamplePeriod = configuration.getSamplePeriod();
                if ((newSamplePeriod != null) && (newSamplePeriod > 0)) {
                    changeMeasurementPeriod(kaaClient, newSamplePeriod);
                } else {
                    LOG.warn("Sample period value (= {}) in updated configuration is wrong, so ignore it.", newSamplePeriod);
                }
            }
        });

        /*
         * Start the Kaa client and connect it to the Kaa server.
         */
        kaaClient.start();
        sleepForSeconds(MAX_SECONDS_TO_INIT_KAA);

        /*
         * Start periodical temperature value generating and sending results to Kaa node
         */
        startMeasurement(kaaClient);

        LOG.info("*** Press Enter to stop sending log records ***");
        waitForAnyInput();

        /*
         * Stop generating and sending data to Kaa node
         */
        stopMeasurement();

        /*
         * Stop the Kaa client and release all the resources which were in use.
         */
        kaaClient.stop();
        displayResults();
        LOG.info("--= Data collection demo stopped =--");
    }

1 个答案:

答案 0 :(得分:1)

onStarted()方法中调用的方法start()。有关详细信息,请参阅AbstaractKaaClient