Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SchedulerTool |
|
| 1.4;1,4 |
1 | package org.apache.turbine.services.schedule; | |
2 | ||
3 | ||
4 | /* | |
5 | * Licensed to the Apache Software Foundation (ASF) under one | |
6 | * or more contributor license agreements. See the NOTICE file | |
7 | * distributed with this work for additional information | |
8 | * regarding copyright ownership. The ASF licenses this file | |
9 | * to you under the Apache License, Version 2.0 (the | |
10 | * "License"); you may not use this file except in compliance | |
11 | * with the License. You may obtain a copy of the License at | |
12 | * | |
13 | * http://www.apache.org/licenses/LICENSE-2.0 | |
14 | * | |
15 | * Unless required by applicable law or agreed to in writing, | |
16 | * software distributed under the License is distributed on an | |
17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
18 | * KIND, either express or implied. See the License for the | |
19 | * specific language governing permissions and limitations | |
20 | * under the License. | |
21 | */ | |
22 | ||
23 | ||
24 | import java.util.List; | |
25 | ||
26 | import org.apache.logging.log4j.LogManager; | |
27 | import org.apache.logging.log4j.Logger; | |
28 | import org.apache.turbine.annotation.TurbineService; | |
29 | import org.apache.turbine.services.pull.ApplicationTool; | |
30 | import org.apache.turbine.util.TurbineException; | |
31 | ||
32 | /** | |
33 | * This tool is used to retrieve information about the job scheduler. | |
34 | * | |
35 | * @author <a href="mailto:qmccombs@nequalsone.com">Quinton McCombs</a> | |
36 | * @version $Id: SchedulerTool.java 1854688 2019-03-03 10:36:42Z tv $ | |
37 | */ | |
38 | 0 | public class SchedulerTool implements ApplicationTool |
39 | { | |
40 | /** Used for logging */ | |
41 | 0 | private static final Logger log = LogManager.getLogger(ScheduleService.LOGGER_NAME); |
42 | ||
43 | /** | |
44 | * The scheduler service. | |
45 | */ | |
46 | @TurbineService | |
47 | private ScheduleService schedulerService; | |
48 | ||
49 | /** | |
50 | * Initialize the pull tool | |
51 | */ | |
52 | @Override | |
53 | public void init(Object data) | |
54 | { | |
55 | // Rely on injection | |
56 | 0 | if (schedulerService == null) |
57 | { | |
58 | 0 | log.error("You can not use the SchedulerTool unless you enable " |
59 | +"the Scheduler Service!!!!"); | |
60 | } | |
61 | 0 | } |
62 | ||
63 | /** | |
64 | * Does nothing | |
65 | */ | |
66 | @Override | |
67 | public void refresh() | |
68 | { | |
69 | // empty | |
70 | 0 | } |
71 | ||
72 | /** | |
73 | * Gets the list of scheduled jobs. | |
74 | * | |
75 | * @return List of JobEntry objects. | |
76 | */ | |
77 | public List<? extends JobEntry> getScheduledJobs() | |
78 | { | |
79 | 0 | return schedulerService.listJobs(); |
80 | } | |
81 | ||
82 | /** | |
83 | * Determines if the scheduler service is currently enabled. | |
84 | * @return true if the scheduler is enabled | |
85 | */ | |
86 | public boolean isEnabled() | |
87 | { | |
88 | 0 | return schedulerService.isEnabled(); |
89 | } | |
90 | ||
91 | /** | |
92 | * Gets the job identified by the jobId. | |
93 | * | |
94 | * @param jobId Id of the job to retrieve. | |
95 | * @return The job. Null if the jobId is not found. | |
96 | */ | |
97 | public JobEntry getJob(String jobId) | |
98 | { | |
99 | 0 | JobEntry je = null; |
100 | ||
101 | try | |
102 | { | |
103 | 0 | je = schedulerService.getJob(Integer.parseInt(jobId)); |
104 | } | |
105 | 0 | catch (TurbineException e) |
106 | { | |
107 | 0 | log.error("Could not retreive job id #{}", jobId, e); |
108 | 0 | } |
109 | ||
110 | 0 | return je; |
111 | } | |
112 | ||
113 | } |