Search in sources :

Example 1 with Application

use of com.nabalive.application.core.Application in project NabAlive by jcheype.

the class ApplicationScheduler method clock.

@Scheduled(cron = "0 0 * * * *")
public void clock() {
    logger.debug("clock trigger");
    // clock
    Application application = checkNotNull(applicationManager.getApplication(CLOCK_APIKEY));
    Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", CLOCK_APIKEY);
    Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
    while (iterator.hasNext()) {
        Nabaztag nabaztag = iterator.next();
        Status status = connectionManager.get(nabaztag.getMacAddress());
        if (status != null && !status.isAsleep()) {
            try {
                application.onStartup(nabaztag, findConfig(CLOCK_APIKEY, nabaztag.getApplicationConfigList()));
            } catch (Exception e) {
                logger.debug("cannot send message", e);
            }
        }
    }
}
Also used : Status(com.nabalive.server.jabber.Status) Nabaztag(com.nabalive.data.core.model.Nabaztag) Application(com.nabalive.application.core.Application) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 2 with Application

use of com.nabalive.application.core.Application in project NabAlive by jcheype.

the class ApplicationScheduler method taichi.

@Scheduled(fixedDelay = 400000)
public void taichi() {
    logger.debug("taichi trigger");
    // taichi
    Application application = checkNotNull(applicationManager.getApplication(TAICHI_APIKEY));
    Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", TAICHI_APIKEY);
    Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
    while (iterator.hasNext()) {
        Nabaztag nabaztag = iterator.next();
        Status status = connectionManager.get(nabaztag.getMacAddress());
        if (status != null && status.isIdle()) {
            if (rand.nextInt(4) == 0) {
                try {
                    application.onStartup(nabaztag, findConfig(TAICHI_APIKEY, nabaztag.getApplicationConfigList()));
                } catch (Exception e) {
                    logger.debug("cannot send message", e);
                }
            }
        }
    }
}
Also used : Status(com.nabalive.server.jabber.Status) Nabaztag(com.nabalive.data.core.model.Nabaztag) Application(com.nabalive.application.core.Application) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 3 with Application

use of com.nabalive.application.core.Application in project NabAlive by jcheype.

the class ApplicationScheduler method mood.

@Scheduled(fixedDelay = 300000)
public void mood() {
    logger.debug("mood trigger");
    // mood
    Application application = checkNotNull(applicationManager.getApplication(MOOD_APIKEY));
    Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", MOOD_APIKEY);
    Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
    while (iterator.hasNext()) {
        Nabaztag nabaztag = iterator.next();
        Status status = connectionManager.get(nabaztag.getMacAddress());
        if (status != null && status.isIdle()) {
            if (rand.nextInt(4) == 0) {
                try {
                    application.onStartup(nabaztag, findConfig(MOOD_APIKEY, nabaztag.getApplicationConfigList()));
                } catch (Exception e) {
                    logger.debug("cannot send message", e);
                }
            }
        }
    }
}
Also used : Status(com.nabalive.server.jabber.Status) Nabaztag(com.nabalive.data.core.model.Nabaztag) Application(com.nabalive.application.core.Application) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

Application (com.nabalive.application.core.Application)3 Nabaztag (com.nabalive.data.core.model.Nabaztag)3 Status (com.nabalive.server.jabber.Status)3 Scheduled (org.springframework.scheduling.annotation.Scheduled)3