View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  /*
12  fgetSchedulerFactoryBean * Licensed under the GPL License. You may not use this file except in compliance with the License.
13   * You may obtain a copy of the License at
14   *
15   *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
16   *
17   * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
18   * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
19   * PURPOSE.
20   */
21  package psiprobe;
22  
23  import java.util.Properties;
24  
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  import org.springframework.beans.factory.annotation.Autowired;
28  import org.springframework.context.annotation.Bean;
29  import org.springframework.context.annotation.Configuration;
30  import org.springframework.scheduling.quartz.SchedulerFactoryBean;
31  
32  import psiprobe.scheduler.jobs.AppStatsJobDetail;
33  import psiprobe.scheduler.jobs.ClusterStatsJobDetail;
34  import psiprobe.scheduler.jobs.ConnectorStatsJobDetail;
35  import psiprobe.scheduler.jobs.DatasourceStatsJobDetail;
36  import psiprobe.scheduler.jobs.MemoryStatsJobDetail;
37  import psiprobe.scheduler.jobs.RuntimeStatsJobDetail;
38  import psiprobe.scheduler.jobs.StatsSerializerJobDetail;
39  import psiprobe.scheduler.triggers.AppStatsTrigger;
40  import psiprobe.scheduler.triggers.ClusterStatsTrigger;
41  import psiprobe.scheduler.triggers.ConnectorStatsTrigger;
42  import psiprobe.scheduler.triggers.DatasourceStatsTrigger;
43  import psiprobe.scheduler.triggers.MemoryStatsTrigger;
44  import psiprobe.scheduler.triggers.RuntimeStatsTrigger;
45  import psiprobe.scheduler.triggers.StatsSerializerTrigger;
46  
47  /**
48   * The Class ProbeConfigScheduler.
49   */
50  @Configuration
51  public class ProbeConfigScheduler {
52  
53    /** The Constant logger. */
54    private static final Logger logger = LoggerFactory.getLogger(ProbeConfigScheduler.class);
55  
56    /**
57     * Gets the connector stats job detail.
58     *
59     * @return the connector stats job detail
60     */
61    @Bean(name = "connectorStatsJobDetail")
62    public ConnectorStatsJobDetail getConnectorStatsJobDetail() {
63      logger.debug("Instantiated connectorStatsJobDetail");
64      return new ConnectorStatsJobDetail();
65    }
66  
67    /**
68     * Gets the cluster stats job detail.
69     *
70     * @return the cluster stats job detail
71     */
72    @Bean(name = "clusterStatsJobDetail")
73    public ClusterStatsJobDetail getClusterStatsJobDetail() {
74      logger.debug("Instantiated clusterStatsJobDetail");
75      return new ClusterStatsJobDetail();
76    }
77  
78    /**
79     * Gets the memory stats job detail.
80     *
81     * @return the memory stats job detail
82     */
83    @Bean(name = "memoryStatsJobDetail")
84    public MemoryStatsJobDetail getMemoryStatsJobDetail() {
85      logger.debug("Instantiated memoryStatsJobDetail");
86      return new MemoryStatsJobDetail();
87    }
88  
89    /**
90     * Gets the runtime stats job detail.
91     *
92     * @return the runtime stats job detail
93     */
94    @Bean(name = "runtimeStatsJobDetail")
95    public RuntimeStatsJobDetail getRuntimeStatsJobDetail() {
96      logger.debug("Instantiated runtimeStatsJobDetail");
97      return new RuntimeStatsJobDetail();
98    }
99  
100   /**
101    * Gets the app stats job detail.
102    *
103    * @return the app stats job detail
104    */
105   @Bean(name = "appStatsJobDetail")
106   public AppStatsJobDetail getAppStatsJobDetail() {
107     logger.debug("Instantiated appStatsJobDetail");
108     return new AppStatsJobDetail();
109   }
110 
111   /**
112    * Gets the datasource stats job detail.
113    *
114    * @return the datasource stats job detail
115    */
116   @Bean(name = "datasourceStatsJobDetail")
117   public DatasourceStatsJobDetail getDatasourceStatsJobDetail() {
118     logger.debug("Instantiated datasourceStatsJobDetail");
119     return new DatasourceStatsJobDetail();
120   }
121 
122   /**
123    * Gets the stats serializer job detail.
124    *
125    * @return the stats serializer job detail
126    */
127   @Bean(name = "statsSerializerJobDetail")
128   public StatsSerializerJobDetail getStatsSerializerJobDetail() {
129     logger.debug("Instantiated statsSerializerJobDetail");
130     return new StatsSerializerJobDetail();
131   }
132 
133   /**
134    * Gets the connector stats trigger.
135    *
136    * @return the connector stats trigger
137    */
138   @Bean(name = "connectorStatsTrigger")
139   public ConnectorStatsTrigger getConnectorStatsTrigger() {
140     logger.debug("Instantiated connectorStatsTrigger");
141     ConnectorStatsTrigger trigger = new ConnectorStatsTrigger();
142     trigger.setJobDetail(getConnectorStatsJobDetail().getObject());
143     return trigger;
144   }
145 
146   /**
147    * Gets the cluster stats trigger.
148    *
149    * @return the cluster stats trigger
150    */
151   @Bean(name = "clusterStatsTrigger")
152   public ClusterStatsTrigger getClusterStatsTrigger() {
153     logger.debug("Instantiated clusterStatsTrigger");
154     ClusterStatsTrigger trigger = new ClusterStatsTrigger();
155     trigger.setJobDetail(getClusterStatsJobDetail().getObject());
156     return trigger;
157   }
158 
159   /**
160    * Gets the memory stats trigger.
161    *
162    * @return the memory stats trigger
163    */
164   @Bean(name = "memoryStatsTrigger")
165   public MemoryStatsTrigger getMemoryStatsTrigger() {
166     logger.debug("Instantiated memoryStatsTrigger");
167     MemoryStatsTrigger trigger = new MemoryStatsTrigger();
168     trigger.setJobDetail(getMemoryStatsJobDetail().getObject());
169     return trigger;
170   }
171 
172   /**
173    * Gets the runtime stats trigger.
174    *
175    * @return the runtime stats trigger
176    */
177   @Bean(name = "runtimeStatsTrigger")
178   public RuntimeStatsTrigger getRuntimeStatsTrigger() {
179     logger.debug("Instantiated runtimeStatsTrigger");
180     RuntimeStatsTrigger trigger = new RuntimeStatsTrigger();
181     trigger.setJobDetail(getRuntimeStatsJobDetail().getObject());
182     return trigger;
183   }
184 
185   /**
186    * Gets the app stats trigger.
187    *
188    * @return the app stats trigger
189    */
190   @Bean(name = "appStatsTrigger")
191   public AppStatsTrigger getAppStatsTrigger() {
192     logger.debug("Instantiated appStatsTrigger");
193     AppStatsTrigger trigger = new AppStatsTrigger();
194     trigger.setJobDetail(getAppStatsJobDetail().getObject());
195     return trigger;
196   }
197 
198   /**
199    * Gets the datasource stats trigger.
200    *
201    * @return the datasource stats trigger
202    */
203   @Bean(name = "datasourceStatsTrigger")
204   public DatasourceStatsTrigger getDatasourceStatsTrigger() {
205     logger.debug("Instantiated datasourceStatsTrigger");
206     DatasourceStatsTrigger trigger = new DatasourceStatsTrigger();
207     trigger.setJobDetail(getDatasourceStatsJobDetail().getObject());
208     return trigger;
209   }
210 
211   /**
212    * Gets the stats serializer trigger.
213    *
214    * @return the stats serializer trigger
215    */
216   @Bean(name = "statsSerializerTrigger")
217   public StatsSerializerTrigger getStatsSerializerTrigger() {
218     logger.debug("Instantiated statsSerializerTrigger");
219     StatsSerializerTrigger trigger = new StatsSerializerTrigger();
220     trigger.setJobDetail(getStatsSerializerJobDetail().getObject());
221     return trigger;
222   }
223 
224   /**
225    * Gets the scheduler factory bean.
226    *
227    * @param appStatsTrigger the app stats trigger
228    * @param clusterStatsTrigger the cluster stats trigger
229    * @param connectorStatsTrigger the connector stats trigger
230    * @param datasourceStatsTrigger the datasource stats trigger
231    * @param memoryStatsTrigger the memory stats trigger
232    * @param runtimeStatsTrigger the runtime stats trigger
233    * @param statsSerializerTrigger the stats serializer trigger
234    *
235    * @return the scheduler factory bean
236    */
237   @Bean(name = "scheduler")
238   public SchedulerFactoryBean getSchedulerFactoryBean(@Autowired AppStatsTrigger appStatsTrigger,
239       @Autowired ClusterStatsTrigger clusterStatsTrigger,
240       @Autowired ConnectorStatsTrigger connectorStatsTrigger,
241       @Autowired DatasourceStatsTrigger datasourceStatsTrigger,
242       @Autowired MemoryStatsTrigger memoryStatsTrigger,
243       @Autowired RuntimeStatsTrigger runtimeStatsTrigger,
244       @Autowired StatsSerializerTrigger statsSerializerTrigger) {
245 
246     logger.debug("Instantiated scheduler");
247     SchedulerFactoryBean bean = new SchedulerFactoryBean();
248 
249     // Add Triggers
250     bean.setTriggers(appStatsTrigger.getObject(), clusterStatsTrigger.getObject(),
251         connectorStatsTrigger.getObject(), datasourceStatsTrigger.getObject(),
252         memoryStatsTrigger.getObject(), runtimeStatsTrigger.getObject(),
253         statsSerializerTrigger.getObject());
254 
255     // Add Properties
256     Properties properties = new Properties();
257     properties.setProperty("org.quartz.scheduler.instanceName", "ProbeScheduler");
258     properties.setProperty("org.quartz.threadPool.threadCount", "5");
259     properties.setProperty("org.quartz.threadPool.threadNamePrefix", "Probe_Quartz");
260     bean.setQuartzProperties(properties);
261 
262     return bean;
263   }
264 
265 }