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.auraframework.impl.RegistryServiceImpl.java

@Override
public RegistrySet getDefaultRegistrySet(Mode mode, Authentication access) {
    if (cachingService == null || mode == null || access == null) {
        return buildDefaultRegistrySet(mode, access);
    }//from w  w  w . j a  v  a 2 s  . c  o  m

    Cache<RegistrySetKey, RegistrySet> cache = cachingService.getRegistrySetCache();
    if (cache == null) {
        return buildDefaultRegistrySet(mode, access);
    }

    // build cachekey
    String sessionCacheKey = configAdapter.getSessionCacheKey();
    if (sessionCacheKey == null) {

        // if session cache key is null, it means that we're not caching this.
        return buildDefaultRegistrySet(mode, access);
    }

    final RegistrySetKey registrySetCacheKey = new RegistrySetKey(mode, access, sessionCacheKey);

    try {
        return cache.get(registrySetCacheKey, new Callable<RegistrySet>() {

            @Override
            public RegistrySet call() throws Exception {
                RegistrySet res = buildDefaultRegistrySet(mode, access);

                if (res == null) {
                    // see com.google.common.cache.Cache#get; this method may never return null.
                    throw new NullPointerException("null RegistrySet for key=" + registrySetCacheKey);
                }
                return res;
            }
        });
    } catch (UncheckedExecutionException e) {
        // thrown if a unchecked exception was thrown in call
        throw (RuntimeException) e.getCause();
    } catch (ExecutionException e) {
        // thrown if a checked exception was thrown in call
        throw new RuntimeException(e.getCause());
    } catch (ExecutionError e) {
        // if an error was thrown while loading the value.
        throw new Error(e.getCause());
    }
}

From source file:com.datastax.driver.core.CodecRegistry.java

@SuppressWarnings("unchecked")
private <T> TypeCodec<T> lookupCodec(DataType cqlType, TypeToken<T> javaType) {
    checkNotNull(cqlType, "Parameter cqlType cannot be null");
    if (logger.isTraceEnabled())
        logger.trace("Querying cache for codec [{} <-> {}]", toString(cqlType), toString(javaType));
    CacheKey cacheKey = new CacheKey(cqlType, javaType);
    try {/*from   ww w.j  a v  a  2  s . c  o m*/
        TypeCodec<?> codec = cache.get(cacheKey);
        logger.trace("Returning cached codec {}", codec);
        return (TypeCodec<T>) codec;
    } catch (UncheckedExecutionException e) {
        if (e.getCause() instanceof CodecNotFoundException) {
            throw (CodecNotFoundException) e.getCause();
        }
        throw new CodecNotFoundException(e.getCause(), cqlType, javaType);
    } catch (RuntimeException e) {
        throw new CodecNotFoundException(e.getCause(), cqlType, javaType);
    } catch (ExecutionException e) {
        throw new CodecNotFoundException(e.getCause(), cqlType, javaType);
    }
}

From source file:org.apache.nifi.web.security.x509.ocsp.OcspCertificateValidator.java

/**
 * Validates the specified certificate using OCSP if configured.
 *
 * @param certificates the client certificates
 * @throws CertificateStatusException ex
 *//*from www. j a v  a 2 s  .  co m*/
public void validate(final X509Certificate[] certificates) throws CertificateStatusException {
    // only validate if configured to do so
    if (client != null && certificates != null && certificates.length > 0) {
        final X509Certificate subjectCertificate = getSubjectCertificate(certificates);
        final X509Certificate issuerCertificate = getIssuerCertificate(certificates);
        if (issuerCertificate == null) {
            throw new IllegalArgumentException(String.format(
                    "Unable to obtain certificate of issuer <%s> for the specified subject certificate <%s>.",
                    subjectCertificate.getIssuerX500Principal().getName(),
                    subjectCertificate.getSubjectX500Principal().getName()));
        }

        // create the ocsp status key
        final OcspRequest ocspRequest = new OcspRequest(subjectCertificate, issuerCertificate);

        try {
            // determine the status and ensure it isn't verified as revoked
            final OcspStatus ocspStatus = ocspCache.getUnchecked(ocspRequest);

            // we only disallow when we have a verified response that states the certificate is revoked
            if (VerificationStatus.Verified.equals(ocspStatus.getVerificationStatus())
                    && ValidationStatus.Revoked.equals(ocspStatus.getValidationStatus())) {
                throw new CertificateStatusException(String.format(
                        "Client certificate for <%s> is revoked according to the certificate authority.",
                        subjectCertificate.getSubjectX500Principal().getName()));
            }
        } catch (final UncheckedExecutionException uee) {
            logger.warn(String.format("Unable to validate client certificate via OCSP: <%s>",
                    subjectCertificate.getSubjectX500Principal().getName()), uee.getCause());
        }
    }
}

From source file:io.prestosql.type.TypeRegistry.java

@Override
public Type getType(TypeSignature signature) {
    Type type = types.get(signature);
    if (type == null) {
        try {//from   w ww.j  ava2 s  .c o  m
            return parametricTypeCache.getUnchecked(signature);
        } catch (UncheckedExecutionException e) {
            throwIfUnchecked(e.getCause());
            throw new RuntimeException(e.getCause());
        }
    }
    return type;
}

From source file:org.apache.brooklyn.location.jclouds.networking.JcloudsLocationSecurityGroupCustomizer.java

private SecurityGroup getSecurityGroup(final String nodeId, final SecurityGroupExtension securityApi,
        final String locationId) {
    // Expect to have two security groups on the node: one shared between all nodes in the location,
    // that is cached in sharedGroupCache, and one created by Jclouds that is unique to the node.
    // Relies on customize having been called before. This should be safe because the arguments
    // needed to call this method are not available until post-instance creation.
    SecurityGroup machineUniqueSecurityGroup;
    Tasks.setBlockingDetails("Loading unique security group for node: " + nodeId);
    try {//from www . j  a v  a 2s .  c  o m
        machineUniqueSecurityGroup = uniqueGroupCache.get(nodeId, new Callable<SecurityGroup>() {
            @Override
            public SecurityGroup call() throws Exception {
                SecurityGroup sg = getUniqueSecurityGroupForNodeCachingSharedGroupIfPreviouslyUnknown(nodeId,
                        locationId, securityApi);
                if (sg == null) {
                    throw new IllegalStateException("Failed to find machine-unique group on node: " + nodeId);
                }
                return sg;
            }
        });
    } catch (UncheckedExecutionException e) {
        throw Throwables.propagate(new Exception(e.getCause()));
    } catch (ExecutionException e) {
        throw Throwables.propagate(new Exception(e.getCause()));
    } finally {
        Tasks.resetBlockingDetails();
    }
    return machineUniqueSecurityGroup;
}

From source file:io.prestosql.plugin.raptor.legacy.metadata.DatabaseShardManager.java

private int getOrCreateNodeId(String nodeIdentifier) {
    try {/*from ww w . j  a va  2s.  c o  m*/
        return nodeIdCache.getUnchecked(nodeIdentifier);
    } catch (UncheckedExecutionException e) {
        throwIfInstanceOf(e.getCause(), PrestoException.class);
        throw e;
    }
}

From source file:io.prestosql.plugin.raptor.legacy.metadata.DatabaseShardManager.java

@Override
public List<String> getBucketAssignments(long distributionId) {
    try {//from w w w  .  j  a  v a  2  s  .c o m
        return bucketAssignmentsCache.getUnchecked(distributionId);
    } catch (UncheckedExecutionException e) {
        throwIfInstanceOf(e.getCause(), PrestoException.class);
        throw e;
    }
}

From source file:com.facebook.presto.metadata.FunctionRegistry.java

public WindowFunctionSupplier getWindowFunctionImplementation(Signature signature) {
    checkArgument(signature.getKind() == WINDOW || signature.getKind() == AGGREGATE,
            "%s is not a window function", signature);
    checkArgument(signature.getTypeParameters().isEmpty(), "%s has unbound type parameters", signature);
    Iterable<SqlFunction> candidates = functions.get(QualifiedName.of(signature.getName()));
    // search for exact match
    for (SqlFunction operator : candidates) {
        Type returnType = typeManager.getType(signature.getReturnType());
        List<Type> argumentTypes = resolveTypes(signature.getArgumentTypes(), typeManager);
        Map<String, Type> boundTypeParameters = operator.getSignature().bindTypeParameters(returnType,
                argumentTypes, false, typeManager);
        if (boundTypeParameters != null) {
            try {
                return specializedWindowCache.getUnchecked(new SpecializedFunctionKey(operator,
                        boundTypeParameters, signature.getArgumentTypes().size()));
            } catch (UncheckedExecutionException e) {
                throw Throwables.propagate(e.getCause());
            }/*from ww  w .java  2  s  . c om*/
        }
    }
    throw new PrestoException(FUNCTION_IMPLEMENTATION_MISSING, format("%s not found", signature));
}

From source file:com.facebook.presto.metadata.FunctionRegistry.java

public InternalAggregationFunction getAggregateFunctionImplementation(Signature signature) {
    checkArgument(signature.getKind() == AGGREGATE || signature.getKind() == APPROXIMATE_AGGREGATE,
            "%s is not an aggregate function", signature);
    checkArgument(signature.getTypeParameters().isEmpty(), "%s has unbound type parameters", signature);
    Iterable<SqlFunction> candidates = functions.get(QualifiedName.of(signature.getName()));
    // search for exact match
    for (SqlFunction operator : candidates) {
        Type returnType = typeManager.getType(signature.getReturnType());
        List<Type> argumentTypes = resolveTypes(signature.getArgumentTypes(), typeManager);
        Map<String, Type> boundTypeParameters = operator.getSignature().bindTypeParameters(returnType,
                argumentTypes, false, typeManager);
        if (boundTypeParameters != null) {
            try {
                return specializedAggregationCache.getUnchecked(new SpecializedFunctionKey(operator,
                        boundTypeParameters, signature.getArgumentTypes().size()));
            } catch (UncheckedExecutionException e) {
                throw Throwables.propagate(e.getCause());
            }/*from w w  w  .  ja va2 s  . c  o m*/
        }
    }
    throw new PrestoException(FUNCTION_IMPLEMENTATION_MISSING, format("%s not found", signature));
}

From source file:com.facebook.presto.metadata.FunctionRegistry.java

public ScalarFunctionImplementation getScalarFunctionImplementation(Signature signature) {
    checkArgument(signature.getKind() == SCALAR, "%s is not a scalar function", signature);
    checkArgument(signature.getTypeParameters().isEmpty(), "%s has unbound type parameters", signature);
    Iterable<SqlFunction> candidates = functions.get(QualifiedName.of(signature.getName()));
    // search for exact match
    Type returnType = typeManager.getType(signature.getReturnType());
    List<Type> argumentTypes = resolveTypes(signature.getArgumentTypes(), typeManager);
    for (SqlFunction operator : candidates) {
        Map<String, Type> boundTypeParameters = operator.getSignature().bindTypeParameters(returnType,
                argumentTypes, false, typeManager);
        if (boundTypeParameters != null) {
            try {
                return specializedScalarCache.getUnchecked(new SpecializedFunctionKey(operator,
                        boundTypeParameters, signature.getArgumentTypes().size()));
            } catch (UncheckedExecutionException e) {
                throw Throwables.propagate(e.getCause());
            }/*from  ww  w  . j  av a 2s. co m*/
        }
    }

    // TODO: this is a hack and should be removed
    if (signature.getName().startsWith(MAGIC_LITERAL_FUNCTION_PREFIX)) {
        List<TypeSignature> parameterTypes = signature.getArgumentTypes();
        // extract type from function name
        String typeName = signature.getName().substring(MAGIC_LITERAL_FUNCTION_PREFIX.length());

        // lookup the type
        Type type = typeManager.getType(parseTypeSignature(typeName));
        requireNonNull(type, format("Type %s not registered", typeName));

        // verify we have one parameter of the proper type
        checkArgument(parameterTypes.size() == 1, "Expected one argument to literal function, but got %s",
                parameterTypes);
        Type parameterType = typeManager.getType(parameterTypes.get(0));
        requireNonNull(parameterType, format("Type %s not found", parameterTypes.get(0)));

        MethodHandle methodHandle = null;
        if (parameterType.getJavaType() == type.getJavaType()) {
            methodHandle = MethodHandles.identity(parameterType.getJavaType());
        }

        if (parameterType.getJavaType() == Slice.class) {
            if (type.getJavaType() == Block.class) {
                methodHandle = BlockSerdeUtil.READ_BLOCK.bindTo(blockEncodingSerde);
            }
        }

        checkArgument(methodHandle != null,
                "Expected type %s to use (or can be converted into) Java type %s, but Java type is %s", type,
                parameterType.getJavaType(), type.getJavaType());

        return new ScalarFunctionImplementation(false, ImmutableList.of(false), methodHandle, true);
    }

    // TODO this should be removed and implemented as a special expression type
    if (!signature.getArgumentTypes().isEmpty()
            && signature.getArgumentTypes().get(0).getBase().equals(StandardTypes.ROW)) {
        SqlFunction fieldReference = getRowFieldReference(signature.getName(),
                signature.getArgumentTypes().get(0));
        if (fieldReference != null) {
            Map<String, Type> boundTypeParameters = fieldReference.getSignature().bindTypeParameters(returnType,
                    argumentTypes, false, typeManager);
            return specializedScalarCache.getUnchecked(new SpecializedFunctionKey(fieldReference,
                    boundTypeParameters, signature.getArgumentTypes().size()));
        }
    }
    throw new PrestoException(FUNCTION_IMPLEMENTATION_MISSING, format("%s not found", signature));
}