本文整理了Java中org.jooby.funzy.Try.onComplete()
方法的一些代码示例,展示了Try.onComplete()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Try.onComplete()
方法的具体详情如下:
包路径:org.jooby.funzy.Try
类名称:Try
方法名:onComplete
[英]Always run the given action, works like a finally clause. Exception will be null in case of success.
[中]始终运行给定的操作,就像finally子句一样工作。如果成功,异常将为空。
代码示例来源:origin: jooby-project/jooby
@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();
}
代码示例来源:origin: jooby-project/jooby
/**
* 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();
}
}
代码示例来源:origin: jooby-project/jooby
public void release() {
Try.run(mem::release)
.onComplete(() -> releaseNow(v8));
}
代码示例来源:origin: jooby-project/jooby
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();
}
代码示例来源:origin: jooby-project/jooby
/**
* 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();
}
}
代码示例来源:origin: jooby-project/jooby
.onComplete(() -> connection.close())
.throwException()));
watcher.start();
代码示例来源:origin: org.jooby/funzy
/**
* 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);
}
代码示例来源:origin: org.jooby/funzy
@Override public Value<V> onComplete(final Throwing.Consumer<Throwable> action) {
return (Value<V>) super.onComplete(action);
}
代码示例来源:origin: org.jooby/jooby-aws
@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();
}
代码示例来源:origin: org.jooby/jooby
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();
}
代码示例来源:origin: org.jooby/jooby-assets-nodejs
/**
* 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();
}
}
内容来源于网络,如有侵权,请联系作者删除!