Skip to content

Commit

Permalink
#30545 Improving processors discovery.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Dec 20, 2024
1 parent 2f636df commit c2dcbee
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ public List<Class<? extends JobProcessor>> discoverJobProcessors() {
for (Bean<?> bean : beans) {
Class<?> beanClass = bean.getBeanClass();

if (JobProcessor.class.isAssignableFrom(beanClass)) {

// Validate that the bean is in the correct scope
validateScope(bean);

if (JobProcessor.class.isAssignableFrom(beanClass)
&& isValidateScope(bean)) {
processors.add((Class<? extends JobProcessor>) beanClass);
Logger.debug(this, "Discovered JobProcessor: " + beanClass.getName());
}
Expand All @@ -75,14 +72,20 @@ public List<Class<? extends JobProcessor>> discoverJobProcessors() {
* Validates that the scope of the bean is correct for a JobProcessor.
*
* @param bean The bean to validate.
* @return True if the scope is valid, false otherwise.
*/
private void validateScope(Bean<?> bean) {
private boolean isValidateScope(Bean<?> bean) {

Class<?> scope = bean.getScope();
if (scope != Dependent.class) {
throw new DotRuntimeException(
"JobProcessor " + bean.getBeanClass().getName() +
" must use @Dependent scope, found: " + scope.getName());
final String errorMessage = "JobProcessor " + bean.getBeanClass().getName() +
" must use @Dependent scope, found: " + scope.getName() + " scope. "
+ "Won't be registered.";
Logger.error(this, errorMessage);
return false;
}

return true;
}

}

0 comments on commit c2dcbee

Please sign in to comment.