All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cloudfoundry.multiapps.controller.process.util.LockOwnerReleaser Maven / Gradle / Ivy

There is a newer version: 1.183.0
Show newest version
package org.cloudfoundry.multiapps.controller.process.util;

import java.util.List;

import jakarta.inject.Inject;
import jakarta.inject.Named;

import org.apache.commons.collections4.CollectionUtils;
import org.cloudfoundry.multiapps.controller.process.flowable.commands.ClearJobLockOwnersCmd;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.impl.cmd.ClearProcessInstanceLockTimesCmd;
import org.flowable.job.api.Job;
import org.flowable.job.service.JobServiceConfiguration;

@Named("lockOwnerReleaser")
public class LockOwnerReleaser {

    private final ProcessEngine processEngine;

    @Inject
    public LockOwnerReleaser(ProcessEngine processEngine) {
        this.processEngine = processEngine;
    }

    public void release(String lockOwner) {
        clearProcessInstanceLockTime(lockOwner);
        clearJobsLockTime(lockOwner);
    }

    private void clearProcessInstanceLockTime(String lockOwner) {
        processEngine.getProcessEngineConfiguration()
                     .getCommandExecutor()
                     .execute(new ClearProcessInstanceLockTimesCmd(lockOwner));
    }

    private void clearJobsLockTime(String lockOwner) {
        JobServiceConfiguration jobServiceConfiguration = processEngine.getProcessEngineConfiguration()
                                                                       .getAsyncExecutor()
                                                                       .getJobServiceConfiguration();
        List jobs = getStaleJobs(lockOwner);
        if (CollectionUtils.isNotEmpty(jobs)) {
            processEngine.getManagementService()
                         .executeCommand(new ClearJobLockOwnersCmd(jobs, jobServiceConfiguration));
        }
    }

    private List getStaleJobs(String lockOwner) {
        return processEngine.getManagementService()
                            .createJobQuery()
                            .lockOwner(lockOwner)
                            .list();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy