1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.internal.provisioning; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
import java.util.concurrent.ExecutorService; |
27 |
|
import java.util.concurrent.Executors; |
28 |
|
|
29 |
|
import javax.inject.Inject; |
30 |
|
import javax.inject.Provider; |
31 |
|
import javax.inject.Singleton; |
32 |
|
|
33 |
|
import org.apache.commons.lang3.concurrent.BasicThreadFactory; |
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
import org.xwiki.component.manager.ComponentLookupException; |
36 |
|
import org.xwiki.component.manager.ComponentManager; |
37 |
|
import org.xwiki.component.phase.Initializable; |
38 |
|
import org.xwiki.component.phase.InitializationException; |
39 |
|
import org.xwiki.job.Job; |
40 |
|
import org.xwiki.wiki.provisioning.WikiProvisioningJob; |
41 |
|
import org.xwiki.wiki.provisioning.WikiProvisioningJobException; |
42 |
|
import org.xwiki.wiki.provisioning.WikiProvisioningJobExecutor; |
43 |
|
import org.xwiki.wiki.provisioning.WikiProvisioningJobRequest; |
44 |
|
|
45 |
|
import com.xpn.xwiki.XWikiContext; |
46 |
|
|
47 |
|
|
48 |
|
@link |
49 |
|
|
50 |
|
@since |
51 |
|
@version |
52 |
|
|
53 |
|
@Component |
54 |
|
@Singleton |
|
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 4 |
Complexity Density: 0.22 |
|
55 |
|
public class DefaultWikiProvisioningJobExecutor implements WikiProvisioningJobExecutor, Initializable |
56 |
|
{ |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
private Map<List<String>, WikiProvisioningJob> jobs; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
private ExecutorService jobExecutor; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
@Inject |
72 |
|
private ComponentManager componentManager; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
@Inject |
78 |
|
private Provider<XWikiContext> xcontextProvider; |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
80 |
3 |
@Override... |
81 |
|
public void initialize() throws InitializationException |
82 |
|
{ |
83 |
3 |
this.jobs = new HashMap<List<String>, WikiProvisioningJob>(); |
84 |
|
|
85 |
|
|
86 |
3 |
BasicThreadFactory factory = |
87 |
|
new BasicThreadFactory.Builder().namingPattern("XWiki provisioning thread").daemon(true) |
88 |
|
.priority(Thread.MIN_PRIORITY).build(); |
89 |
3 |
this.jobExecutor = Executors.newCachedThreadPool(factory); |
90 |
|
} |
91 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 2 |
Complexity Density: 0.15 |
|
92 |
1 |
@Override... |
93 |
|
public WikiProvisioningJob createAndExecuteJob(String wikiId, String provisioningJobName, Object parameter) throws |
94 |
|
WikiProvisioningJobException |
95 |
|
{ |
96 |
1 |
try { |
97 |
|
|
98 |
1 |
XWikiContext xcontext = xcontextProvider.get(); |
99 |
|
|
100 |
1 |
WikiProvisioningJob job = componentManager.getInstance(Job.class, provisioningJobName); |
101 |
|
|
102 |
1 |
List<String> jobId = new ArrayList<String>(); |
103 |
1 |
jobId.add("wiki"); |
104 |
1 |
jobId.add("provisioning"); |
105 |
1 |
jobId.add(provisioningJobName); |
106 |
1 |
jobId.add(wikiId); |
107 |
|
|
108 |
1 |
job.initialize(new WikiProvisioningJobRequest(jobId, wikiId, parameter, xcontext.getUserReference())); |
109 |
|
|
110 |
1 |
jobs.put(jobId, job); |
111 |
|
|
112 |
1 |
jobExecutor.execute(job); |
113 |
|
|
114 |
1 |
return job; |
115 |
|
} catch (ComponentLookupException e) { |
116 |
0 |
throw new WikiProvisioningJobException( |
117 |
|
String.format("Failed to lookup provisioning job component for role [%s]", provisioningJobName), e); |
118 |
|
} |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
121 |
2 |
@Override... |
122 |
|
public WikiProvisioningJob getJob(List<String> jobId) throws WikiProvisioningJobException |
123 |
|
{ |
124 |
2 |
WikiProvisioningJob job = jobs.get(jobId); |
125 |
2 |
return job; |
126 |
|
} |
127 |
|
} |