Search in sources :

Example 1 with Status

use of com.nabalive.server.jabber.Status 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 Status

use of com.nabalive.server.jabber.Status 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)

Example 3 with Status

use of com.nabalive.server.jabber.Status 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 4 with Status

use of com.nabalive.server.jabber.Status in project NabAlive by jcheype.

the class BaseEventRegistrationService method register.

@Override
public void register(String id, EventListener eventListener) {
    Status status = connectionManager.get(id);
    if (status == null) {
        throw new IllegalArgumentException("id [" + id + "] is not found");
    }
    status.registerEvent(eventListener);
}
Also used : Status(com.nabalive.server.jabber.Status)

Example 5 with Status

use of com.nabalive.server.jabber.Status in project NabAlive by jcheype.

the class BaseMessageService method sendMessage.

@Override
public void sendMessage(String to, Packet message) {
    Status status = checkNotNull(connectionManager.get(to));
    String xmpp = message.getXmpp("www.nabalive.server.jabber", status.getJid().toString());
    status.write(xmpp);
}
Also used : Status(com.nabalive.server.jabber.Status)

Aggregations

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