use of com.nabalive.data.core.model.Nabaztag 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);
}
}
}
}
use of com.nabalive.data.core.model.Nabaztag in project NabAlive by jcheype.
the class AppTest method testInserNabaztag.
@Test
public void testInserNabaztag() {
Nabaztag n1 = new Nabaztag();
Nabaztag n2 = new Nabaztag();
n1.setName("n1");
n2.setName("n2");
n1.setMacAddress(UUID.randomUUID().toString());
n2.setMacAddress(UUID.randomUUID().toString());
nabaztagDAO.save(n1);
nabaztagDAO.save(n2);
}
use of com.nabalive.data.core.model.Nabaztag in project NabAlive by jcheype.
the class SleepTest method sleepTest.
@Test
public void sleepTest() {
ConnectionWelcome welcome = new ConnectionWelcome();
Nabaztag nabaztag = new Nabaztag();
nabaztag.getSleep().add("14:06-7");
nabaztag.getSleep().add("08:50-5");
nabaztag.getSleep().add("10:17-3");
nabaztag.getWakeup().add("14:03-6");
nabaztag.getWakeup().add("11:45-6");
nabaztag.getWakeup().add("10:32-2");
boolean b = welcome.checkSleep(nabaztag);
System.out.println("b:" + b);
}
use of com.nabalive.data.core.model.Nabaztag in project NabAlive by jcheype.
the class RecordController method init.
@PostConstruct
void init() {
restHandler.post(new Route("/vl/record.jsp") {
@Override
public void handle(Request request, Response response, Map<String, String> map) throws Exception {
String mac = checkNotNull(request.getParam("sn")).toLowerCase();
if (!connectionManager.containsKey(mac))
throw new HttpException(HttpResponseStatus.NOT_FOUND, "sn is not connected");
Nabaztag nabaztag = checkNotNull(nabaztagDAO.findOne("macAddress", mac));
ChannelBuffer content = request.request.getContent();
logger.debug("record orig size: {}", content.readableBytes());
ChannelBufferInputStream inputStream = new ChannelBufferInputStream(content);
TmpData sound = new TmpData();
sound.setData(ByteStreams.toByteArray(inputStream));
tmpDataDAO.save(sound, WriteConcern.SAFE);
String host = request.request.getHeader("Host");
String url = "http://" + host + "/record/" + sound.getId().toString();
logger.debug("sound url: {}", url);
final String command = "ST " + url + "\nMW\n";
Query<Nabaztag> query = nabaztagDAO.createQuery();
query.filter("subscribe.objectId", nabaztag.getId().toString());
List<Nabaztag> nabaztags = nabaztagDAO.find(query).asList();
logger.debug("sending to {} subscribers", nabaztags.size());
for (Nabaztag nab : nabaztags) {
if (connectionManager.containsKey(nab.getMacAddress())) {
final Nabaztag nabTmp = nab;
Runnable runnable = new Runnable() {
@Override
public void run() {
logger.debug("sending to {}", nabTmp.getMacAddress());
logger.debug("command {}", command);
messageService.sendMessage(nabTmp.getMacAddress(), command);
}
};
ses.schedule(runnable, 500, TimeUnit.MILLISECONDS);
}
}
response.write("ok");
}
}).get(new Route("/record/:recordId") {
@Override
public void handle(Request request, Response response, Map<String, String> map) throws Exception {
ObjectId recordId = new ObjectId(checkNotNull(map.get("recordId")));
TmpData sound = checkNotNull(tmpDataDAO.get(recordId));
response.write(sound.getData());
}
});
}
use of com.nabalive.data.core.model.Nabaztag 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);
}
}
}
}
}
Aggregations