本文整理汇总了Java中org.activiti.engine.impl.persistence.entity.JobEntity.isExclusive方法的典型用法代码示例。如果您正苦于以下问题:Java JobEntity.isExclusive方法的具体用法?Java JobEntity.isExclusive怎么用?Java JobEntity.isExclusive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.activiti.engine.impl.persistence.entity.JobEntity
的用法示例。
在下文中一共展示了JobEntity.isExclusive方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unlockJobIsNeeded
import org.activiti.engine.impl.persistence.entity.JobEntity; //导入方法依赖的package包/类
protected static void unlockJobIsNeeded(final JobEntity job, final CommandExecutor commandExecutor) {
try {
if (job.isExclusive()) {
commandExecutor.execute(new UnlockExclusiveJobCmd(job));
}
} catch (ActivitiOptimisticLockingException optimisticLockingException) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Optimistic locking exception while unlocking the job. If you have multiple async executors running against the same database, " +
"this exception means that this thread tried to acquire an exclusive job, which already was changed by another async executor thread." +
"This is expected behavior in a clustered environment. " +
"You can ignore this message if you indeed have multiple job executor acquisition threads running against the same database. " +
"Exception message: {}", optimisticLockingException.getMessage());
}
} catch (Throwable t) {
LOGGER.error("Error while unlocking exclusive job {}", job.getId(), t);
}
}
示例2: execute
import org.activiti.engine.impl.persistence.entity.JobEntity; //导入方法依赖的package包/类
public AcquiredJobs execute(CommandContext commandContext) {
String lockOwner = jobExecutor.getLockOwner();
int lockTimeInMillis = jobExecutor.getLockTimeInMillis();
int maxJobsPerAcquisition = jobExecutor.getMaxJobsPerAcquisition();
AcquiredJobs acquiredJobs = new AcquiredJobs();
List<JobEntity> jobs = commandContext
.getJobManager()
.findNextJobsToExecute(new Page(0, maxJobsPerAcquisition));
for (JobEntity job: jobs) {
List<String> jobIds = new ArrayList<String>();
if (job != null) {
job.setLockOwner(lockOwner);
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTime(ClockUtil.getCurrentTime());
gregorianCalendar.add(Calendar.MILLISECOND, lockTimeInMillis);
job.setLockExpirationTime(gregorianCalendar.getTime());
jobIds.add(job.getId());
if (job.isExclusive()) {
// TODO acquire other exclusive jobs for the same process instance.
}
}
acquiredJobs.addJobIds(jobIds);
}
return acquiredJobs;
}
示例3: execute
import org.activiti.engine.impl.persistence.entity.JobEntity; //导入方法依赖的package包/类
public AcquiredJobs execute(CommandContext commandContext) {
String lockOwner = jobExecutor.getLockOwner();
int lockTimeInMillis = jobExecutor.getLockTimeInMillis();
int maxNonExclusiveJobsPerAcquisition = jobExecutor.getMaxJobsPerAcquisition();
AcquiredJobs acquiredJobs = new AcquiredJobs();
List<JobEntity> jobs = commandContext
.getJobEntityManager()
.findNextJobsToExecute(new Page(0, maxNonExclusiveJobsPerAcquisition));
for (JobEntity job: jobs) {
List<String> jobIds = new ArrayList<String>();
if (job != null && !acquiredJobs.contains(job.getId())) {
if (job.isExclusive() && job.getProcessInstanceId() != null) {
// acquire all exclusive jobs in the same process instance
// (includes the current job)
List<JobEntity> exclusiveJobs = commandContext.getJobEntityManager()
.findExclusiveJobsToExecute(job.getProcessInstanceId());
for (JobEntity exclusiveJob : exclusiveJobs) {
if(exclusiveJob != null) {
lockJob(exclusiveJob, lockOwner, lockTimeInMillis);
jobIds.add(exclusiveJob.getId());
}
}
} else {
lockJob(job, lockOwner, lockTimeInMillis);
jobIds.add(job.getId());
}
}
acquiredJobs.addJobIdBatch(jobIds);
}
return acquiredJobs;
}
示例4: executeJob
import org.activiti.engine.impl.persistence.entity.JobEntity; //导入方法依赖的package包/类
public static void executeJob(final JobEntity job, final CommandExecutor commandExecutor) {
try {
if (job.isExclusive()) {
commandExecutor.execute(new LockExclusiveJobCmd(job));
}
} catch (Throwable lockException) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Could not lock exclusive job. Unlocking job so it can be acquired again. Caught exception: {}", lockException.getMessage());
}
unacquireJob(commandExecutor, job);
return;
}
try {
commandExecutor.execute(new Command<Void>() {
@Override
public Void execute(CommandContext commandContext) {
new ExecuteAsyncJobCmd(job).execute(commandContext);
if (job.isExclusive()) {
new UnlockExclusiveJobCmd(job).execute(commandContext);
}
return null;
}
});
} catch (final ActivitiOptimisticLockingException e) {
handleFailedJob(job, e, commandExecutor);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Optimistic locking exception during job execution. If you have multiple async executors running against the same database, " +
"this exception means that this thread tried to acquire an exclusive job, which already was changed by another async executor thread." +
"This is expected behavior in a clustered environment. " +
"You can ignore this message if you indeed have multiple job executor threads running against the same database. " +
"Exception message: {}", e.getMessage());
}
} catch (Throwable exception) {
handleFailedJob(job, exception, commandExecutor);
// Finally, Throw the exception to indicate the ExecuteAsyncJobCmd failed
String message = "Job " + job.getId() + " failed";
LOGGER.error(message, exception);
}
}
示例5: execute
import org.activiti.engine.impl.persistence.entity.JobEntity; //导入方法依赖的package包/类
public AcquiredJobs execute(CommandContext commandContext) {
String lockOwner = jobExecutor.getLockOwner();
int lockTimeInMillis = jobExecutor.getLockTimeInMillis();
int maxJobsPerAcquisition = jobExecutor.getMaxJobsPerAcquisition();
int jobsInThisAcquisition = 0;
AcquiredJobs acquiredJobs = new AcquiredJobs();
List<JobEntity> jobs = commandContext
.getJobManager()
.findNextJobsToExecute(new Page(0, maxJobsPerAcquisition));
for (JobEntity job: jobs) {
List<String> jobIds = new ArrayList<String>();
if (job != null && !acquiredJobs.contains(job.getId())) {
if (job.isExclusive() && job.getProcessInstanceId() != null) {
// acquire all exclusive jobs in the same process instance
// (includes the current job)
List<JobEntity> exclusiveJobs = commandContext.getJobManager()
.findExclusiveJobsToExecute(job.getProcessInstanceId());
for (JobEntity exclusiveJob : exclusiveJobs) {
if(exclusiveJob != null) {
lockJob(exclusiveJob, lockOwner, lockTimeInMillis);
jobIds.add(exclusiveJob.getId());
}
}
} else {
lockJob(job, lockOwner, lockTimeInMillis);
jobIds.add(job.getId());
}
}
acquiredJobs.addJobIdBatch(jobIds);
jobsInThisAcquisition += jobIds.size();
if(jobsInThisAcquisition >= maxJobsPerAcquisition) {
break;
}
}
return acquiredJobs;
}