本文整理汇总了Java中javaslang.control.Try.isSuccess方法的典型用法代码示例。如果您正苦于以下问题:Java Try.isSuccess方法的具体用法?Java Try.isSuccess怎么用?Java Try.isSuccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javaslang.control.Try
的用法示例。
在下文中一共展示了Try.isSuccess方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import javaslang.control.Try; //导入方法依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
final String operation = method.getName();
final Instant t0 = time.get();
final Try<?> result = Try.of(() -> {
try {
return method.invoke(delegate, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
});
final long durationMillis = t0.until(time.get(), ChronoUnit.MILLIS);
// TODO: Instrument at a lower level to catch errors with greater granularity. At this level we might not see
// all errors as the implementation might swallow exceptions, perform retries, etc.
result.onFailure(error -> {
if (delegate instanceof DockerRunner) {
reportDockerOperationError(operation, durationMillis, error);
}
});
final String status = (result.isSuccess()) ? "success" : "failure";
if (delegate instanceof Storage) {
stats.recordStorageOperation(operation, durationMillis, status);
} else if (delegate instanceof DockerRunner) {
stats.recordDockerOperation(operation, durationMillis, status);
}
// Propagate failure
if (result.isFailure()) {
throw result.getCause();
}
// Return successful result
return result.get();
}
示例2: getDisplayname
import javaslang.control.Try; //导入方法依赖的package包/类
public static Optional<String> getDisplayname(GraphTraversalSource traversalSource, Vertex vertex,
Collection targetCollection) {
ReadableProperty displayNameProperty = targetCollection.getDisplayName();
if (displayNameProperty != null) {
GraphTraversal<Vertex, Try<JsonNode>> displayNameGetter = traversalSource.V(vertex.id()).union(
targetCollection.getDisplayName().traversalJson()
);
if (displayNameGetter.hasNext()) {
Try<JsonNode> traversalResult = displayNameGetter.next();
if (!traversalResult.isSuccess()) {
LOG.debug(databaseInvariant, "Retrieving displayname failed", traversalResult.getCause());
} else {
if (traversalResult.get() == null) {
LOG.debug(databaseInvariant, "Displayname was null");
} else {
if (!traversalResult.get().isTextual()) {
LOG.debug(databaseInvariant, "Displayname was not a string but " + traversalResult.get().toString());
} else {
return Optional.of(traversalResult.get().asText());
}
}
}
} else {
LOG.debug(databaseInvariant, "Displayname traversal resulted in no results: " + displayNameGetter);
}
} else {
LOG.debug("No displayname configured for " + targetCollection.getEntityTypeName());
//FIXME: deze wordt gegooid tijdens de finish. da's raar
}
return Optional.empty();
}
示例3: assertFailure
import javaslang.control.Try; //导入方法依赖的package包/类
public static <T> void assertFailure(@Nonnull final Try<T> tryObj, @Nonnull final Consumer<Throwable> assertions) {
if (tryObj.isSuccess()) {
fail("Expected failure, but was: " + tryObj.get());
}
assertions.accept(tryObj.getCause());
}