Search in sources :

Example 6 with Nabaztag

use of com.nabalive.data.core.model.Nabaztag 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 7 with Nabaztag

use of com.nabalive.data.core.model.Nabaztag in project NabAlive by jcheype.

the class ApplicationScheduler method scheduled.

@Scheduled(cron = "0 * * * * *")
public void scheduled() {
    logger.debug("scheduled");
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    int day = cal.get(Calendar.DAY_OF_WEEK);
    String scheduleKey = String.format("%02d:%02d-%d", hour, minute, day);
    logger.debug("scheduleKey: {}", scheduleKey);
    Query<Nabaztag> queryWakeUp = nabaztagDAO.createQuery().filter("wakeup", scheduleKey);
    sendToAll(queryWakeUp, new SleepPacket(SleepPacket.Action.WakeUp));
    Query<Nabaztag> querySleep = nabaztagDAO.createQuery().filter("sleep", scheduleKey);
    sendToAll(querySleep, new SleepPacket(SleepPacket.Action.Sleep));
}
Also used : Nabaztag(com.nabalive.data.core.model.Nabaztag) SleepPacket(com.nabalive.server.jabber.packet.SleepPacket) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 8 with Nabaztag

use of com.nabalive.data.core.model.Nabaztag in project NabAlive by jcheype.

the class ConnectionWelcome method onEvent.

@Override
public void onEvent(String sender, Event event) throws Exception {
    logger.debug("event type {}", event.type);
    logger.debug("event type {}", event.content);
    if (event.type == Event.Type.UNBIND_RESOURCE && event.content.contains("<resource>boot</resource></unbind>")) {
        Nabaztag nabaztag = nabaztagDAO.findOne("macAddress", sender);
        logger.debug("WELCOME: unbind {}", nabaztag);
        messageService.sendMessage(sender, new PingPacket(60));
        if (nabaztag == null) {
            logger.debug("WELCOME: SENDING SOUND");
            String command = "CH http://www.nabalive.com/api/chor/rand/5\nMW\n" + "ST " + WELCOME_URL + "\nMW\n";
            messageService.sendMessage(sender, command);
        } else {
            boolean isSleep = checkSleep(nabaztag);
            logger.debug("WELCOME: ISSLEEP :" + isSleep);
            if (isSleep) {
                logger.debug("WELCOME: SENDING SLEEP");
                messageService.sendMessage(nabaztag.getMacAddress(), new SleepPacket(SleepPacket.Action.Sleep));
            }
        }
    }
}
Also used : Nabaztag(com.nabalive.data.core.model.Nabaztag) SleepPacket(com.nabalive.server.jabber.packet.SleepPacket) PingPacket(com.nabalive.server.jabber.packet.PingPacket)

Aggregations

Nabaztag (com.nabalive.data.core.model.Nabaztag)8 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 Application (com.nabalive.application.core.Application)3 Status (com.nabalive.server.jabber.Status)3 SleepPacket (com.nabalive.server.jabber.packet.SleepPacket)2 Test (org.junit.Test)2 TmpData (com.nabalive.data.core.model.TmpData)1 Request (com.nabalive.framework.web.Request)1 Response (com.nabalive.framework.web.Response)1 Route (com.nabalive.framework.web.Route)1 HttpException (com.nabalive.framework.web.exception.HttpException)1 PingPacket (com.nabalive.server.jabber.packet.PingPacket)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 PostConstruct (javax.annotation.PostConstruct)1 ObjectId (org.bson.types.ObjectId)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 ChannelBufferInputStream (org.jboss.netty.buffer.ChannelBufferInputStream)1