Search code examples
kaa

Kaa: When onStarted() was called in main?


Like to understand how onStarted() is being called. Does kaaClient.start() executed onStarted()? I tried to debug with ecplise and found it always executed "sleepForSeconds(MAX_SECONDS_TO_INIT_KAA);" before going to "LOG.info("--= Kaa client started =--")" but I can't tell when onStarted() was executed.

   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 =--");
    }

Solution

  • Method onStarted() called in the start() method. For details see AbstaractKaaClient.