Skip to content

Commit

Permalink
#30669 update JobQueueManagerHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinogiardino committed Nov 21, 2024
1 parent 8880be6 commit 126f0ea
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dotcms.jobs.business.api.JobQueueManagerAPI;
import com.dotcms.jobs.business.processor.JobProcessor;
import com.dotcms.jobs.business.processor.Queue;
import com.dotcms.util.AnnotationUtils;
import com.dotmarketing.util.Logger;

import javax.enterprise.context.ApplicationScoped;
Expand All @@ -17,14 +18,15 @@ public class JobQueueManagerHelper {
private JobProcessorScanner scanner;

@Inject
public JobQueueManagerHelper(JobProcessorScanner scanner) {
public JobQueueManagerHelper(final JobProcessorScanner scanner) {
this.scanner = scanner;
}

public JobQueueManagerHelper() {
// Default constructor required by CDI
}

public void registerProcessors(JobQueueManagerAPI jobQueueManagerAPI) {
public void registerProcessors(final JobQueueManagerAPI jobQueueManagerAPI) {
if (!jobQueueManagerAPI.isStarted()) {
jobQueueManagerAPI.start();
Logger.info(this.getClass(), "JobQueueManagerAPI started");
Expand All @@ -48,7 +50,7 @@ public void registerProcessors(JobQueueManagerAPI jobQueueManagerAPI) {
* @param processor The processor to tested
* @return true if the processor can be instantiated, false otherwise
*/
private boolean testInstantiation(Class<? extends JobProcessor> processor) {
private boolean testInstantiation(final Class<? extends JobProcessor> processor) {
try {
Constructor<? extends JobProcessor> declaredConstructor = processor.getDeclaredConstructor();
declaredConstructor.newInstance();
Expand All @@ -59,16 +61,16 @@ private boolean testInstantiation(Class<? extends JobProcessor> processor) {
return false;
}

private void registerProcessor(JobQueueManagerAPI jobQueueManagerAPI, Class<? extends JobProcessor> processor) {
if (processor.isAnnotationPresent(Queue.class)) {
Queue queue = processor.getAnnotation(Queue.class);
private void registerProcessor(final JobQueueManagerAPI jobQueueManagerAPI, final Class<? extends JobProcessor> processor) {
Queue queue = AnnotationUtils.getBeanAnnotation(processor, Queue.class);
if (null != queue) {
jobQueueManagerAPI.registerProcessor(queue.value(), processor);
} else {
jobQueueManagerAPI.registerProcessor(processor.getName(), processor);
}
}

public void shutdown(JobQueueManagerAPI jobQueueManagerAPI) {
public void shutdown(final JobQueueManagerAPI jobQueueManagerAPI) {
if (jobQueueManagerAPI.isStarted()) {
try {
jobQueueManagerAPI.close();
Expand Down

0 comments on commit 126f0ea

Please sign in to comment.