use of javax.annotation.PostConstruct 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 javax.annotation.PostConstruct in project NabAlive by jcheype.
the class TtsController method init.
@PostConstruct
void init() {
restHandler.get(new Route("/tts/:apikey/:voice") {
@Override
public void handle(Request request, final Response response, Map<String, String> map) throws Exception {
String text = StringEscapeUtils.escapeXml(checkNotNull(request.getParam("text")));
String voice = checkNotNull(map.get("voice"));
if (!text.startsWith("<s>")) {
text = "<s>" + text + "</s>";
}
final String key = text + "|" + voice;
byte[] bytes = ttsCache.asMap().get(key);
if (bytes != null) {
response.write(ChannelBuffers.copiedBuffer(bytes));
return;
}
asyncHttpClient.preparePost(frenchTtsUrl).setBody(text).execute(new AsyncCompletionHandler<com.ning.http.client.Response>() {
@Override
public com.ning.http.client.Response onCompleted(com.ning.http.client.Response asyncResponse) throws Exception {
InputStream inputStream = asyncResponse.getResponseBodyAsStream();
byte[] bytes = ByteStreams.toByteArray(inputStream);
ttsCache.asMap().put(key, bytes);
response.write(bytes);
return asyncResponse;
}
@Override
public void onThrowable(Throwable t) {
logger.error("TTS error", t);
HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
response.write(httpResponse);
}
});
}
}).get(new Route("/tts/:voice") {
@Override
public void handle(Request request, final Response response, Map<String, String> map) throws Exception {
String text = StringEscapeUtils.escapeXml(checkNotNull(request.getParam("text")));
String voice = checkNotNull(map.get("voice"));
if (!text.startsWith("<s>")) {
text = "<s>" + text + "</s>";
}
final String key = text + "|" + voice;
byte[] bytes = ttsCache.asMap().get(key);
if (bytes != null) {
response.write(ChannelBuffers.copiedBuffer(bytes));
return;
}
asyncHttpClient.preparePost(frenchTtsUrl).setBody(text).execute(new AsyncCompletionHandler<com.ning.http.client.Response>() {
@Override
public com.ning.http.client.Response onCompleted(com.ning.http.client.Response asyncResponse) throws Exception {
InputStream inputStream = asyncResponse.getResponseBodyAsStream();
byte[] bytes = ByteStreams.toByteArray(inputStream);
ttsCache.asMap().put(key, bytes);
response.write(bytes);
return asyncResponse;
}
@Override
public void onThrowable(Throwable t) {
logger.error("TTS error", t);
HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
response.write(httpResponse);
}
});
}
});
}
use of javax.annotation.PostConstruct in project JFoenix by jfoenixadmin.
the class IconsController method init.
@PostConstruct
public void init() throws FlowException, VetoException {
bindAction(burger1);
bindAction(burger2);
bindAction(burger3);
bindAction(burger4);
snackbar.registerSnackbarContainer(root);
badge1.setOnMouseClicked((e) -> {
int value = Integer.parseInt(badge1.getText());
if (e.getButton() == MouseButton.PRIMARY) {
value++;
} else if (e.getButton() == MouseButton.SECONDARY) {
value--;
}
if (value == 0) {
badge1.setEnabled(false);
} else {
badge1.setEnabled(true);
}
badge1.setText(String.valueOf(value));
// trigger snackbar
if (count++ % 2 == 0) {
snackbar.fireEvent(new SnackbarEvent("Toast Message " + count));
} else {
if (count % 4 == 0) {
snackbar.fireEvent(new SnackbarEvent("Snackbar Message Persistant " + count, "CLOSE", 3000, true, (b) -> {
snackbar.close();
}));
} else {
snackbar.fireEvent(new SnackbarEvent("Snackbar Message " + count, "UNDO", 3000, false, (b) -> {
}));
}
}
});
}
use of javax.annotation.PostConstruct in project JFoenix by jfoenixadmin.
the class SVGLoaderController method init.
@PostConstruct
public void init() throws FlowException, VetoException, Exception {
final Stage stage = (Stage) context.getRegisteredObject("Stage");
glyphDetailViewer = new GlyphDetailViewer();
detailsContainer.getChildren().add(glyphDetailViewer);
ScrollPane scrollableGlyphs = allGlyphs();
scrollableGlyphs.setStyle("-fx-background-insets: 0;");
iconsContainer.getChildren().add(scrollableGlyphs);
browseFont.setOnAction((action) -> {
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("SVG files (*.svg)", "*.svg");
fileChooser.getExtensionFilters().add(extFilter);
File file = fileChooser.showOpenDialog(stage);
if (file != null) {
SVGGlyphLoader.clear();
try {
SVGGlyphLoader.loadGlyphsFont(new FileInputStream(file), file.getName());
ScrollPane newglyphs = allGlyphs();
newglyphs.setStyle("-fx-background-insets: 0;");
iconsContainer.getChildren().clear();
iconsContainer.getChildren().add(newglyphs);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of javax.annotation.PostConstruct in project NabAlive by jcheype.
the class ApplicationGroovyLoader method init.
@PostConstruct
public void init() {
File scriptFolder = new File(APPS_FOLDER);
if (!scriptFolder.isDirectory()) {
throw new IllegalStateException("parameter \"apps.folder\" must point to a directory: " + APPS_FOLDER);
}
Runnable folderWatcher = new FolderWatcher(scriptFolder) {
@Override
protected void onChange(File file) {
logger.debug("FolderWatcher onChange: {}", file.getName());
if (!file.exists()) {
applicationManager.unRegisterByName(stripExtension(file.getName()));
return;
} else if (file.getName().endsWith(".zip")) {
try {
registerZip(file);
} catch (Exception e) {
logger.error("cannot load app: {}", file.getName(), e);
}
}
}
};
new Thread(folderWatcher).start();
}
Aggregations