Search in sources :

Example 76 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 77 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project zipkin by openzipkin.

the class TracedSession method handleInvocation.

@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
    // Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
    if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null && brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null && // Only trace named statements for now, since that's what we use
    method.getName().equals("executeAsync") && args[0] instanceof NamedBoundStatement) {
        NamedBoundStatement statement = (NamedBoundStatement) args[0];
        SpanId spanId = brave.clientTracer().startNewSpan(statement.name);
        // o.a.c.tracing.Tracing.newSession must use the same format for the key zipkin
        if (version.compareTo(ProtocolVersion.V4) >= 0) {
            statement.enableTracing();
            statement.setOutgoingPayload(singletonMap("zipkin", ByteBuffer.wrap(spanId.bytes())));
        }
        // start the span and store it
        brave.clientTracer().setClientSent();
        brave.clientTracer().submitBinaryAnnotation("cql.query", statement.preparedStatement().getQueryString());
        cache.put(statement, brave.clientSpanThreadBinder().getCurrentClientSpan());
        // let go of the client span as it is only used for the RPC (will have no local children)
        brave.clientSpanThreadBinder().setCurrentSpan(null);
        return new BraveResultSetFuture(target.executeAsync(statement), brave);
    }
    try {
        return method.invoke(target, args);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException)
            throw e.getCause();
        throw e;
    }
}
Also used : NamedBoundStatement(zipkin.storage.cassandra.NamedBoundStatement) InvocationTargetException(java.lang.reflect.InvocationTargetException) SpanId(com.github.kristofa.brave.SpanId)

Example 78 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project zipkin by openzipkin.

the class TracedSession method handleInvocation.

@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
    // Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
    if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null && brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null && method.getName().equals("executeAsync") && args[0] instanceof BoundStatement) {
        BoundStatement statement = (BoundStatement) args[0];
        // via an internal class z.s.cassandra3.NamedBoundStatement, toString() is a nice name
        SpanId spanId = brave.clientTracer().startNewSpan(statement.toString());
        // o.a.c.tracing.Tracing.newSession must use the same format for the key zipkin
        if (version.compareTo(ProtocolVersion.V4) >= 0) {
            statement.enableTracing();
            statement.setOutgoingPayload(singletonMap("zipkin", ByteBuffer.wrap(spanId.bytes())));
        }
        // start the span and store it
        brave.clientTracer().setClientSent();
        brave.clientTracer().submitBinaryAnnotation("cql.query", statement.preparedStatement().getQueryString());
        cache.put(statement, brave.clientSpanThreadBinder().getCurrentClientSpan());
        // let go of the client span as it is only used for the RPC (will have no local children)
        brave.clientSpanThreadBinder().setCurrentSpan(null);
        return new BraveResultSetFuture(target.executeAsync(statement), brave);
    }
    try {
        return method.invoke(target, args);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException)
            throw e.getCause();
        throw e;
    }
}
Also used : BoundStatement(com.datastax.driver.core.BoundStatement) InvocationTargetException(java.lang.reflect.InvocationTargetException) SpanId(com.github.kristofa.brave.SpanId)

Example 79 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project jphp by jphp-compiler.

the class UIWindow method __setOpacity.

@Signature(@Arg("value"))
protected Memory __setOpacity(Environment env, Memory... args) {
    Window window = getWindow();
    try {
        Method m = window.getClass().getMethod("setOpacity", Float.TYPE);
        m.invoke(window, args[0].toFloat());
    } catch (NoSuchMethodException e) {
        return Memory.NULL;
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    return Memory.NULL;
}
Also used : RootWindow(org.develnext.jphp.swing.support.RootWindow) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 80 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project openhab1-addons by openhab.

the class EBusBinding method updated.

/*
     * (non-Javadoc)
     *
     * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
     */
@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    logger.info("Update eBus Binding configuration ...");
    if (properties == null || properties.isEmpty()) {
        throw new RuntimeException("No properties in openhab.cfg set!");
    }
    try {
        // stop last connector-thread if active
        stopConnector();
        // check to ensure that it is available
        checkConfigurationProvider();
        // clear current configuration
        configurationProvider.clear();
        // load parser from default url
        parser = new EBusTelegramParser(configurationProvider);
        URL configurationUrl = null;
        String parsers = (String) properties.get("parsers");
        if (StringUtils.isEmpty(parsers)) {
            // set to current stable configurations as default
            parsers = "common";
        }
        for (String elem : parsers.split(",")) {
            configurationUrl = null;
            // check for keyword custom to load custom configuration
            if (elem.trim().equals("custom")) {
                String parserUrl = (String) properties.get("parserUrl");
                if (parserUrl != null) {
                    logger.debug("Load custom eBus Parser with url {}", parserUrl);
                    configurationUrl = new URL(parserUrl);
                }
            } else {
                logger.debug("Load eBus Parser Configuration \"{}\" ...", elem.trim());
                String filename = "src/main/resources/" + elem.trim() + "-configuration.json";
                Bundle bundle = FrameworkUtil.getBundle(EBusBinding.class);
                configurationUrl = bundle.getResource(filename);
                if (configurationUrl == null) {
                    logger.error("Unable to load file {} ...", elem.trim() + "-configuration.json");
                }
            }
            if (configurationUrl != null) {
                configurationProvider.loadConfigurationFile(configurationUrl);
            }
        }
        // check minimal config
        if (properties.get("serialPort") != null && properties.get("hostname") != null) {
            throw new ConfigurationException("hostname", "Set property serialPort or hostname, not both!");
        }
        // use the serial connector
        if (StringUtils.isNotEmpty((String) properties.get("serialPort"))) {
            try {
                // load class by reflection to keep gnu.io (serial) optional. Declarative Services causes an
                // class not found exception, also if serial is not used!
                // FIXME: Is there a better way to avoid that a class not found exception?
                @SuppressWarnings("unchecked") Class<AbstractEBusWriteConnector> _tempClass = (Class<AbstractEBusWriteConnector>) EBusBinding.class.getClassLoader().loadClass("org.openhab.binding.ebus.internal.connection.EBusSerialConnector");
                Constructor<AbstractEBusWriteConnector> constructor = _tempClass.getDeclaredConstructor(String.class);
                connector = constructor.newInstance((String) properties.get("serialPort"));
            } catch (ClassNotFoundException e) {
                logger.error(e.toString(), e);
            } catch (NoSuchMethodException e) {
                logger.error(e.toString(), e);
            } catch (SecurityException e) {
                logger.error(e.toString(), e);
            } catch (InstantiationException e) {
                logger.error(e.toString(), e);
            } catch (IllegalAccessException e) {
                logger.error(e.toString(), e);
            } catch (IllegalArgumentException e) {
                logger.error(e.toString(), e);
            } catch (InvocationTargetException e) {
                logger.error(e.toString(), e);
            }
        } else if (StringUtils.isNotEmpty((String) properties.get("hostname"))) {
            // use the tcp-ip connector
            connector = new EBusTCPConnector((String) properties.get("hostname"), Integer.parseInt((String) properties.get("port")));
        }
        // Set eBus sender id or default 0xFF
        if (StringUtils.isNotEmpty((String) properties.get("senderId"))) {
            connector.setSenderId(EBusUtils.toByte((String) properties.get("senderId")));
        }
        if (properties.get("record") != null) {
            String debugWriterMode = (String) properties.get("record");
            logger.info("Enable CSV writer for eBUS {}", debugWriterMode);
            debugWriter = new EBusTelegramCSVWriter();
            debugWriter.openInUserData("ebus-" + debugWriterMode + ".csv");
            parser.setDebugCSVWriter(debugWriter, debugWriterMode);
        }
        // add event listener
        connector.addEBusEventListener(this);
        // start thread
        connector.start();
        // set the new connector
        commandProcessor.setConnector(connector);
        commandProcessor.setConfigurationProvider(configurationProvider);
    } catch (MalformedURLException e) {
        logger.error(e.toString(), e);
    } catch (IOException e) {
        throw new ConfigurationException("general", e.toString(), e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) URL(java.net.URL) InvocationTargetException(java.lang.reflect.InvocationTargetException) EBusTelegramParser(org.openhab.binding.ebus.internal.parser.EBusTelegramParser) AbstractEBusWriteConnector(org.openhab.binding.ebus.internal.connection.AbstractEBusWriteConnector) ConfigurationException(org.osgi.service.cm.ConfigurationException) EBusTCPConnector(org.openhab.binding.ebus.internal.connection.EBusTCPConnector) EBusTelegramCSVWriter(org.openhab.binding.ebus.internal.parser.EBusTelegramCSVWriter)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)4781 Method (java.lang.reflect.Method)2031 IOException (java.io.IOException)550 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)492 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)407 ArrayList (java.util.ArrayList)402 List (java.util.List)248 CoreException (org.eclipse.core.runtime.CoreException)247 File (java.io.File)238 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)236 Constructor (java.lang.reflect.Constructor)233 Field (java.lang.reflect.Field)220 Test (org.junit.Test)209 Map (java.util.Map)205 HashMap (java.util.HashMap)202 DBException (org.jkiss.dbeaver.DBException)169 IStatus (org.eclipse.core.runtime.IStatus)136 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)97 Arrays (java.util.Arrays)96 Status (org.eclipse.core.runtime.Status)94