RevisionCleanupTask.java 3.69 KB
/*
 * 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 Revision Cleanup Task", description="This task runs the revision cleanup of the repository.")
@Service(value={JobExecutor.class})
@Properties(value={@Property(name="granite.maintenance.name", value={"RevisionCleanupTask"}, propertyPrivate=1), @Property(name="granite.maintenance.title", value={"Revision Clean Up"}, 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 revision cleanup task"})})
public class RevisionCleanupTask
extends AbstractBaseTask {
    @Reference
    RepositoryManagementMBean mbean;

    public JobExecutionResult process(Job job, JobExecutionContext context) {
        String prefix = "Failure on executing revision GC: ";
        CompositeData data = this.mbean.startRevisionGC();
        Integer id = data == null ? null : (Integer)data.get("id");
        JobExecutionResult result = null;
        do {
            if ((result = this.createResult(context, "Failure on executing revision GC: ", data, id)) != null) continue;
            if (context.isStopped()) {
                return context.result().message("Failure on executing revision GC: Stopped by user.").failed();
            }
            try {
                Thread.sleep(1000);
            }
            catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            data = this.mbean.getRevisionGCStatus();
        } 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;
        }
    }
}