-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(JobQueue Resource) Refs: 29480 (#30303)
### Proposed Changes This PR includes the integration of the JobQueue implementation with rest services. Functionalities such as List, Cancel, Status, Create, and Monitor can be found here It also includes two sample JobProcessors to serve as examples and used be the respective postman tests
- Loading branch information
1 parent
aaf3e4f
commit ca8d9e2
Showing
25 changed files
with
12,940 additions
and
223 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
dotCMS/src/main/java/com/dotcms/jobs/business/api/JobProcessorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.dotcms.jobs.business.api; | ||
|
||
import com.dotcms.jobs.business.error.JobProcessorInstantiationException; | ||
import com.dotcms.jobs.business.processor.JobProcessor; | ||
import com.dotmarketing.util.Logger; | ||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class JobProcessorFactory { | ||
|
||
public JobProcessorFactory() { | ||
// Default constructor for CDI | ||
} | ||
|
||
/** | ||
* Creates a new instance of the specified job processor class. | ||
* | ||
* @param processorClass The class of the job processor to create. | ||
* @return An optional containing the new job processor instance, or an empty optional if the | ||
* processor could not be created. | ||
*/ | ||
JobProcessor newInstance( | ||
Class<? extends JobProcessor> processorClass) { | ||
try { | ||
return processorClass.getDeclaredConstructor().newInstance(); | ||
} catch (Exception e) { | ||
Logger.error(this, "Error creating job processor", e); | ||
throw new JobProcessorInstantiationException(processorClass, e); | ||
} | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
dotCMS/src/main/java/com/dotcms/jobs/business/api/JobProcessorScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.dotcms.jobs.business.api; | ||
|
||
import com.dotcms.jobs.business.processor.JobProcessor; | ||
import com.dotmarketing.util.Logger; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.Index; | ||
import org.jboss.jandex.IndexReader; | ||
|
||
/** | ||
* Scans the classpath for classes that implement the JobProcessor interface. | ||
* This class uses Jandex to scan the classpath for classes that implement the JobProcessor interface. | ||
*/ | ||
@ApplicationScoped | ||
public class JobProcessorScanner { | ||
|
||
/** | ||
* Discovers all classes that implement the JobProcessor interface. | ||
* @return A list of classes that implement the JobProcessor interface. | ||
*/ | ||
public List<Class<? extends JobProcessor>> discoverJobProcessors() { | ||
List<Class<? extends JobProcessor>> jobProcessors = new ArrayList<>(); | ||
try { | ||
|
||
Index index = getJandexIndex(); | ||
DotName jobProcessorInterface = DotName.createSimple(JobProcessor.class.getName()); | ||
|
||
Collection<ClassInfo> implementors = index.getAllKnownImplementors(jobProcessorInterface); | ||
|
||
for (ClassInfo classInfo : implementors) { | ||
String className = classInfo.name().toString(); | ||
|
||
Class<?> clazz = Class.forName(className); | ||
if (JobProcessor.class.isAssignableFrom(clazz)) { | ||
jobProcessors.add((Class<? extends JobProcessor>) clazz); | ||
} | ||
} | ||
|
||
} catch (IOException | ClassNotFoundException e) { | ||
Logger.error(JobProcessorScanner.class, "Error discovering JobProcessors", e); | ||
|
||
} | ||
return jobProcessors; | ||
} | ||
|
||
/** | ||
* Reads the Jandex index file. | ||
* @return The Jandex index. | ||
* @throws IOException If the Jandex index file cannot be read. | ||
*/ | ||
private Index getJandexIndex() throws IOException { | ||
InputStream input = getClass().getClassLoader().getResourceAsStream("META-INF/jandex.idx"); | ||
if (input == null) { | ||
throw new IOException("Jandex index not found"); | ||
} | ||
IndexReader reader = new IndexReader(input); | ||
return reader.read(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.