Example usage for com.google.common.util.concurrent UncheckedExecutionException getCause

List of usage examples for com.google.common.util.concurrent UncheckedExecutionException getCause

Introduction

In this page you can find the example usage for com.google.common.util.concurrent UncheckedExecutionException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore.java

@SuppressWarnings("unchecked")
private <T extends Document> T find(final Collection<T> collection, final String key, boolean preferCached,
        final int maxCacheAge) {
    if (collection != Collection.NODES) {
        return findUncachedWithRetry(collection, key, DocumentReadPreference.PRIMARY, 2);
    }/*from   w ww. j  a  v  a2s  .  co  m*/
    NodeDocument doc;
    if (maxCacheAge > 0 || preferCached) {
        // first try without lock
        doc = nodesCache.getIfPresent(key);
        if (doc != null) {
            if (preferCached || getTime() - doc.getCreated() < maxCacheAge) {
                stats.doneFindCached(collection, key);
                if (doc == NodeDocument.NULL) {
                    return null;
                }
                return (T) doc;
            }
        }
    }
    Throwable t;
    try {
        Lock lock = nodeLocks.acquire(key);
        try {
            if (maxCacheAge > 0 || preferCached) {
                // try again some other thread may have populated
                // the cache by now
                doc = nodesCache.getIfPresent(key);
                if (doc != null) {
                    if (preferCached || getTime() - doc.getCreated() < maxCacheAge) {
                        stats.doneFindCached(collection, key);
                        if (doc == NodeDocument.NULL) {
                            return null;
                        }
                        return (T) doc;
                    }
                }
            }
            final NodeDocument d = (NodeDocument) findUncachedWithRetry(collection, key,
                    getReadPreference(maxCacheAge), 2);
            invalidateCache(collection, key);
            doc = nodesCache.get(key, new Callable<NodeDocument>() {
                @Override
                public NodeDocument call() throws Exception {
                    return d == null ? NodeDocument.NULL : d;
                }
            });
        } finally {
            lock.unlock();
        }
        if (doc == NodeDocument.NULL) {
            return null;
        } else {
            return (T) doc;
        }
    } catch (UncheckedExecutionException e) {
        t = e.getCause();
    } catch (ExecutionException e) {
        t = e.getCause();
    } catch (RuntimeException e) {
        t = e;
    }
    throw new DocumentStoreException("Failed to load document with " + key, t);
}

From source file:com.facebook.buck.apple.ProjectGenerator.java

public void createXcodeProjects() throws IOException {
    LOG.debug("Creating projects for targets %s", initialTargets);

    try {//w  ww .  j a  v  a 2  s  . c  om
        for (TargetNode<?> targetNode : targetGraph.getNodes()) {
            if (isBuiltByCurrentProject(targetNode.getBuildTarget())) {
                LOG.debug("Including rule %s in project", targetNode);
                // Trigger the loading cache to call the generateProjectTarget function.
                Optional<PBXTarget> target = targetNodeToProjectTarget.getUnchecked(targetNode);
                if (target.isPresent()) {
                    targetNodeToGeneratedProjectTargetBuilder.put(targetNode, target.get());
                }
            } else {
                LOG.verbose("Excluding rule %s (not built by current project)", targetNode);
            }
        }

        if (targetToBuildWithBuck.isPresent()) {
            generateBuildWithBuckTarget(targetGraph.get(targetToBuildWithBuck.get()));
        }

        int combinedTestIndex = 0;
        for (AppleTestBundleParamsKey key : additionalCombinedTestTargets.keySet()) {
            generateCombinedTestTarget(deriveCombinedTestTargetNameFromKey(key, combinedTestIndex++), key,
                    additionalCombinedTestTargets.get(key));
        }

        for (String configName : targetConfigNamesBuilder.build()) {
            XCBuildConfiguration outputConfig = project.getBuildConfigurationList()
                    .getBuildConfigurationsByName().getUnchecked(configName);
            outputConfig.setBuildSettings(new NSDictionary());
        }

        writeProjectFile(project);

        projectGenerated = true;
    } catch (UncheckedExecutionException e) {
        // if any code throws an exception, they tend to get wrapped in LoadingCache's
        // UncheckedExecutionException. Unwrap it if its cause is HumanReadable.
        UncheckedExecutionException originalException = e;
        while (e.getCause() instanceof UncheckedExecutionException) {
            e = (UncheckedExecutionException) e.getCause();
        }
        if (e.getCause() instanceof HumanReadableException) {
            throw (HumanReadableException) e.getCause();
        } else {
            throw originalException;
        }
    }
}

From source file:com.facebook.buck.apple.project_generator.ProjectGenerator.java

public void createXcodeProjects() throws IOException {
    LOG.debug("Creating projects for targets %s", initialTargets);

    boolean hasAtLeastOneTarget = false;
    try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus,
            PerfEventId.of("xcode_project_generation"), ImmutableMap.of("Path", getProjectPath()))) {
        for (TargetNode<?, ?> targetNode : targetGraph.getNodes()) {
            if (isBuiltByCurrentProject(targetNode.getBuildTarget())) {
                LOG.debug("Including rule %s in project", targetNode);
                // Trigger the loading cache to call the generateProjectTarget function.
                Optional<PBXTarget> target = targetNodeToProjectTarget.getUnchecked(targetNode);
                if (target.isPresent()) {
                    targetNodeToGeneratedProjectTargetBuilder.put(targetNode, target.get());
                }//from  w  w  w. ja  v  a  2s. co  m
                if (shouldIncludeBuildTargetIntoFocusedProject(focusModules, targetNode.getBuildTarget())) {
                    // If the target is not included, we still need to do other operations to generate
                    // the required header maps.
                    hasAtLeastOneTarget = true;
                }
            } else {
                LOG.verbose("Excluding rule %s (not built by current project)", targetNode);
            }
        }

        if (!hasAtLeastOneTarget && focusModules.size() != 0) {
            return;
        }

        if (targetToBuildWithBuck.isPresent()) {
            generateBuildWithBuckTarget(targetGraph.get(targetToBuildWithBuck.get()));
        }

        for (String configName : targetConfigNamesBuilder.build()) {
            XCBuildConfiguration outputConfig = project.getBuildConfigurationList()
                    .getBuildConfigurationsByName().getUnchecked(configName);
            outputConfig.setBuildSettings(new NSDictionary());
        }

        writeProjectFile(project);

        projectGenerated = true;
    } catch (UncheckedExecutionException e) {
        // if any code throws an exception, they tend to get wrapped in LoadingCache's
        // UncheckedExecutionException. Unwrap it if its cause is HumanReadable.
        UncheckedExecutionException originalException = e;
        while (e.getCause() instanceof UncheckedExecutionException) {
            e = (UncheckedExecutionException) e.getCause();
        }
        if (e.getCause() instanceof HumanReadableException) {
            throw (HumanReadableException) e.getCause();
        } else {
            throw originalException;
        }
    }
}

From source file:org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore.java

/**
 * Get the node for the given path and revision. The returned object might
 * not be modified directly.//w  w w  .ja  va 2  s  .com
 *
 * @param path the path of the node.
 * @param rev the read revision.
 * @return the node or <code>null</code> if the node does not exist at the
 *          given revision.
 */
@CheckForNull
DocumentNodeState getNode(@Nonnull final String path, @Nonnull final RevisionVector rev) {
    checkNotNull(rev);
    checkNotNull(path);
    final long start = PERFLOG.start();
    try {
        PathRev key = new PathRev(path, rev);
        DocumentNodeState node = nodeCache.get(key, new Callable<DocumentNodeState>() {
            @Override
            public DocumentNodeState call() throws Exception {
                boolean nodeDoesNotExist = checkNodeNotExistsFromChildrenCache(path, rev);
                if (nodeDoesNotExist) {
                    return missing;
                }
                DocumentNodeState n = readNode(path, rev);
                if (n == null) {
                    n = missing;
                }
                return n;
            }
        });
        final DocumentNodeState result = node == missing || node.equals(missing) ? null : node;
        PERFLOG.end(start, 1, "getNode: path={}, rev={}", path, rev);
        return result;
    } catch (UncheckedExecutionException e) {
        throw DocumentStoreException.convert(e.getCause());
    } catch (ExecutionException e) {
        throw DocumentStoreException.convert(e.getCause());
    }
}

From source file:org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore.java

DocumentNodeState.Children getChildren(@Nonnull final AbstractDocumentNodeState parent,
        @Nullable final String name, final int limit) throws DocumentStoreException {
    if (checkNotNull(parent).hasNoChildren()) {
        return DocumentNodeState.NO_CHILDREN;
    }/*from   w w  w. j a v  a2  s.  c o m*/
    final String path = checkNotNull(parent).getPath();
    final RevisionVector readRevision = parent.getLastRevision();
    try {
        PathRev key = childNodeCacheKey(path, readRevision, name);
        DocumentNodeState.Children children = nodeChildrenCache.get(key,
                new Callable<DocumentNodeState.Children>() {
                    @Override
                    public DocumentNodeState.Children call() throws Exception {
                        return readChildren(parent, name, limit);
                    }
                });
        if (children.children.size() < limit && children.hasMore) {
            // not enough children loaded - load more,
            // and put that in the cache
            // (not using nodeChildrenCache.invalidate, because
            // the generational persistent cache doesn't support that)
            children = readChildren(parent, name, limit);
            nodeChildrenCache.put(key, children);
        }
        return children;
    } catch (UncheckedExecutionException e) {
        throw DocumentStoreException.convert(e.getCause(),
                "Error occurred while fetching children for path " + path);
    } catch (ExecutionException e) {
        throw DocumentStoreException.convert(e.getCause(),
                "Error occurred while fetching children for path " + path);
    }
}

From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java

public void createXcodeProjects() throws IOException {
    LOG.debug("Creating projects for targets %s", initialTargets);

    boolean hasAtLeastOneTarget = false;
    try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus,
            PerfEventId.of("xcode_project_generation"), ImmutableMap.of("Path", getProjectPath()))) {

        // Filter out nodes that aren't included in project.
        ImmutableSet.Builder<TargetNode<?>> projectTargetsBuilder = ImmutableSet.builder();
        for (TargetNode<?> targetNode : targetGraph.getNodes()) {
            if (isBuiltByCurrentProject(targetNode.getBuildTarget())) {
                LOG.debug("Including rule %s in project", targetNode);
                projectTargetsBuilder.add(targetNode);

                if (focusModules.isFocusedOn(targetNode.getBuildTarget())) {
                    // If the target is not included, we still need to do other operations to generate
                    // the required header maps.
                    hasAtLeastOneTarget = true;
                }/*from  w w  w .  j a v  a2  s. com*/
            } else {
                LOG.verbose("Excluding rule %s (not built by current project)", targetNode);
            }
        }
        final ImmutableSet<TargetNode<?>> projectTargets = projectTargetsBuilder.build();

        // Trigger the loading cache for the workspace target if it's in the project. This ensures the
        // workspace target isn't filtered later by loading it first.
        final Optional<TargetNode<?>> workspaceTargetNode = workspaceTarget
                .map(target -> targetGraph.get(target));
        workspaceTargetNode.filter(targetNode -> projectTargets.contains(targetNode))
                .ifPresent(targetNode -> triggerLoadingCache(targetNode));

        // Trigger the loading cache to call the generateProjectTarget function on all other targets.
        // Exclude the workspace target since it's loaded above.
        RichStream.from(projectTargets)
                .filter(input -> !workspaceTargetNode.isPresent() || !input.equals(workspaceTargetNode.get()))
                .forEach(input -> triggerLoadingCache(input));

        addGenruleFiles();

        if (!hasAtLeastOneTarget && focusModules.hasFocus()) {
            return;
        }

        if (shouldMergeHeaderMaps() && isMainProject) {
            createMergedHeaderMap();
        }

        for (String configName : targetConfigNamesBuilder.build()) {
            XCBuildConfiguration outputConfig = project.getBuildConfigurationList()
                    .getBuildConfigurationsByName().getUnchecked(configName);
            outputConfig.setBuildSettings(new NSDictionary());
        }

        if (!options.shouldGenerateHeaderSymlinkTreesOnly()) {
            writeProjectFile(project);
        }

        projectGenerated = true;
    } catch (UncheckedExecutionException e) {
        // if any code throws an exception, they tend to get wrapped in LoadingCache's
        // UncheckedExecutionException. Unwrap it if its cause is HumanReadable.
        UncheckedExecutionException originalException = e;
        while (e.getCause() instanceof UncheckedExecutionException) {
            e = (UncheckedExecutionException) e.getCause();
        }
        if (e.getCause() instanceof HumanReadableException) {
            throw (HumanReadableException) e.getCause();
        } else {
            throw originalException;
        }
    }
}