JobDistributor.java
3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.event.jobs.Job
* org.apache.sling.event.jobs.JobManager
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemfd.watchfolder.distribution;
import com.adobe.aemfd.watchfolder.config.WatchFolderConfiguration;
import com.adobe.aemfd.watchfolder.factory.InputProcessorFactory;
import com.adobe.aemfd.watchfolder.util.LogUtil;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.JobManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(metatype=0, immediate=1)
@Service(value={JobDistributor.class})
public class JobDistributor {
private static final Logger logger = LoggerFactory.getLogger(JobDistributor.class);
static final String JOB_TOPIC = "com/adobe/aemfd/watchfolder";
static final String JOB_TYPE_PARAM = "JobType";
static final String WF_CONFIG_ID_PARAM = "WatchFolderConfigID";
static final String SOURCE_FILE_PARAM = "SourceFileOrDir";
static final String INPUTS_PARAM = "InputFiles";
static final String JOB_TYPE_LAUNCH_PROCESSOR = "LaunchProcessor";
@Reference
private JobManager jobManager;
@Reference
private InputProcessorFactory inputProcessorFactory;
public void distributeFileProcessing(WatchFolderConfiguration config, File source, Map<String, File> inputs) throws Exception {
if (!config.isAsynch()) {
this.inputProcessorFactory.processInputs(null, config, source, inputs);
return;
}
logger.warn("Triggering load-balanced job for launching processor " + config.getInputProcessorId() + " for processing inputs " + inputs);
HashMap<String, Object> props = new HashMap<String, Object>();
props.put("JobType", "LaunchProcessor");
props.put("WatchFolderConfigID", config.getId());
props.put("SourceFileOrDir", source);
props.put("InputFiles", inputs);
Job j = this.jobManager.addJob("com/adobe/aemfd/watchfolder", props);
if (j == null) {
throw new Exception("Unknown error starting job for triggering processor for watch-folder " + config.getId() + ", source " + source.getAbsolutePath());
}
logger.info(LogUtil.toJSON("CREATE_JOB_SUCCESS", source.getAbsolutePath(), j.getId(), null));
}
protected void bindJobManager(JobManager jobManager) {
this.jobManager = jobManager;
}
protected void unbindJobManager(JobManager jobManager) {
if (this.jobManager == jobManager) {
this.jobManager = null;
}
}
protected void bindInputProcessorFactory(InputProcessorFactory inputProcessorFactory) {
this.inputProcessorFactory = inputProcessorFactory;
}
protected void unbindInputProcessorFactory(InputProcessorFactory inputProcessorFactory) {
if (this.inputProcessorFactory == inputProcessorFactory) {
this.inputProcessorFactory = null;
}
}
}