1 | |
package org.apache.onami.scheduler; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.Set; |
23 | |
|
24 | |
import javax.inject.Inject; |
25 | |
import javax.inject.Provider; |
26 | |
|
27 | |
import org.quartz.JobListener; |
28 | |
import org.quartz.Scheduler; |
29 | |
import org.quartz.SchedulerException; |
30 | |
import org.quartz.SchedulerListener; |
31 | |
import org.quartz.TriggerListener; |
32 | |
import org.quartz.impl.StdSchedulerFactory; |
33 | |
import org.quartz.spi.JobFactory; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 5 | final class SchedulerProvider |
39 | |
implements Provider<Scheduler> |
40 | |
{ |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
private final Scheduler scheduler; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
@Inject |
53 | |
public SchedulerProvider( SchedulerConfiguration schedulerConfiguration ) |
54 | |
throws SchedulerException |
55 | 5 | { |
56 | 5 | StdSchedulerFactory schedulerFactory = new StdSchedulerFactory(); |
57 | |
|
58 | 5 | if ( schedulerConfiguration.getProperties() != null ) |
59 | |
{ |
60 | 1 | schedulerFactory.initialize( schedulerConfiguration.getProperties() ); |
61 | |
} |
62 | |
|
63 | 5 | this.scheduler = schedulerFactory.getScheduler(); |
64 | |
|
65 | 5 | if ( !schedulerConfiguration.startManually() ) |
66 | |
{ |
67 | 4 | scheduler.start(); |
68 | |
} |
69 | 5 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
@Inject |
78 | |
public void setJobFactory( JobFactory jobFactory ) |
79 | |
throws SchedulerException |
80 | |
{ |
81 | 5 | scheduler.setJobFactory( jobFactory ); |
82 | 5 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
@com.google.inject.Inject( optional = true ) |
91 | |
public void addJobListeners( Set<JobListener> jobListeners ) |
92 | |
throws SchedulerException |
93 | |
{ |
94 | 5 | for ( JobListener jobListener : jobListeners ) |
95 | |
{ |
96 | 0 | scheduler.getListenerManager().addJobListener( jobListener ); |
97 | |
} |
98 | 5 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
@com.google.inject.Inject( optional = true ) |
107 | |
public void addSchedulerListeners( Set<SchedulerListener> schedulerListeners ) |
108 | |
throws SchedulerException |
109 | |
{ |
110 | 5 | for ( SchedulerListener schedulerListener : schedulerListeners ) |
111 | |
{ |
112 | 0 | scheduler.getListenerManager().addSchedulerListener( schedulerListener ); |
113 | |
} |
114 | 5 | } |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
@com.google.inject.Inject( optional = true ) |
123 | |
public void addTriggerListeners( Set<TriggerListener> triggerListeners ) |
124 | |
throws SchedulerException |
125 | |
{ |
126 | 5 | for ( TriggerListener triggerListener : triggerListeners ) |
127 | |
{ |
128 | 0 | scheduler.getListenerManager().addTriggerListener( triggerListener ); |
129 | |
} |
130 | 5 | } |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
public Scheduler get() |
136 | |
{ |
137 | 5 | return scheduler; |
138 | |
} |
139 | |
|
140 | |
} |