Search in sources :

Example 1 with AbstractSampleConsumer

use of org.apache.jmeter.report.processor.AbstractSampleConsumer in project jmeter by apache.

the class ReportGenerator method addGraphConsumer.

private void addGraphConsumer(FilterConsumer nameFilter, FilterConsumer excludeControllerFilter, Map.Entry<String, GraphConfiguration> entryGraphCfg) throws GenerationException {
    String graphName = entryGraphCfg.getKey();
    GraphConfiguration graphConfiguration = entryGraphCfg.getValue();
    // Instantiate the class from the classname
    String className = graphConfiguration.getClassName();
    try {
        Class<?> clazz = Class.forName(className);
        Object obj = clazz.newInstance();
        AbstractGraphConsumer graph = (AbstractGraphConsumer) obj;
        graph.setName(graphName);
        // Set the graph title
        graph.setTitle(graphConfiguration.getTitle());
        // Set graph properties using reflection
        Method[] methods = clazz.getMethods();
        for (Map.Entry<String, String> entryProperty : graphConfiguration.getProperties().entrySet()) {
            String propertyName = entryProperty.getKey();
            String propertyValue = entryProperty.getValue();
            String setterName = getSetterName(propertyName);
            setProperty(className, obj, methods, propertyName, propertyValue, setterName);
        }
        // Choose which entry point to use to plug the graph
        AbstractSampleConsumer entryPoint = graphConfiguration.excludesControllers() ? excludeControllerFilter : nameFilter;
        entryPoint.addSampleConsumer(graph);
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | ClassCastException ex) {
        String error = String.format(INVALID_CLASS_FMT, className);
        log.error(error, ex);
        throw new GenerationException(error, ex);
    }
}
Also used : GraphConfiguration(org.apache.jmeter.report.config.GraphConfiguration) Method(java.lang.reflect.Method) AbstractSampleConsumer(org.apache.jmeter.report.processor.AbstractSampleConsumer) Map(java.util.Map) AbstractGraphConsumer(org.apache.jmeter.report.processor.graph.AbstractGraphConsumer)

Aggregations

Method (java.lang.reflect.Method)1 Map (java.util.Map)1 GraphConfiguration (org.apache.jmeter.report.config.GraphConfiguration)1 AbstractSampleConsumer (org.apache.jmeter.report.processor.AbstractSampleConsumer)1 AbstractGraphConsumer (org.apache.jmeter.report.processor.graph.AbstractGraphConsumer)1