本文整理了Java中com.linecorp.armeria.common.util.Exceptions.peel()
方法的一些代码示例,展示了Exceptions.peel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Exceptions.peel()
方法的具体详情如下:
包路径:com.linecorp.armeria.common.util.Exceptions
类名称:Exceptions
方法名:peel
[英]Returns the cause of the specified throwable peeling it recursively, if it is one of the CompletionException, ExecutionException, InvocationTargetExceptionor ExceptionInInitializerError. Otherwise returns the throwable.
[中]如果指定的可丢弃文件是CompletionException、ExecutionException、InvocationTargetExceptionor或ExceptionInInitializerError中的一个,则以递归方式返回该文件的原因。否则返回可丢弃的。
代码示例来源:origin: line/armeria
@Nullable
private static String handleThrowable(@Nullable Throwable cause) {
if (cause == null) {
return null;
}
cause = Exceptions.peel(cause);
final String message = cause.getMessage();
return message != null ? cause.getClass().getSimpleName() + ": " + message
: cause.getClass().getSimpleName();
}
代码示例来源:origin: line/armeria
private HttpFile cache() {
// TODO(trustin): We assume here that the file being read is small enough that it will not block
// an event loop for a long time. Revisit if the assumption turns out to be false.
AggregatedHttpFile cachedFile = null;
try {
this.cachedFile = cachedFile = file.aggregate(MoreExecutors.directExecutor()).get();
} catch (Exception e) {
this.cachedFile = null;
logger.warn("Failed to cache a file: {}", file, Exceptions.peel(e));
}
return MoreObjects.firstNonNull(cachedFile, file);
}
代码示例来源:origin: line/armeria
/**
* A {@link RetryStrategy} that retries only on {@link UnprocessedRequestException} with the specified
* {@link Backoff}.
*/
static RetryStrategy onUnprocessed(Backoff backoff) {
requireNonNull(backoff, "backoff");
return onStatus((status, thrown) -> {
if (thrown != null && Exceptions.peel(thrown) instanceof UnprocessedRequestException) {
return backoff;
}
return null;
});
}
代码示例来源:origin: line/armeria
@Override
public synchronized void stop() {
try {
if (isRunning) {
server.stop().get();
isRunning = false;
}
} catch (Exception cause) {
throw new WebServerException("Failed to stop " + ArmeriaWebServer.class.getSimpleName(),
Exceptions.peel(cause));
}
}
代码示例来源:origin: line/armeria
@Override
public Response execute() throws IOException {
final CompletableCallback completableCallback = new CompletableCallback();
enqueue(completableCallback);
try {
return completableCallback.join();
} catch (CancellationException e) {
throw new IOException(e);
} catch (CompletionException e) {
throw new IOException(Exceptions.peel(e));
}
}
代码示例来源:origin: line/armeria
private HttpFile cache(ServiceRequestContext ctx, PathAndEncoding pathAndEncoding, HttpFile file) {
assert cache != null;
// TODO(trustin): We assume here that the file being read is small enough that it will not block
// an event loop for a long time. Revisit if the assumption turns out to be false.
final AggregatedHttpFile cachedFile = cache.get(pathAndEncoding, key -> {
try {
return file.aggregateWithPooledObjects(MoreExecutors.directExecutor(), ctx.alloc()).get();
} catch (Exception e) {
logger.warn("{} Failed to cache a file: {}", ctx, file, Exceptions.peel(e));
return null;
}
});
return cachedFile != null ? cachedFile : file;
}
代码示例来源:origin: line/armeria
/**
* A synchronous version of {@link #stop()}. Exceptions occurred during shutdown are reported to
* {@link #closeFailed(Throwable)}.
*/
@Override
public final void close() {
final CompletableFuture<Void> f;
synchronized (this) {
if (state == State.STOPPED) {
return;
}
f = stop();
}
boolean interrupted = false;
for (;;) {
try {
f.get();
break;
} catch (InterruptedException ignored) {
interrupted = true;
} catch (ExecutionException e) {
closeFailed(Exceptions.peel(e));
break;
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
}
代码示例来源:origin: line/armeria
@Override
public synchronized void start() {
try {
if (!isRunning) {
server.start().get();
if (port == 0) {
// Replace the specified port number with the primary port number.
// Server#activePort doesn't return the first added port, so we need to find that.
final Optional<ServerPort> port =
server.activePorts().values().stream()
.filter(p -> p.protocols().contains(protocol))
.filter(p -> address == null ||
Arrays.equals(address.getAddress(),
p.localAddress().getAddress().getAddress()))
.findFirst();
assert port.isPresent() : "the primary port doest not exist.";
this.port = port.get().localAddress().getPort();
}
isRunning = true;
}
} catch (Exception cause) {
throw new WebServerException("Failed to start " + ArmeriaWebServer.class.getSimpleName(),
Exceptions.peel(cause));
}
}
代码示例来源:origin: line/armeria
@Override
public HttpResponse handleException(RequestContext ctx, HttpRequest req, Throwable cause) {
final Throwable peeledCause = Exceptions.peel(cause);
if (Flags.annotatedServiceExceptionVerbosity() == ExceptionVerbosity.ALL &&
logger.isWarnEnabled()) {
logger.warn("{} Exception raised by method '{}' in '{}':",
ctx, methodName, className, peeledCause);
}
for (final ExceptionHandlerFunction func : functions) {
try {
final HttpResponse response = func.handleException(ctx, req, peeledCause);
// Check the return value just in case, then pass this exception to the default handler
// if it is null.
if (response == null) {
break;
}
return response;
} catch (FallthroughException ignore) {
// Do nothing.
} catch (Exception e) {
logger.warn("{} Unexpected exception from an exception handler {}:",
ctx, func.getClass().getName(), e);
}
}
return HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP response that delegates to the {@link HttpResponse} produced by the specified
* {@link CompletionStage}. If the specified {@link CompletionStage} fails, the returned response will be
* closed with the same cause as well.
*/
static HttpResponse from(CompletionStage<? extends HttpResponse> stage) {
requireNonNull(stage, "stage");
final DeferredHttpResponse res = new DeferredHttpResponse();
stage.handle((delegate, thrown) -> {
if (thrown != null) {
res.close(Exceptions.peel(thrown));
} else if (delegate == null) {
res.close(new NullPointerException("delegate stage produced a null response: " + stage));
} else {
res.delegate(delegate);
}
return null;
});
return res;
}
代码示例来源:origin: line/armeria
return reply.get();
} catch (ExecutionException e) {
throw Exceptions.peel(e);
代码示例来源:origin: line/armeria
rollbackFailed(Exceptions.peel(stopCause));
return null;
});
代码示例来源:origin: line/armeria
/**
* Creates a new {@link RpcResponse} that is completed successfully or exceptionally based on the
* completion of the specified {@link CompletionStage}.
*/
static RpcResponse from(CompletionStage<?> stage) {
requireNonNull(stage, "stage");
final DefaultRpcResponse res = new DefaultRpcResponse();
stage.handle((value, cause) -> {
if (cause != null) {
res.completeExceptionally(cause);
} else if (value instanceof RpcResponse) {
((RpcResponse) value).handle((rpcResponseResult, rpcResponseCause) -> {
if (rpcResponseCause != null) {
res.completeExceptionally(Exceptions.peel(rpcResponseCause));
} else {
res.complete(rpcResponseResult);
}
return null;
});
} else {
res.complete(value);
}
return null;
});
return res;
}
代码示例来源:origin: line/armeria
.isInstanceOf(ExecutionException.class)
.hasCauseInstanceOf(TApplicationException.class)
.satisfies(cause -> assertThat(((TApplicationException) Exceptions.peel(cause)).getType())
.isEqualTo(TApplicationException.BAD_SEQUENCE_ID));
代码示例来源:origin: line/armeria
handlePreDecodeException(ctx, reply, func, Exceptions.peel(cause));
return null;
代码示例来源:origin: line/centraldogma
CachingRepository(Repository repo, RepositoryCache cache) {
this.repo = requireNonNull(repo, "repo");
this.cache = requireNonNull(cache, "cache").cache;
try {
final List<Commit> history = repo.history(Revision.INIT, Revision.INIT, ALL_PATH, 1).join();
firstCommit = history.get(0);
} catch (CompletionException e) {
final Throwable cause = Exceptions.peel(e);
Throwables.throwIfUnchecked(cause);
throw new StorageException("failed to retrieve the initial commit", cause);
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
CachingRepository(Repository repo, RepositoryCache cache) {
this.repo = requireNonNull(repo, "repo");
this.cache = requireNonNull(cache, "cache").cache;
try {
final List<Commit> history = repo.history(Revision.INIT, Revision.INIT, ALL_PATH, 1).join();
firstCommit = history.get(0);
} catch (CompletionException e) {
final Throwable cause = Exceptions.peel(e);
Throwables.throwIfUnchecked(cause);
throw new StorageException("failed to retrieve the initial commit", cause);
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
static HttpResponse handleException(ServiceRequestContext ctx, Throwable cause) {
cause = Exceptions.peel(cause);
if (cause instanceof RepositoryNotFoundException ||
cause instanceof ProjectNotFoundException) {
return HttpApiUtil.newResponse(ctx, HttpStatus.NOT_FOUND, cause);
} else {
return Exceptions.throwUnsafely(cause);
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded
static HttpResponse handleException(Throwable cause) {
cause = Exceptions.peel(cause);
if (cause instanceof RepositoryNotFoundException ||
cause instanceof ProjectNotFoundException) {
return HttpApiUtil.newResponse(HttpStatus.NOT_FOUND, cause);
} else {
return Exceptions.throwUnsafely(cause);
}
}
代码示例来源:origin: line/centraldogma
static HttpResponse handleException(ServiceRequestContext ctx, Throwable cause) {
cause = Exceptions.peel(cause);
if (cause instanceof RepositoryNotFoundException ||
cause instanceof ProjectNotFoundException) {
return HttpApiUtil.newResponse(ctx, HttpStatus.NOT_FOUND, cause);
} else {
return Exceptions.throwUnsafely(cause);
}
}
内容来源于网络,如有侵权,请联系作者删除!