public List<StepInvoker> getStepInvokers() { List<StepInvoker> stepInvokers = new ArrayList<>(); //if the handler implements StepInvokerProvider then get the step invokers directly //these invokers may change at any point in the scenario lifecycle, even between steps addStepProviderInvokers(stepInvokers); //add step invokers for any annotated step methods //these are tied to the handler class and so are only calculated once addMethodStepInvokers(stepInvokers); return stepInvokers; }
private void createMethodInvokers() { if ( invokersForMethods == null) { invokersForMethods = getStepInvokersForAnnotatedMethods(); } }
private void addLocalHandlerClassSteps(List<Object> handlerInstances, CompositeStepInvokerProvider compositeStepProvider) { for ( Object handler : handlerInstances) { HandlerClassInvokerFactory f = new HandlerClassInvokerFactory(handler); compositeStepProvider.addChild(f); } }
private void addMethodStepInvokers(List<StepInvoker> stepInvokers) { createMethodInvokers(); stepInvokers.addAll(invokersForMethods); log.debug("Added " + invokersForMethods.size() + " step invokers for handler class " + handlerInstance.getClass().getSimpleName() + " annotated methods"); }
@Override public void addStepsForHandlerClasses(List<Class> classes) { //we need to create handler instances in order to get StepInvokers for catalogue writing //Cataloguing is performed against StepInvoker since this is more general than class specific invocation List<Object> handlerInstances = createHandlerInstances(classes); List<StepInvoker> l = handlerInstances .stream() .map(HandlerClassInvokerFactory::new) .flatMap(f -> f.getStepInvokers().stream()) .collect(Collectors.toList()); addSteps(l); }
private List<StepInvoker> getStepInvokersForAnnotatedMethods() { List<StepInvoker> stepInvokers = new ArrayList<>(); Method[] methods = handlerInstance.getClass().getMethods(); for (Method method : methods) { //only check methods with Step annotation Step stepAnnotationInstance = method.getAnnotation(Step.class); if (stepAnnotationInstance != null) { if ( log.isTraceEnabled()) { log.trace("Found @Step annotated method " + method + " on handler " + handlerInstance); } StepInvoker invoker = createInvoker(handlerInstance, method); stepInvokers.add(invoker); } } return stepInvokers; }
/** * Add handler classes containing the step definitions to publish * This must be done before publish is called (or while the step publisher is disconnected) */ public void addHandlers(Object... handlers) { for ( Object handler : handlers) { //assert that this is a Handler checkValidHandlerType(handler); StepInvokerProvider invokerFactory = new HandlerClassInvokerFactory(handler); List<StepInvoker> invokers = invokerFactory.getStepInvokers(); if (invokers.isEmpty()) { Class<?> handlerClass = handler.getClass(); log.warn(String.format("Cannot export object of type (%s) it either: 1) Has no methods that declare the @Step annotation " + "2) Returns zero StepInvoker's from a StepInvokerProvider instance", handlerClass.getName())); } for ( StepInvoker i : invokers) { addStepInvoker(i); } } }
/** * @param patternPreProcessor - A function to perform a mapping on the patterns of all exported handler steps * @param handlers - Instances of handler classes which should be exported */ public ChorusHandlerJmxExporter(UnaryOperator<Pattern> patternPreProcessor, Object... handlers) { this.patternPreProcessor = patternPreProcessor; for ( Object handler : handlers) { //assert that this is a Handler checkValidHandlerType(handler); StepInvokerProvider invokerFactory = new HandlerClassInvokerFactory(handler); //Process the patterns if a step pattern pre processor is set //This mechanism lets the user transform the patterns of all steps exported by a component, for example if ( patternPreProcessor != DEFAULT_STEP_PATTERN_PREPROCESSOR) { invokerFactory = new PatternPreProcessingProvider(patternPreProcessor, invokerFactory); } List<StepInvoker> invokers = invokerFactory.getStepInvokers(); if (invokers.isEmpty()) { Class<?> handlerClass = handler.getClass(); log.warn(String.format("Cannot export object of type (%s) it either: 1) Has no methods that declare the @Step annotation " + "2) Returns zero StepInvoker's from a StepInvokerProvider instance", handlerClass.getName())); } for ( StepInvoker i : invokers) { addStepInvoker(i); } } }