下面列出了java.util.concurrent.ExecutionException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void runOnMain(Runnable runnable) throws WebApplicationException {
if (Sponge.getServer().isMainThread()) {
runnable.run();
} else {
CompletableFuture future = CompletableFuture.runAsync(runnable, WebAPI.syncExecutor);
try {
future.get();
} catch (InterruptedException ignored) {
} catch (ExecutionException e) {
// Rethrow any web application exceptions we get, because they're handled by the servlets
if (e.getCause() instanceof WebApplicationException)
throw (WebApplicationException)e.getCause();
e.printStackTrace();
WebAPI.sentryCapture(e);
throw new InternalServerErrorException(e.getMessage());
}
}
}
@Override
public T await() throws ApiException, IOException, InterruptedException {
try {
HTTPResponse result = call.get();
metrics.endNetwork();
return parseResponse(this, result);
} catch (ExecutionException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
} else {
// According to
// https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/urlfetch/URLFetchService
// all exceptions should be subclass of IOException so this should not happen.
throw new UnknownErrorException("Unexpected exception from " + e.getMessage());
}
}
}
/**
* Creates a RepositoryName from a known-valid string (not @-prefixed). Generally this is a
* directory that has been created via getSourceRoot() or getPathUnderExecRoot().
*/
public static RepositoryName createFromValidStrippedName(String name) {
try {
return repositoryNameCache.get("@" + name);
} catch (ExecutionException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
@Override
@Nullable
public T get(long timeout, TimeUnit unit) throws CompletionException, TimeoutException, InterruptedException {
requireNonNull(unit);
try {
return future.get(timeout, unit);
} catch (ExecutionException ex) {
throw new CompletionException(ex.getMessage(), ex.getCause());
}
}
@Override
public void join(long timeout, TimeUnit unit) throws CompletionException, TimeoutException, InterruptedException {
requireNonNull(unit);
try {
future.get(timeout, unit);
} catch (ExecutionException ex) {
throw new CompletionException(ex.getMessage(), ex.getCause());
}
}
@Override
@Nullable
public T get(long timeout, TimeUnit unit) throws CompletionException, TimeoutException, InterruptedException {
requireNonNull(unit);
try {
return future.get(timeout, unit);
} catch (ExecutionException ex) {
throw new CompletionException(ex.getMessage(), ex.getCause());
}
}
@Override
public void join(long timeout, TimeUnit unit) throws CompletionException, TimeoutException, InterruptedException {
requireNonNull(unit);
try {
future.get(timeout, unit);
} catch (ExecutionException ex) {
throw new CompletionException(ex.getMessage(), ex.getCause());
}
}
/**
* Handle ExecutionException errors when raised.
* @param executionException The exception raised.
* @return Appropriate exception instance to throw.
*/
private RuntimeException handleExecutionException(final ExecutionException executionException) {
if (executionException.getCause() != null && executionException.getCause() instanceof RuntimeException) {
return (RuntimeException) executionException.getCause();
}
return new RuntimeException(executionException.getMessage(), executionException);
}
@Override
public ValueWrapper get(Object key) {
if (this.cache instanceof LoadingCache) {
try {
Object value = ((LoadingCache<Object, Object>) this.cache).get(key);
return toValueWrapper(value);
}
catch (ExecutionException ex) {
throw new UncheckedExecutionException(ex.getMessage(), ex);
}
}
return super.get(key);
}
public SliceQuery getQuery(InternalRelationType type, Direction dir) {
CacheEntry ce;
try {
ce = cache.get(type.longId(), () -> new CacheEntry(edgeSerializer, type));
} catch (ExecutionException e) {
throw new AssertionError("Should not happen: " + e.getMessage());
}
return ce.get(dir);
}
/**
* Cancel a copy operation. Afterwards, the copy is forgotten and subsequent queries with this copy string will lead to {@link NoSuchCopyException}
*
* @param copyIdentifier
* the identifier of the copy operation which to cancel.
*
* @return a {@link CopyStatus} containing the status of the copy.
*
* @throws NoSuchCopyException
* If the copy is not known.
* @throws NotConnectedException
* If file system is closed.
* @throws XenonException
* if an I/O error occurred.
* @throws IllegalArgumentException
* If the copyIdentifier is null.
*/
public synchronized CopyStatus cancel(String copyIdentifier) throws XenonException {
if (copyIdentifier == null) {
throw new IllegalArgumentException("Copy identifier may not be null");
}
PendingCopy copy = pendingCopies.remove(copyIdentifier);
if (copy == null) {
throw new NoSuchCopyException(getAdaptorName(), "Copy not found: " + copyIdentifier);
}
copy.callback.cancel();
copy.future.cancel(true);
XenonException ex = null;
String state = "DONE";
try {
copy.future.get();
} catch (ExecutionException ee) {
ex = new XenonException(getAdaptorName(), ee.getMessage(), ee);
state = "FAILED";
} catch (CancellationException ce) {
ex = new CopyCancelledException(getAdaptorName(), "Copy cancelled by user");
state = "FAILED";
} catch (InterruptedException e) {
ex = new CopyCancelledException(getAdaptorName(), "Copy interrupted by user");
state = "FAILED";
Thread.currentThread().interrupt();
}
return new CopyStatusImplementation(copyIdentifier, state, copy.callback.getBytesToCopy(), copy.callback.getBytesCopied(), ex);
}
/**
* Handles an error while searching.
*
* @param e
* the exception
*/
private void handleSearchError(ExecutionException e) {
String message = null;
Throwable cause = e.getCause();
if (cause instanceof ParseException) {
message = cause.getMessage() != null ? cause.getMessage() : cause.toString();
} else if (cause == null) {
message = e.getMessage();
}
model.clearAllCategories();
model.setError(message);
}
/**
* {@inheritDoc}
*/
public Map<Dependency, ArtifactVersions> lookupDependenciesUpdates( Set<Dependency> dependencies,
boolean usePluginRepositories )
throws ArtifactMetadataRetrievalException, InvalidVersionSpecificationException
{
// Create the request for details collection for parallel lookup...
final List<Callable<DependencyArtifactVersions>> requestsForDetails =
new ArrayList<Callable<DependencyArtifactVersions>>( dependencies.size() );
for ( final Dependency dependency : dependencies )
{
requestsForDetails.add( new DependencyLookup( dependency, usePluginRepositories ) );
}
final Map<Dependency, ArtifactVersions> dependencyUpdates =
new TreeMap<Dependency, ArtifactVersions>( new DependencyComparator() );
// Lookup details in parallel...
final ExecutorService executor = Executors.newFixedThreadPool( LOOKUP_PARALLEL_THREADS );
try
{
final List<Future<DependencyArtifactVersions>> responseForDetails =
executor.invokeAll( requestsForDetails );
// Construct the final results...
for ( final Future<DependencyArtifactVersions> details : responseForDetails )
{
final DependencyArtifactVersions dav = details.get();
dependencyUpdates.put( dav.getDependency(), dav.getArtifactVersions() );
}
}
catch ( final ExecutionException ee )
{
throw new ArtifactMetadataRetrievalException( "Unable to acquire metadata for dependencies " + dependencies
+ ": " + ee.getMessage(), ee );
}
catch ( final InterruptedException ie )
{
throw new ArtifactMetadataRetrievalException( "Unable to acquire metadata for dependencies " + dependencies
+ ": " + ie.getMessage(), ie );
}
finally
{
executor.shutdownNow();
}
return dependencyUpdates;
}
/**
* {@inheritDoc}
*/
public Map<Plugin, PluginUpdatesDetails> lookupPluginsUpdates( Set<Plugin> plugins, boolean allowSnapshots )
throws ArtifactMetadataRetrievalException, InvalidVersionSpecificationException
{
// Create the request for details collection for parallel lookup...
final List<Callable<PluginPluginUpdatesDetails>> requestsForDetails =
new ArrayList<Callable<PluginPluginUpdatesDetails>>( plugins.size() );
for ( final Plugin plugin : plugins )
{
requestsForDetails.add( new PluginLookup( plugin, allowSnapshots ) );
}
final Map<Plugin, PluginUpdatesDetails> pluginUpdates =
new TreeMap<Plugin, PluginUpdatesDetails>( new PluginComparator() );
// Lookup details in parallel...
final ExecutorService executor = Executors.newFixedThreadPool( LOOKUP_PARALLEL_THREADS );
try
{
final List<Future<PluginPluginUpdatesDetails>> responseForDetails =
executor.invokeAll( requestsForDetails );
// Construct the final results...
for ( final Future<PluginPluginUpdatesDetails> details : responseForDetails )
{
final PluginPluginUpdatesDetails pud = details.get();
pluginUpdates.put( pud.getPlugin(), pud.getPluginUpdatesDetails() );
}
}
catch ( final ExecutionException ee )
{
throw new ArtifactMetadataRetrievalException( "Unable to acquire metadata for plugins " + plugins + ": "
+ ee.getMessage(), ee );
}
catch ( final InterruptedException ie )
{
throw new ArtifactMetadataRetrievalException( "Unable to acquire metadata for plugins " + plugins + ": "
+ ie.getMessage(), ie );
}
finally
{
executor.shutdownNow();
}
return pluginUpdates;
}
/**
* Inspects the cause of the specified {@code ExecutionException} and
* creates a {@code ConcurrentRuntimeException} with the checked cause if
* necessary. This method works exactly like
* {@link #extractCause(ExecutionException)}. The only difference is that
* the cause of the specified {@code ExecutionException} is extracted as a
* runtime exception. This is an alternative for client code that does not
* want to deal with checked exceptions.
*
* @param ex the exception to be processed
* @return a {@code ConcurrentRuntimeException} with the checked cause
*/
public static ConcurrentRuntimeException extractCauseUnchecked(
final ExecutionException ex) {
if (ex == null || ex.getCause() == null) {
return null;
}
throwCause(ex);
return new ConcurrentRuntimeException(ex.getMessage(), ex.getCause());
}
/**
* Inspects the cause of the specified {@code ExecutionException} and
* creates a {@code ConcurrentException} with the checked cause if
* necessary. This method performs the following checks on the cause of the
* passed in exception:
* <ul>
* <li>If the passed in exception is <b>null</b> or the cause is
* <b>null</b>, this method returns <b>null</b>.</li>
* <li>If the cause is a runtime exception, it is directly thrown.</li>
* <li>If the cause is an error, it is directly thrown, too.</li>
* <li>In any other case the cause is a checked exception. The method then
* creates a {@link ConcurrentException}, initializes it with the cause, and
* returns it.</li>
* </ul>
*
* @param ex the exception to be processed
* @return a {@code ConcurrentException} with the checked cause
*/
public static ConcurrentException extractCause(ExecutionException ex) {
if (ex == null || ex.getCause() == null) {
return null;
}
throwCause(ex);
return new ConcurrentException(ex.getMessage(), ex.getCause());
}
/**
* Inspects the cause of the specified {@code ExecutionException} and
* creates a {@code ConcurrentException} with the checked cause if
* necessary. This method performs the following checks on the cause of the
* passed in exception:
* <ul>
* <li>If the passed in exception is <b>null</b> or the cause is
* <b>null</b>, this method returns <b>null</b>.</li>
* <li>If the cause is a runtime exception, it is directly thrown.</li>
* <li>If the cause is an error, it is directly thrown, too.</li>
* <li>In any other case the cause is a checked exception. The method then
* creates a {@link ConcurrentException}, initializes it with the cause, and
* returns it.</li>
* </ul>
*
* @param ex the exception to be processed
* @return a {@code ConcurrentException} with the checked cause
*/
public static ConcurrentException extractCause(ExecutionException ex) {
if (ex == null || ex.getCause() == null) {
return null;
}
throwCause(ex);
return new ConcurrentException(ex.getMessage(), ex.getCause());
}
/**
* Inspects the cause of the specified {@code ExecutionException} and
* creates a {@code ConcurrentException} with the checked cause if
* necessary. This method performs the following checks on the cause of the
* passed in exception:
* <ul>
* <li>If the passed in exception is <b>null</b> or the cause is
* <b>null</b>, this method returns <b>null</b>.</li>
* <li>If the cause is a runtime exception, it is directly thrown.</li>
* <li>If the cause is an error, it is directly thrown, too.</li>
* <li>In any other case the cause is a checked exception. The method then
* creates a {@link ConcurrentException}, initializes it with the cause, and
* returns it.</li>
* </ul>
*
* @param ex the exception to be processed
* @return a {@code ConcurrentException} with the checked cause
*/
public static ConcurrentException extractCause(ExecutionException ex) {
if (ex == null || ex.getCause() == null) {
return null;
}
throwCause(ex);
return new ConcurrentException(ex.getMessage(), ex.getCause());
}
/**
* Inspects the cause of the specified {@code ExecutionException} and
* creates a {@code ConcurrentRuntimeException} with the checked cause if
* necessary. This method works exactly like
* {@link #extractCause(ExecutionException)}. The only difference is that
* the cause of the specified {@code ExecutionException} is extracted as a
* runtime exception. This is an alternative for client code that does not
* want to deal with checked exceptions.
*
* @param ex the exception to be processed
* @return a {@code ConcurrentRuntimeException} with the checked cause
*/
public static ConcurrentRuntimeException extractCauseUnchecked(
ExecutionException ex) {
if (ex == null || ex.getCause() == null) {
return null;
}
throwCause(ex);
return new ConcurrentRuntimeException(ex.getMessage(), ex.getCause());
}
/**
* Inspects the cause of the specified {@code ExecutionException} and
* creates a {@code ConcurrentRuntimeException} with the checked cause if
* necessary. This method works exactly like
* {@link #extractCause(ExecutionException)}. The only difference is that
* the cause of the specified {@code ExecutionException} is extracted as a
* runtime exception. This is an alternative for client code that does not
* want to deal with checked exceptions.
*
* @param ex the exception to be processed
* @return a {@code ConcurrentRuntimeException} with the checked cause
*/
public static ConcurrentRuntimeException extractCauseUnchecked(
ExecutionException ex) {
if (ex == null || ex.getCause() == null) {
return null;
}
throwCause(ex);
return new ConcurrentRuntimeException(ex.getMessage(), ex.getCause());
}