DataStoreGarbageCollectionTask.java 3.77 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 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;
        }
    }
}