DeleteTempArchiveScheduler.java
4.95 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.commons.scheduler.Scheduler
* org.apache.sling.jcr.api.SlingRepository
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aem.formsndocuments.scheduler;
import com.adobe.aem.formsndocuments.util.FMUtils;
import com.adobe.aemforms.fm.exception.FormsMgrException;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.scheduler.Scheduler;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1)
@Service(value={DeleteTempArchiveScheduler.class})
public class DeleteTempArchiveScheduler {
private static final long DEFAULT_DELETION_SCHEDULING_PERIOD = 720;
private long deletionSchedulingPeriod;
@Reference(referenceInterface=SlingRepository.class)
private SlingRepository repository;
@Reference(referenceInterface=Scheduler.class)
private Scheduler scheduler;
protected final Logger log;
private static final String DELETE_TEMP_ARCHIVE_JOB_NAME = "FMDeleteTempArchive";
public DeleteTempArchiveScheduler() {
this.log = LoggerFactory.getLogger(this.getClass());
}
protected void activate(ComponentContext componentContext) {
this.setDeletionSchedulingPeriod(720);
long period = this.getDeletionSchedulingPeriod() * 60;
this.log.info("Period for DeleteTempArchiveScheduler Service : " + period + " seconds");
HashMap jobConfig = new HashMap();
boolean runConcurrently = false;
Runnable deleteTempArchiveJob = new Runnable(){
@Override
public void run() {
DeleteTempArchiveScheduler.this.log.info("Running DeleteTempArchiveScheduler service.");
try {
DeleteTempArchiveScheduler.this.deleteTempArchives();
}
catch (Exception e) {
DeleteTempArchiveScheduler.this.log.error("Exception occured while running deletion scheduler ", (Throwable)e);
}
}
};
try {
this.log.debug("Adding job FMDeleteTempArchive to the scheduler");
this.scheduler.addPeriodicJob("FMDeleteTempArchive", (Object)deleteTempArchiveJob, jobConfig, period, runConcurrently);
}
catch (Exception e) {
this.log.error("Exception occured while adding job to the scheduler ", (Throwable)e);
}
}
protected void deactivate(ComponentContext componentContext) {
try {
this.log.debug("Removing job FMDeleteTempArchive from scheduler");
this.scheduler.removeJob("FMDeleteTempArchive");
}
catch (NoSuchElementException noJobException) {
this.log.error("Exception while deregistering the temp archive deletion job", (Throwable)noJobException);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void deleteTempArchives() throws FormsMgrException {
Session session = null;
try {
session = FMUtils.getFnDServiceUserSession(this.repository);
FMUtils.deleteTempArchives(session);
}
catch (Exception e) {
this.log.error("Exception while deleting temporary archives.", (Throwable)e);
this.throwFormsManagerException(e);
}
finally {
if (session != null) {
session.logout();
}
}
}
private void throwFormsManagerException(Exception e) throws FormsMgrException {
if (e instanceof FormsMgrException) {
throw (FormsMgrException)e;
}
throw new FormsMgrException(e);
}
public long getDeletionSchedulingPeriod() {
return this.deletionSchedulingPeriod;
}
public void setDeletionSchedulingPeriod(long deletionSchedulingPeriod) {
this.deletionSchedulingPeriod = deletionSchedulingPeriod;
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindScheduler(Scheduler scheduler) {
this.scheduler = scheduler;
}
protected void unbindScheduler(Scheduler scheduler) {
if (this.scheduler == scheduler) {
this.scheduler = null;
}
}
}