DataStoreGarbageCollectionTask.java
3.77 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.ConfigurationPolicy
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean
* org.apache.sling.event.jobs.Job
* org.apache.sling.event.jobs.consumer.JobExecutionContext
* org.apache.sling.event.jobs.consumer.JobExecutionContext$ResultBuilder
* org.apache.sling.event.jobs.consumer.JobExecutionResult
* org.apache.sling.event.jobs.consumer.JobExecutor
*/
package com.adobe.granite.maintenance.crx.impl;
import com.adobe.granite.maintenance.crx.impl.AbstractBaseTask;
import javax.management.openmbean.CompositeData;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobExecutionContext;
import org.apache.sling.event.jobs.consumer.JobExecutionResult;
import org.apache.sling.event.jobs.consumer.JobExecutor;
@Component(policy=ConfigurationPolicy.REQUIRE, metatype=1, label="Adobe Granite Repository Data Store Garbage Collection Task", description="This task runs the garbage collection of the repository.")
@Service(value={JobExecutor.class})
@Properties(value={@Property(name="granite.maintenance.name", value={"DataStoreGarbageCollectionTask"}, propertyPrivate=1), @Property(name="granite.maintenance.title", value={"Data Store Garbage Collection"}, label="Title", description="The title of the task."), @Property(name="granite.maintenance.isStoppable", boolValue={1}, propertyPrivate=1), @Property(name="granite.maintenance.mandatory", boolValue={1}, propertyPrivate=1), @Property(name="granite.maintenance.isConservative", boolValue={1}, propertyPrivate=1), @Property(name="granite.maintenance.supportsThrottling", boolValue={0}, propertyPrivate=1), @Property(name="job.topics", propertyPrivate=1), @Property(name="service.description", value={"This is the data store garbage collection task"})})
public class DataStoreGarbageCollectionTask
extends AbstractBaseTask {
@Reference
RepositoryManagementMBean mbean;
public JobExecutionResult process(Job job, JobExecutionContext context) {
String prefix = "Failure on executing data store GC: ";
CompositeData data = this.mbean.startDataStoreGC(false);
Integer id = data == null ? null : (Integer)data.get("id");
JobExecutionResult result = null;
do {
if ((result = this.createResult(context, "Failure on executing data store GC: ", data, id)) != null) continue;
if (context.isStopped()) {
return context.result().message("Failure on executing data store GC: Stopped by user.").failed();
}
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
data = this.mbean.getDataStoreGCStatus();
} while (result == null);
return result;
}
protected void bindMbean(RepositoryManagementMBean repositoryManagementMBean) {
this.mbean = repositoryManagementMBean;
}
protected void unbindMbean(RepositoryManagementMBean repositoryManagementMBean) {
if (this.mbean == repositoryManagementMBean) {
this.mbean = null;
}
}
}