@Override public void tryRun() throws Throwable { if (dep == null) { return; } Try.run(() -> { Optional<Method> shutdown = Arrays.stream(dep.getClass().getMethods()) .filter(m -> m.getName().startsWith("shutdown") && m.getParameterCount() == 0 && Modifier.isPublic(m.getModifiers())) .findFirst(); if (shutdown.isPresent()) { log.debug("stopping {}", dep); shutdown.get().invoke(dep); } else { log.debug("no shutdown method found for: {}", dep); } }).unwrap(InvocationTargetException.class) .onComplete(() -> this.dep = null) .throwException(); }
/** * Execute the given command without waiting for completion. * * @param cmd Command. * @param args Arguments. */ default void execute(String cmd, String... args) { /** * Hacky way of dealing with restart and background tasks: * * (will be better if we can start/stop all the process started by node) */ String cmdline = cmd + Arrays.asList(args).stream().collect(Collectors.joining(" ")); String runkey = "frontend." + cmdline.replace(" ", "."); boolean run = Boolean.parseBoolean(System.getProperty(runkey, "true")); if (run) { Runnable action = () -> Try.run(() -> { System.setProperty(runkey, "false"); executeSync(cmd, args); }).onComplete(() -> System.setProperty(runkey, "true")); Thread thread = new Thread(action, cmd); thread.setDaemon(true); thread.start(); } }
public void release() { Try.run(mem::release) .onComplete(() -> releaseNow(v8)); }
private void handleErr(final Throwable cause) { Try.run(() -> { if (SILENT.test(cause)) { log.debug("execution of WS" + path() + " resulted in exception", cause); } else { exceptionCallback.onError(cause); } }) .onComplete(() -> cleanup(cause)) .throwException(); }
/** * Execute the given nodejs callback and automatically releaseNow v8 and nodejs resources. * * @param basedir Base dir where to deploy a library. * @param callback Nodejs callback. */ public static void run(final File basedir, final Throwing.Consumer<Nodejs> callback) { Nodejs node = new Nodejs(basedir); Try.run(() -> callback.accept(node)) .onComplete(node::release) .throwException(); } }
.onComplete(() -> connection.close()) .throwException())); watcher.start();
/** * Always run the given action, works like a finally clause. * * @param action Finally action. * @return This try result. */ @Override public Value<V> onComplete(Throwing.Runnable action) { return (Value<V>) super.onComplete(action); }
@Override public Value<V> onComplete(final Throwing.Consumer<Throwable> action) { return (Value<V>) super.onComplete(action); }
@Override public void tryRun() throws Throwable { if (dep == null) { return; } Try.run(() -> { Optional<Method> shutdown = Arrays.stream(dep.getClass().getMethods()) .filter(m -> m.getName().startsWith("shutdown") && m.getParameterCount() == 0 && Modifier.isPublic(m.getModifiers())) .findFirst(); if (shutdown.isPresent()) { log.debug("stopping {}", dep); shutdown.get().invoke(dep); } else { log.debug("no shutdown method found for: {}", dep); } }).unwrap(InvocationTargetException.class) .onComplete(() -> this.dep = null) .throwException(); }
private void handleErr(final Throwable cause) { Try.run(() -> { if (SILENT.test(cause)) { log.debug("execution of WS" + path() + " resulted in exception", cause); } else { exceptionCallback.onError(cause); } }) .onComplete(() -> cleanup(cause)) .throwException(); }
/** * Execute the given nodejs callback and automatically releaseNow v8 and nodejs resources. * * @param basedir Base dir where to deploy a library. * @param callback Nodejs callback. */ public static void run(final File basedir, final Throwing.Consumer<Nodejs> callback) { Nodejs node = new Nodejs(basedir); Try.run(() -> callback.accept(node)) .onComplete(node::release) .throwException(); } }