org.jooby.funzy.Try.onComplete()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(307)

本文整理了Java中org.jooby.funzy.Try.onComplete()方法的一些代码示例,展示了Try.onComplete()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Try.onComplete()方法的具体详情如下:
包路径:org.jooby.funzy.Try
类名称:Try
方法名:onComplete

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

  1. @Override
  2. public void tryRun() throws Throwable {
  3. if (dep == null) {
  4. return;
  5. }
  6. Try.run(() -> {
  7. Optional<Method> shutdown = Arrays.stream(dep.getClass().getMethods())
  8. .filter(m -> m.getName().startsWith("shutdown")
  9. && m.getParameterCount() == 0
  10. && Modifier.isPublic(m.getModifiers()))
  11. .findFirst();
  12. if (shutdown.isPresent()) {
  13. log.debug("stopping {}", dep);
  14. shutdown.get().invoke(dep);
  15. } else {
  16. log.debug("no shutdown method found for: {}", dep);
  17. }
  18. }).unwrap(InvocationTargetException.class)
  19. .onComplete(() -> this.dep = null)
  20. .throwException();
  21. }

代码示例来源:origin: jooby-project/jooby

  1. /**
  2. * Execute the given command without waiting for completion.
  3. *
  4. * @param cmd Command.
  5. * @param args Arguments.
  6. */
  7. default void execute(String cmd, String... args) {
  8. /**
  9. * Hacky way of dealing with restart and background tasks:
  10. *
  11. * (will be better if we can start/stop all the process started by node)
  12. */
  13. String cmdline = cmd + Arrays.asList(args).stream().collect(Collectors.joining(" "));
  14. String runkey = "frontend." + cmdline.replace(" ", ".");
  15. boolean run = Boolean.parseBoolean(System.getProperty(runkey, "true"));
  16. if (run) {
  17. Runnable action = () -> Try.run(() -> {
  18. System.setProperty(runkey, "false");
  19. executeSync(cmd, args);
  20. }).onComplete(() -> System.setProperty(runkey, "true"));
  21. Thread thread = new Thread(action, cmd);
  22. thread.setDaemon(true);
  23. thread.start();
  24. }
  25. }

代码示例来源:origin: jooby-project/jooby

  1. public void release() {
  2. Try.run(mem::release)
  3. .onComplete(() -> releaseNow(v8));
  4. }

代码示例来源:origin: jooby-project/jooby

  1. private void handleErr(final Throwable cause) {
  2. Try.run(() -> {
  3. if (SILENT.test(cause)) {
  4. log.debug("execution of WS" + path() + " resulted in exception", cause);
  5. } else {
  6. exceptionCallback.onError(cause);
  7. }
  8. })
  9. .onComplete(() -> cleanup(cause))
  10. .throwException();
  11. }

代码示例来源:origin: jooby-project/jooby

  1. /**
  2. * Execute the given nodejs callback and automatically releaseNow v8 and nodejs resources.
  3. *
  4. * @param basedir Base dir where to deploy a library.
  5. * @param callback Nodejs callback.
  6. */
  7. public static void run(final File basedir, final Throwing.Consumer<Nodejs> callback) {
  8. Nodejs node = new Nodejs(basedir);
  9. Try.run(() -> callback.accept(node))
  10. .onComplete(node::release)
  11. .throwException();
  12. }
  13. }

代码示例来源:origin: jooby-project/jooby

  1. .onComplete(() -> connection.close())
  2. .throwException()));
  3. watcher.start();

代码示例来源:origin: org.jooby/funzy

  1. /**
  2. * Always run the given action, works like a finally clause.
  3. *
  4. * @param action Finally action.
  5. * @return This try result.
  6. */
  7. @Override public Value<V> onComplete(Throwing.Runnable action) {
  8. return (Value<V>) super.onComplete(action);
  9. }

代码示例来源:origin: org.jooby/funzy

  1. @Override public Value<V> onComplete(final Throwing.Consumer<Throwable> action) {
  2. return (Value<V>) super.onComplete(action);
  3. }

代码示例来源:origin: org.jooby/jooby-aws

  1. @Override
  2. public void tryRun() throws Throwable {
  3. if (dep == null) {
  4. return;
  5. }
  6. Try.run(() -> {
  7. Optional<Method> shutdown = Arrays.stream(dep.getClass().getMethods())
  8. .filter(m -> m.getName().startsWith("shutdown")
  9. && m.getParameterCount() == 0
  10. && Modifier.isPublic(m.getModifiers()))
  11. .findFirst();
  12. if (shutdown.isPresent()) {
  13. log.debug("stopping {}", dep);
  14. shutdown.get().invoke(dep);
  15. } else {
  16. log.debug("no shutdown method found for: {}", dep);
  17. }
  18. }).unwrap(InvocationTargetException.class)
  19. .onComplete(() -> this.dep = null)
  20. .throwException();
  21. }

代码示例来源:origin: org.jooby/jooby

  1. private void handleErr(final Throwable cause) {
  2. Try.run(() -> {
  3. if (SILENT.test(cause)) {
  4. log.debug("execution of WS" + path() + " resulted in exception", cause);
  5. } else {
  6. exceptionCallback.onError(cause);
  7. }
  8. })
  9. .onComplete(() -> cleanup(cause))
  10. .throwException();
  11. }

代码示例来源:origin: org.jooby/jooby-assets-nodejs

  1. /**
  2. * Execute the given nodejs callback and automatically releaseNow v8 and nodejs resources.
  3. *
  4. * @param basedir Base dir where to deploy a library.
  5. * @param callback Nodejs callback.
  6. */
  7. public static void run(final File basedir, final Throwing.Consumer<Nodejs> callback) {
  8. Nodejs node = new Nodejs(basedir);
  9. Try.run(() -> callback.accept(node))
  10. .onComplete(node::release)
  11. .throwException();
  12. }
  13. }

相关文章