/** * Invoke the specified method. * <p>The invoker needs to have been prepared before. * @return the object (possibly null) returned by the method invocation, * or {@code null} if the method has a void return type * @throws InvocationTargetException if the target method threw an exception * @throws IllegalAccessException if the target method couldn't be accessed * @see #prepare */ @Nullable public Object invoke() throws InvocationTargetException, IllegalAccessException { // In the static case, target will simply be {@code null}. Object targetObject = getTargetObject(); Method preparedMethod = getPreparedMethod(); if (targetObject == null && !Modifier.isStatic(preparedMethod.getModifiers())) { throw new IllegalArgumentException("Target method must not be non-static without a target"); } ReflectionUtils.makeAccessible(preparedMethod); return preparedMethod.invoke(targetObject, getArguments()); }
/** * Invoke the specified method. * <p>The invoker needs to have been prepared before. * @return the object (possibly null) returned by the method invocation, * or {@code null} if the method has a void return type * @throws InvocationTargetException if the target method threw an exception * @throws IllegalAccessException if the target method couldn't be accessed * @see #prepare */ @Nullable public Object invoke() throws InvocationTargetException, IllegalAccessException { // In the static case, target will simply be {@code null}. Object targetObject = getTargetObject(); Method preparedMethod = getPreparedMethod(); if (targetObject == null && !Modifier.isStatic(preparedMethod.getModifiers())) { throw new IllegalArgumentException("Target method must not be non-static without a target"); } ReflectionUtils.makeAccessible(preparedMethod); return preparedMethod.invoke(targetObject, getArguments()); }
/** * Invoke the specified method. * <p>The invoker needs to have been prepared before. * @return the object (possibly null) returned by the method invocation, * or <code>null</code> if the method has a void return type * @throws InvocationTargetException if the target method threw an exception * @throws IllegalAccessException if the target method couldn't be accessed * @see #prepare */ public Object invoke() throws InvocationTargetException, IllegalAccessException { // In the static case, target will simply be <code>null</code>. Object targetObject = getTargetObject(); Method preparedMethod = getPreparedMethod(); if (targetObject == null && !Modifier.isStatic(preparedMethod.getModifiers())) { throw new IllegalArgumentException("Target method must not be non-static without a target"); } ReflectionUtils.makeAccessible(preparedMethod); return preparedMethod.invoke(targetObject, getArguments()); }
/** * Invoke the specified method. * <p>The invoker needs to have been prepared before. * @return the object (possibly null) returned by the method invocation, * or {@code null} if the method has a void return type * @throws InvocationTargetException if the target method threw an exception * @throws IllegalAccessException if the target method couldn't be accessed * @see #prepare */ @Nullable public Object invoke() throws InvocationTargetException, IllegalAccessException { // In the static case, target will simply be {@code null}. Object targetObject = getTargetObject(); Method preparedMethod = getPreparedMethod(); if (targetObject == null && !Modifier.isStatic(preparedMethod.getModifiers())) { throw new IllegalArgumentException("Target method must not be non-static without a target"); } ReflectionUtils.makeAccessible(preparedMethod); return preparedMethod.invoke(targetObject, getArguments()); }
/** * Invoke the specified method. * <p>The invoker needs to have been prepared before. * @return the object (possibly null) returned by the method invocation, * or {@code null} if the method has a void return type * @throws InvocationTargetException if the target method threw an exception * @throws IllegalAccessException if the target method couldn't be accessed * @see #prepare */ @Nullable public Object invoke() throws InvocationTargetException, IllegalAccessException { // In the static case, target will simply be {@code null}. Object targetObject = getTargetObject(); Method preparedMethod = getPreparedMethod(); if (targetObject == null && !Modifier.isStatic(preparedMethod.getModifiers())) { throw new IllegalArgumentException("Target method must not be non-static without a target"); } ReflectionUtils.makeAccessible(preparedMethod); return preparedMethod.invoke(targetObject, getArguments()); }
this.method = helper.getPreparedMethod(); return this.method.invoke(this.object, convertedArgs);
public ScheduledMethodInvoker(TaskDefinition taskDefinition, ClusterScheduler clusterScheduler, StringValueResolver stringValueResolver) { this.clusterScheduler = clusterScheduler; this.stringValueResolver = stringValueResolver; ApplicationContext context = ApplicationContextHolder.getApplicationContext(); try { taskId = taskDefinition.getTaskId(); final MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetMethod(taskDefinition.getMethodName()); if (context.containsBean(taskDefinition.getClassName())) { target = context.getBean(taskDefinition.getClassName()); } else { Class<?> aClass = Class.forName(taskDefinition.getClassName()); try { target = context.getBean(aClass); } catch (BeansException e) { target = context.getAutowireCapableBeanFactory().createBean(aClass); } } methodInvoker.setTargetObject(target); methodInvoker.prepare(); this.method = methodInvoker.getPreparedMethod(); this.methodInvoker = methodInvoker; } catch (Exception e) { log.error(e.getMessage(), e); throw new IllegalArgumentException(e); } init(); }