Search in sources :

Example 16 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project groovy by apache.

the class ProxyGeneratorAdapter method delegatingProxy.

@SuppressWarnings("unchecked")
public GroovyObject delegatingProxy(Object delegate, Map<Object, Object> map, Object... constructorArgs) {
    if (constructorArgs == null && cachedNoArgConstructor != null) {
        // if there isn't any argument, we can make invocation faster using the cached constructor
        try {
            return (GroovyObject) cachedNoArgConstructor.newInstance(map, delegate);
        } catch (InstantiationException e) {
            throw new GroovyRuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new GroovyRuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new GroovyRuntimeException(e);
        }
    }
    if (constructorArgs == null)
        constructorArgs = EMPTY_ARGS;
    Object[] values = new Object[constructorArgs.length + 2];
    System.arraycopy(constructorArgs, 0, values, 0, constructorArgs.length);
    values[values.length - 2] = map;
    values[values.length - 1] = delegate;
    return DefaultGroovyMethods.<GroovyObject>newInstance(cachedClass, values);
}
Also used : GroovyRuntimeException(groovy.lang.GroovyRuntimeException) GroovyObject(groovy.lang.GroovyObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) GroovyObject(groovy.lang.GroovyObject)

Example 17 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project groovy by apache.

the class StaticTypeCheckingSupport method evaluateExpression.

/**
     * A helper method that can be used to evaluate expressions as found in annotation
     * parameters. For example, it will evaluate a constant, be it referenced directly as
     * an integer or as a reference to a field.
     *
     * If this method throws an exception, then the expression cannot be evaluated on its own.
     *
     * @param expr the expression to be evaluated
     * @param config the compiler configuration
     * @return the result of the expression
     */
public static Object evaluateExpression(Expression expr, CompilerConfiguration config) {
    String className = "Expression$" + UUID.randomUUID().toString().replace('-', '$');
    ClassNode node = new ClassNode(className, Opcodes.ACC_PUBLIC, OBJECT_TYPE);
    ReturnStatement code = new ReturnStatement(expr);
    node.addMethod(new MethodNode("eval", Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, code));
    CompilerConfiguration copyConf = new CompilerConfiguration(config);
    CompilationUnit cu = new CompilationUnit(copyConf);
    cu.addClassNode(node);
    cu.compile(Phases.CLASS_GENERATION);
    @SuppressWarnings("unchecked") List<GroovyClass> classes = (List<GroovyClass>) cu.getClasses();
    Class aClass = cu.getClassLoader().defineClass(className, classes.get(0).getBytes());
    try {
        return aClass.getMethod("eval").invoke(null);
    } catch (IllegalAccessException e) {
        throw new GroovyBugError(e);
    } catch (InvocationTargetException e) {
        throw new GroovyBugError(e);
    } catch (NoSuchMethodException e) {
        throw new GroovyBugError(e);
    }
}
Also used : CompilationUnit(org.codehaus.groovy.control.CompilationUnit) ClassNode(org.codehaus.groovy.ast.ClassNode) GroovyClass(org.codehaus.groovy.tools.GroovyClass) GroovyBugError(org.codehaus.groovy.GroovyBugError) InvocationTargetException(java.lang.reflect.InvocationTargetException) MethodNode(org.codehaus.groovy.ast.MethodNode) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) GroovyClass(org.codehaus.groovy.tools.GroovyClass)

Example 18 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project hadoop by apache.

the class DefaultSpeculator method getEstimator.

private static TaskRuntimeEstimator getEstimator(Configuration conf, AppContext context) {
    TaskRuntimeEstimator estimator;
    try {
        // "yarn.mapreduce.job.task.runtime.estimator.class"
        Class<? extends TaskRuntimeEstimator> estimatorClass = conf.getClass(MRJobConfig.MR_AM_TASK_ESTIMATOR, LegacyTaskRuntimeEstimator.class, TaskRuntimeEstimator.class);
        Constructor<? extends TaskRuntimeEstimator> estimatorConstructor = estimatorClass.getConstructor();
        estimator = estimatorConstructor.newInstance();
        estimator.contextualize(conf, context);
    } catch (InstantiationException ex) {
        LOG.error("Can't make a speculation runtime estimator", ex);
        throw new YarnRuntimeException(ex);
    } catch (IllegalAccessException ex) {
        LOG.error("Can't make a speculation runtime estimator", ex);
        throw new YarnRuntimeException(ex);
    } catch (InvocationTargetException ex) {
        LOG.error("Can't make a speculation runtime estimator", ex);
        throw new YarnRuntimeException(ex);
    } catch (NoSuchMethodException ex) {
        LOG.error("Can't make a speculation runtime estimator", ex);
        throw new YarnRuntimeException(ex);
    }
    return estimator;
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 19 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project hadoop by apache.

the class ClientServiceDelegate method invoke.

private synchronized Object invoke(String method, Class argClass, Object args) throws IOException {
    Method methodOb = null;
    try {
        methodOb = MRClientProtocol.class.getMethod(method, argClass);
    } catch (SecurityException e) {
        throw new YarnRuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new YarnRuntimeException("Method name mismatch", e);
    }
    maxClientRetry = this.conf.getInt(MRJobConfig.MR_CLIENT_MAX_RETRIES, MRJobConfig.DEFAULT_MR_CLIENT_MAX_RETRIES);
    IOException lastException = null;
    while (maxClientRetry > 0) {
        MRClientProtocol MRClientProxy = null;
        try {
            MRClientProxy = getProxy();
            return methodOb.invoke(MRClientProxy, args);
        } catch (InvocationTargetException e) {
            // Will not throw out YarnException anymore
            LOG.debug("Failed to contact AM/History for job " + jobId + " retrying..", e.getTargetException());
            // Force reconnection by setting the proxy to null.
            realProxy = null;
            if (e.getCause() instanceof AuthorizationException) {
                throw new IOException(e.getTargetException());
            }
            // for its AM to be restarted.
            if (!usingAMProxy.get()) {
                maxClientRetry--;
            }
            usingAMProxy.set(false);
            lastException = new IOException(e.getTargetException());
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
                LOG.warn("ClientServiceDelegate invoke call interrupted", ie);
                throw new YarnRuntimeException(ie);
            }
        } catch (Exception e) {
            LOG.debug("Failed to contact AM/History for job " + jobId + "  Will retry..", e);
            // Force reconnection by setting the proxy to null.
            realProxy = null;
            // RM shutdown
            maxClientRetry--;
            lastException = new IOException(e.getMessage());
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
                LOG.warn("ClientServiceDelegate invoke call interrupted", ie);
                throw new YarnRuntimeException(ie);
            }
        }
    }
    throw lastException;
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) MRClientProtocol(org.apache.hadoop.mapreduce.v2.api.MRClientProtocol)

Example 20 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project hadoop by apache.

the class RecordFactoryProvider method getFactoryClassInstance.

private static Object getFactoryClassInstance(String factoryClassName) {
    try {
        Class<?> clazz = Class.forName(factoryClassName);
        Method method = clazz.getMethod("get", null);
        method.setAccessible(true);
        return method.invoke(null, null);
    } catch (ClassNotFoundException e) {
        throw new YarnRuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new YarnRuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new YarnRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new YarnRuntimeException(e);
    }
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1714 Method (java.lang.reflect.Method)784 IOException (java.io.IOException)193 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)146 ArrayList (java.util.ArrayList)136 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)130 Test (org.junit.Test)129 Constructor (java.lang.reflect.Constructor)116 File (java.io.File)97 HashMap (java.util.HashMap)75 Field (java.lang.reflect.Field)71 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)69 List (java.util.List)61 Map (java.util.Map)60 CoreException (org.eclipse.core.runtime.CoreException)60 IStatus (org.eclipse.core.runtime.IStatus)43 AccessibleObject (java.lang.reflect.AccessibleObject)34 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)34 URLClassLoader (java.net.URLClassLoader)32 Status (org.eclipse.core.runtime.Status)30