MaintenanceTaskInfoImpl.java
4.97 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.commons.osgi.PropertiesUtil
* org.apache.sling.event.jobs.Job
* org.apache.sling.event.jobs.Job$JobState
* org.apache.sling.event.jobs.JobManager
* org.apache.sling.event.jobs.JobManager$QueryType
* org.osgi.framework.ServiceReference
*/
package com.adobe.granite.maintenance.impl;
import com.adobe.granite.maintenance.MaintenanceTaskInfo;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.JobManager;
import org.osgi.framework.ServiceReference;
public class MaintenanceTaskInfoImpl
implements MaintenanceTaskInfo {
public static final String PROPERTY_TASK_TOPICS = "job.topics";
private final String name;
private final String title;
private final boolean stoppable;
private final boolean conservative;
private final boolean supportsThrottling;
private final boolean mandatory;
private final ServiceReference reference;
private final MaintenanceTaskInfo.TaskSchedule schedule;
private final JobManager jobManager;
public MaintenanceTaskInfoImpl(JobManager jobManager, ServiceReference ref) {
this.jobManager = jobManager;
this.reference = ref;
this.name = PropertiesUtil.toString((Object)this.reference.getProperty("granite.maintenance.name"), (String)null);
this.title = PropertiesUtil.toString((Object)this.reference.getProperty("granite.maintenance.title"), (String)null);
this.stoppable = PropertiesUtil.toBoolean((Object)this.reference.getProperty("granite.maintenance.isStoppable"), (boolean)false);
this.conservative = PropertiesUtil.toBoolean((Object)this.reference.getProperty("granite.maintenance.isConservative"), (boolean)true);
this.supportsThrottling = PropertiesUtil.toBoolean((Object)this.reference.getProperty("granite.maintenance.supportsThrottling"), (boolean)false);
this.mandatory = PropertiesUtil.toBoolean((Object)this.reference.getProperty("granite.maintenance.mandatory"), (boolean)false);
String scheduleInfo = PropertiesUtil.toString((Object)this.reference.getProperty("granite.maintenance.schedule"), (String)null);
this.schedule = scheduleInfo != null ? MaintenanceTaskInfo.TaskSchedule.valueOf(scheduleInfo.toUpperCase()) : null;
}
@Override
public String getName() {
return this.name;
}
@Override
public boolean isStoppable() {
return this.stoppable;
}
@Override
public boolean isConservative() {
return this.conservative;
}
@Override
public boolean supportsThrottling() {
return this.supportsThrottling;
}
@Override
public boolean isMandatory() {
return this.mandatory;
}
@Override
public String getDescription() {
return (String)this.reference.getProperty("service.description");
}
@Override
public String getTitle() {
return this.title;
}
@Override
public boolean isRunning() {
Collection jobs = this.jobManager.findJobs(JobManager.QueryType.ACTIVE, this.getTaskTopic(), 1, (Map[])null);
return !jobs.isEmpty();
}
@Override
public Calendar getLastRunTime() {
Collection jobs = this.jobManager.findJobs(JobManager.QueryType.HISTORY, this.getTaskTopic(), 1, (Map[])null);
if (!jobs.isEmpty()) {
return ((Job)jobs.iterator().next()).getFinishedDate();
}
return null;
}
@Override
public MaintenanceTaskInfo.TaskState getLastRunState() {
Collection jobs = this.jobManager.findJobs(JobManager.QueryType.HISTORY, this.getTaskTopic(), 1, (Map[])null);
if (!jobs.isEmpty()) {
Job job = (Job)jobs.iterator().next();
if (job.getJobState() == Job.JobState.SUCCEEDED) {
return MaintenanceTaskInfo.TaskState.SUCCEEDED;
}
if (job.getJobState() == Job.JobState.STOPPED) {
return MaintenanceTaskInfo.TaskState.STOPPED;
}
return MaintenanceTaskInfo.TaskState.FAILED;
}
return MaintenanceTaskInfo.TaskState.UNKNOWN;
}
@Override
public MaintenanceTaskInfo.TaskSchedule getSchedule() {
return MaintenanceTaskInfo.TaskSchedule.DAILY;
}
@Override
public MaintenanceTaskInfo.TaskSchedule getSuggestedSchedule() {
return this.schedule;
}
@Override
public String getTaskTopic() {
return (String)this.reference.getProperty("job.topics");
}
public ServiceReference getServiceReference() {
return this.reference;
}
@Override
public String getConfigurationPid() {
Object prop;
String pid = null;
if (this.reference != null && (prop = this.reference.getProperty("service.pid")) != null) {
pid = prop.toString();
}
return pid;
}
}