本文整理了Java中org.jooby.funzy.Try.onFailure()
方法的一些代码示例,展示了Try.onFailure()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Try.onFailure()
方法的具体详情如下:
包路径:org.jooby.funzy.Try
类名称:Try
方法名:onFailure
[英]Run the given action if and only if this is a failure.
[中]当且仅当此操作失败时运行给定操作。
代码示例来源:origin: jooby-project/jooby
@Override
public void writeSuccess() {
Try.run(success::invoke)
.onFailure(cause -> log.error("Error while invoking success callback", cause));
}
代码示例来源:origin: jooby-project/jooby
@Override
public void run() {
if (watcher != null) {
log.debug("stopping: watcher");
Try.run(watcher::stop).onFailure(ex -> log.debug("Stop of watcher resulted in error", ex));
}
commands.forEach(cmd -> {
log.debug("stopping: " + cmd);
Try.run(cmd::stop).onFailure(ex -> log.error("Stop of " + cmd + " resulted in error", ex));
});
}
}
代码示例来源:origin: jooby-project/jooby
protected void fireCloseEvent() {
Throwing.Runnable task = onclose.getAndSet(null);
if (task != null) {
Try.run(task).onFailure(ex -> log.error("close callback resulted in error", ex));
}
}
代码示例来源:origin: jooby-project/jooby
public void close() throws Exception {
reporters.forEach(r -> Try.run(r::close)
.onFailure(cause -> log.error("close of {} resulted in error", r, cause)));
}
代码示例来源:origin: jooby-project/jooby
private static void fireStop(final Jooby app, final Logger log,
final List<Throwing.Consumer<Registry>> onStop) {
// stop services
onStop.forEach(c -> Try.run(() -> c.accept(app))
.onFailure(x -> log.error("shutdown of {} resulted in error", c, x)));
}
代码示例来源:origin: jooby-project/jooby
public static void forceConverter(final AsyncRepository repo, final JacksonMapper converter) {
Try.run(() -> FIELD.apply(repo.getClass()).set(repo, converter))
.onFailure(x -> log.warn("Set converter resulted in error", x));
}
}
代码示例来源:origin: jooby-project/jooby
@Override
public void writeFailed(final Throwable cause) {
Try.run(() -> err.onError(cause))
.onFailure(ex -> log.error("Error while invoking err callback", ex));
}
};
代码示例来源:origin: jooby-project/jooby
public void done(final Optional<Throwable> cause) {
if (complete.size() > 0) {
for (Route.Complete h : complete) {
Try.run(() -> h.handle(req, this, cause))
.onFailure(x -> LoggerFactory.getLogger(Response.class)
.error("complete listener resulted in error", x));
}
complete.clear();
}
end();
}
代码示例来源:origin: jooby-project/jooby
@Override
protected void closeInternal() {
Try.run(() -> rsp.closeOutput())
.onFailure(cause -> log.debug("error while closing connection", cause));
}
代码示例来源:origin: jooby-project/jooby
static Handler tryPage(final Handler handler, final Logger log) {
return (req, rsp, ex) -> Try.run(() -> handler.handle(req, rsp, ex)).onFailure(cause -> log.debug("execution of pretty err page resulted in exception", cause));
}
代码示例来源:origin: jooby-project/jooby
@SuppressWarnings({"rawtypes", "unchecked"})
private <T> T configure(final T source, final Config config) {
List<Method> methods = Lists.newArrayList(source.getClass().getMethods());
config.entrySet().forEach(o -> {
String key = o.getKey();
String setter = "set" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, key);
Object raw = o.getValue().unwrapped();
Optional<Method> result = methods.stream()
.filter(m -> m.getName().equals(setter))
.findFirst();
if (result.isPresent()) {
Method method = result.get();
Class type = method.getParameterTypes()[0];
Object value = cast(type, raw);
Try.run(() -> method.invoke(source, value)).onFailure(ex -> {
throw new IllegalArgumentException("Bad option: <" + raw + "> for: " + method, ex);
});
} else {
log.error("Unknown option camel.{} = {}", key, raw);
}
});
return source;
}
代码示例来源:origin: jooby-project/jooby
.onFailure(x -> log.error("can't copy {}", it, x));
代码示例来源:origin: jooby-project/jooby
aggregators.accept(a);
a.fileset().forEach(f -> values.add(spath(f)));
})).onFailure(x -> values.add(it)));
raw.put(key.get(0), values);
graph.put(key.get(0), key);
代码示例来源:origin: jooby-project/jooby
services.forEach(exec -> Try.run(() -> exec.getValue().shutdown()).onFailure(cause -> log.error("shutdown of {} resulted in error", exec.getKey(), cause)));
services.clear();
});
代码示例来源:origin: jooby-project/jooby
public void end() {
try {
if (rollbackOnly) {
rollback();
} else {
commit();
}
} finally {
if (readOnly) {
setConnectionReadOnly(false);
}
String sessionId = oid(session);
log.debug("closing session: {}", sessionId);
Try.run(session::close)
.onFailure(x -> log.error("session.close() resulted in exception: {}", sessionId, x))
.onSuccess(() -> log.debug("session closed: {}", sessionId));
unbind(session.getSessionFactory());
}
}
代码示例来源:origin: jooby-project/jooby
.onFailure(x -> {
log.debug("png-fallback resulted in exception", x);
callback.call(null, toV8Array(v8, Arrays.asList(x.getMessage())));
代码示例来源:origin: jooby-project/jooby
.orElse(false));
Try.run(cluster::disconnect)
.onFailure(x -> log.debug("disconnect operation resulted in exception", x));
.onFailure(x -> log.debug("environment shutdown resulted in exception", x));
});
代码示例来源:origin: jooby-project/jooby
.onFailure(this::handleErr));
new MutantImpl(injector.getInstance(ParserExecutor.class), consumes,
new StrParamReferenceImpl("body", "message", ImmutableList.of(message))))))
.onFailure(this::handleErr));
})).onFailure(this::handleErr);
});
代码示例来源:origin: jooby-project/jooby
@Override
default void handle(final Request req, final Response rsp, final Chain chain) throws Throwable {
Sse sse = req.require(Sse.class);
String path = req.path();
rsp.send(new Deferred(deferred -> {
try {
sse.handshake(req, () -> {
Try.run(() -> handle(req, sse))
.onSuccess(() -> deferred.resolve(null))
.onFailure(ex -> {
deferred.reject(ex);
Logger log = LoggerFactory.getLogger(Sse.class);
log.error("execution of {} resulted in error", path, ex);
});
});
} catch (Exception ex) {
deferred.reject(ex);
}
}));
}
代码示例来源:origin: jooby-project/jooby
log.debug("Stopping {}", cstr);
Try.run(session::close)
.onFailure(x -> log.error("session.close() resulted in exception", x));
内容来源于网络,如有侵权,请联系作者删除!