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

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

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

Try.throwException介绍

[英]Propagate/throw the exception in case of failure.
[中]在发生故障时传播/抛出异常。

代码示例

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

private Jooby hackInjector(final Jooby app) {
 Try.run(() -> {
  Field field = Jooby.class.getDeclaredField("injector");
  field.setAccessible(true);
  Injector injector = proxyInjector(getClass().getClassLoader(), registry);
  field.set(app, injector);
  registry.put(Key.get(Injector.class), injector);
 }).throwException();
 return app;
}

代码示例来源: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

private static void copy(final InputStream in, final OutputStream out) {
 Try.of(in, out)
   .run(ByteStreams::copy)
   .throwException();
}

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

method.invoke(owner);
 }).unwrap(InvocationTargetException.class)
   .throwException();
});

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

private void tryOption(final Object source, final Config config, final Method option) {
 Try.run(() -> {
  String optionName = option.getName().replace("set", "");
  Object optionValue = config.getAnyRef(optionName);
  Class<?> optionType = Primitives.wrap(option.getParameterTypes()[0]);
  if (Number.class.isAssignableFrom(optionType) && optionValue instanceof String) {
   // either a byte or time unit
   try {
    optionValue = config.getBytes(optionName);
   } catch (ConfigException.BadValue ex) {
    optionValue = config.getDuration(optionName, TimeUnit.MILLISECONDS);
   }
   if (optionType == Integer.class) {
    // to int
    optionValue = ((Number) optionValue).intValue();
   }
  }
  log.debug("{}.{}({})", source.getClass().getSimpleName(), option.getName(), optionValue);
  option.invoke(source, optionValue);
 }).unwrap(InvocationTargetException.class)
   .throwException();
}

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

.throwException();

代码示例来源: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

@Override
 public void handle(final Request req, final Response rsp, final Optional<Throwable> cause) {
  if (handle.isClosed()) {
   logger.warn("closed handle: {}", handle);
  } else {
   logger.debug("closing handling: {}", handle);
   Try.of(handle)
     .run(h -> {
      if (h.isInTransaction()) {
       if (cause.isPresent()) {
        logger.debug("rollback transaction: {}", handle, cause.get());
        h.rollback();
       } else {
        logger.debug("commit transaction {}", handle);
        h.commit();
       }
      }
     }).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

public MockUnit run(final Block... blocks) throws Exception {
 for (Block block : this.blocks) {
  Try.run(() -> block.run(this))
    .throwException();
 }
 mockClasses.forEach(PowerMock::replay);
 partialMocks.forEach(PowerMock::replay);
 mocks.forEach(EasyMock::replay);
 for (Block main : blocks) {
  Try.run(() -> main.run(this)).throwException();
 }
 mocks.forEach(EasyMock::verify);
 partialMocks.forEach(PowerMock::verify);
 mockClasses.forEach(PowerMock::verify);
 return this;
}

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

Runtime.getRuntime().addShutdownHook(new Thread(() -> Try.run(watcher::stop)
 .onComplete(() -> connection.close())
 .throwException()));
watcher.start();

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

caseSensitiveRouting)
.accept(it))
.throwException();

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

private Executor executor() {
 if (executor == null) {
  if (this.host.startsWith("https://")) {
   Try.run(() -> {
    SSLContext sslContext = SSLContexts.custom()
      .loadTrustMaterial(null, (chain, authType) -> true)
      .build();
    builder.setSSLContext(sslContext);
    builder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
   }).throwException();
  }
  client = builder.build();
  executor = Executor.newInstance(client);
  if (creds != null) {
   executor.auth(creds);
  }
 }
 return executor;
}

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

private Jooby hackInjector(final Jooby app) {
 Try.run(() -> {
  Field field = Jooby.class.getDeclaredField("injector");
  field.setAccessible(true);
  Injector injector = proxyInjector(getClass().getClassLoader(), registry);
  field.set(app, injector);
  registry.put(Key.get(Injector.class), injector);
 }).throwException();
 return app;
}

代码示例来源: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 static void copy(final InputStream in, final OutputStream out) {
 Try.of(in, out)
   .run(ByteStreams::copy)
   .throwException();
}

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

method.invoke(owner);
 }).unwrap(InvocationTargetException.class)
   .throwException();
});

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

private void tryOption(final Object source, final Config config, final Method option) {
 Try.run(() -> {
  String optionName = option.getName().replace("set", "");
  Object optionValue = config.getAnyRef(optionName);
  Class<?> optionType = Primitives.wrap(option.getParameterTypes()[0]);
  if (Number.class.isAssignableFrom(optionType) && optionValue instanceof String) {
   // either a byte or time unit
   try {
    optionValue = config.getBytes(optionName);
   } catch (ConfigException.BadValue ex) {
    optionValue = config.getDuration(optionName, TimeUnit.MILLISECONDS);
   }
   if (optionType == Integer.class) {
    // to int
    optionValue = ((Number) optionValue).intValue();
   }
  }
  log.debug("{}.{}({})", source.getClass().getSimpleName(), option.getName(), optionValue);
  option.invoke(source, optionValue);
 }).unwrap(InvocationTargetException.class)
   .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();
 }
}

相关文章