TaskArchiveService.java
4.09 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.taskmanagement.TaskManagerException
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.taskmanagement.impl.jcr;
import com.adobe.granite.taskmanagement.TaskManagerException;
import com.adobe.granite.taskmanagement.impl.jcr.TaskStorageProvider;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(metatype=1, label="Adobe Granite TaskManagement Archiving Service", description="Archives old tasks to a history location to improve runtime performance")
@Service(value={Runnable.class})
public class TaskArchiveService
implements Runnable {
public static final String DEFAULT_CRON_EXPRESSION = "30 0 * * * ?";
public static final boolean DEFAULT_ARCHIVING_ENABLED = false;
@Property(boolValue={0}, label="Enable Archiving", description="Enable or disable archiving of tasks")
public static final String ARCHIVING_ENABLED = "archiving.enabled";
@Property(value={"30 0 * * * ?"}, description="scheduler cron expression. example: '30 0 * * * ?' runs at 00:30 AM", label="cron expression")
public static final String SCHEDULER_EXPRESSION_CRON = "scheduler.expression";
public static final int DEFAULT_ARCHIVE_SINCE_DAYS_COMPLETED = 365;
@Property(intValue={365}, label="Age of Tasks to Archive", description="Number of days after a task is completed before archiving a task. Value must be > 0")
public static final String SCHEDULE_ARCHIVE_SINCE_DAYS_COMPLETED = "archive.since.days.completed";
@Reference
private TaskStorageProvider taskStorageProvider;
private int numberOfDaysOldToArchive;
private boolean archivingEnabled;
private static final Logger log = LoggerFactory.getLogger(TaskArchiveService.class);
@Override
public void run() {
long start = System.currentTimeMillis();
log.info("archiving tasks at: '{}'", (Object)new Date());
if (!this.archivingEnabled) {
log.trace("Archiving of tasks is disabled.");
return;
}
if (this.numberOfDaysOldToArchive < 1) {
log.trace("Archiving of tasks is configured to archive an invalid value {}", (Object)this.numberOfDaysOldToArchive);
return;
}
long numberOfTasksarchived = 0;
if (this.taskStorageProvider != null) {
Calendar cal = Calendar.getInstance();
cal.add(5, - this.numberOfDaysOldToArchive);
try {
numberOfTasksarchived = this.taskStorageProvider.archiveOldTasks(cal.getTime());
}
catch (TaskManagerException e) {
log.error("Error archiving tasks", (Throwable)e);
}
}
log.info("archiving tasks completed in {} seconds. {} tasks archived", (Object)((System.currentTimeMillis() - start) / 1000), (Object)numberOfTasksarchived);
}
@Activate
public void activate(Map<String, Object> props) {
this.numberOfDaysOldToArchive = (Integer)props.get("archive.since.days.completed");
this.archivingEnabled = (Boolean)props.get("archiving.enabled");
}
protected void bindTaskStorageProvider(TaskStorageProvider taskStorageProvider) {
this.taskStorageProvider = taskStorageProvider;
}
protected void unbindTaskStorageProvider(TaskStorageProvider taskStorageProvider) {
if (this.taskStorageProvider == taskStorageProvider) {
this.taskStorageProvider = null;
}
}
}