本文整理汇总了Java中org.activiti.engine.ActivitiOptimisticLockingException类的典型用法代码示例。如果您正苦于以下问题:Java ActivitiOptimisticLockingException类的具体用法?Java ActivitiOptimisticLockingException怎么用?Java ActivitiOptimisticLockingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActivitiOptimisticLockingException类属于org.activiti.engine包,在下文中一共展示了ActivitiOptimisticLockingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteProcessInstance
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
public void deleteProcessInstance(String userId, String processInstanceId, String deleteReason) {
try {
engine.getIdentityService().setAuthenticatedUserId(userId);
long deadline = System.currentTimeMillis() + DEFAULT_ABORT_TIMEOUT_MS;
while (true) {
try {
LOGGER.debug(format(Messages.SETTING_VARIABLE, Constants.PROCESS_ABORTED, Boolean.TRUE));
// TODO: Use execution ID instead of process instance ID, as they can be
// different if the process has parallel executions.
engine.getRuntimeService().setVariable(processInstanceId, Constants.PROCESS_ABORTED, Boolean.TRUE);
LOGGER.debug(format(Messages.SET_SUCCESSFULLY, Constants.PROCESS_ABORTED));
engine.getRuntimeService().deleteProcessInstance(processInstanceId, deleteReason);
break;
} catch (ActivitiOptimisticLockingException e) {
if (isPastDeadline(deadline)) {
throw new IllegalStateException(Messages.ABORT_OPERATION_TIMED_OUT, e);
}
LOGGER.warn(format(Messages.RETRYING_PROCESS_ABORT, processInstanceId));
}
}
} finally {
engine.getIdentityService().setAuthenticatedUserId(null);
}
}
示例2: unlockJobIsNeeded
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的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);
}
}
示例3: execute
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
@Override
public <T> T execute(CommandConfig config, Command<T> command) {
long waitTime = waitTimeInMs;
int failedAttempts = 0;
do {
if (failedAttempts > 0) {
LOGGER.info("Waiting for {}ms before retrying the command.", waitTime);
waitBeforeRetry(waitTime);
waitTime *= waitIncreaseFactor;
}
try {
// try to execute the command
return next.execute(config, command);
} catch (ActivitiOptimisticLockingException e) {
LOGGER.info("Caught optimistic locking exception: {}", e.getMessage(), e);
}
failedAttempts++;
} while (failedAttempts <= numOfRetries);
throw new ActivitiException(numOfRetries + " retries failed with ActivitiOptimisticLockingException. Giving up.");
}
示例4: updateProcessInstanceLockTime
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
public void updateProcessInstanceLockTime(String processInstanceId) {
CommandContext commandContext = Context.getCommandContext();
Date expirationTime = commandContext.getProcessEngineConfiguration().getClock().getCurrentTime();
int lockMillis = commandContext.getProcessEngineConfiguration().getAsyncExecutorAsyncJobLockTimeInMillis();
GregorianCalendar lockCal = new GregorianCalendar();
lockCal.setTime(expirationTime);
lockCal.add(Calendar.MILLISECOND, lockMillis);
HashMap<String, Object> params = new HashMap<>();
params.put("id", processInstanceId);
params.put("lockTime", lockCal.getTime());
params.put("expirationTime", expirationTime);
int result = getDbSqlSession().update("updateProcessInstanceLockTime", params);
if (result == 0) {
throw new ActivitiOptimisticLockingException("Could not lock process instance");
}
}
示例5: execute
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
@Override
public void execute() {
String deleteStatement = dbSqlSessionFactory.getDeleteStatement(persistentObject.getClass());
deleteStatement = dbSqlSessionFactory.mapStatement(deleteStatement);
if (deleteStatement == null) {
throw new ActivitiException("no delete statement for " + persistentObject.getClass() + " in the ibatis mapping files");
}
// It only makes sense to check for optimistic locking exceptions for objects that actually have a revision
if (persistentObject instanceof HasRevision) {
int nrOfRowsDeleted = sqlSession.delete(deleteStatement, persistentObject);
if (nrOfRowsDeleted == 0) {
throw new ActivitiOptimisticLockingException(persistentObject + " was updated by another transaction concurrently");
}
} else {
sqlSession.delete(deleteStatement, persistentObject);
}
}
示例6: flushUpdates
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
protected void flushUpdates(List<PersistentObject> updatedObjects) {
for (PersistentObject updatedObject : updatedObjects) {
String updateStatement = dbSqlSessionFactory.getUpdateStatement(updatedObject);
updateStatement = dbSqlSessionFactory.mapStatement(updateStatement);
if (updateStatement == null) {
throw new ActivitiException("no update statement for " + updatedObject.getClass() + " in the ibatis mapping files");
}
LOGGER.debug("updating: {}", updatedObject);
int updatedRecords = sqlSession.update(updateStatement, updatedObject);
if (updatedRecords != 1) {
throw new ActivitiOptimisticLockingException(updatedObject + " was updated by another transaction concurrently");
}
// See https://activiti.atlassian.net/browse/ACT-1290
if (updatedObject instanceof HasRevision) {
((HasRevision) updatedObject).setRevision(((HasRevision) updatedObject).getRevisionNext());
}
}
updatedObjects.clear();
}
示例7: execute
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
public <T> T execute(Command<T> command) {
long waitTime=waitTimeInMs;
int failedAttempts=0;
do {
if (failedAttempts > 0) {
log.info( "Waiting for "+waitTime+"ms before retrying the command." );
waitBeforeRetry(waitTime);
waitTime *= waitIncreaseFactor;
}
try {
// try to execute the command
return next.execute(command);
} catch (ActivitiOptimisticLockingException e) {
log.log(Level.INFO, "Caught optimistic locking exception: "+e);
}
failedAttempts ++;
} while(failedAttempts<=numOfRetries);
throw new ActivitiException(numOfRetries + " retries failed with ActivitiOptimisticLockingException. Giving up.");
}
示例8: execute
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
public <T> T execute(CommandConfig config, Command<T> command) {
long waitTime=waitTimeInMs;
int failedAttempts=0;
do {
if (failedAttempts > 0) {
log.info( "Waiting for {}ms before retrying the command.", waitTime);
waitBeforeRetry(waitTime);
waitTime *= waitIncreaseFactor;
}
try {
// try to execute the command
return next.execute(config, command);
} catch (ActivitiOptimisticLockingException e) {
log.info("Caught optimistic locking exception: "+e);
}
failedAttempts ++;
} while(failedAttempts<=numOfRetries);
throw new ActivitiException(numOfRetries + " retries failed with ActivitiOptimisticLockingException. Giving up.");
}
示例9: execute
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
public void execute() {
String deleteStatement = dbSqlSessionFactory.getDeleteStatement(persistentObject.getClass());
deleteStatement = dbSqlSessionFactory.mapStatement(deleteStatement);
if (deleteStatement == null) {
throw new ActivitiException("no delete statement for " + persistentObject.getClass() + " in the ibatis mapping files");
}
// It only makes sense to check for optimistic locking exceptions for objects that actually have a revision
if (persistentObject instanceof HasRevision) {
int nrOfRowsDeleted = sqlSession.delete(deleteStatement, persistentObject);
if (nrOfRowsDeleted == 0) {
throw new ActivitiOptimisticLockingException(persistentObject + " was updated by another transaction concurrently");
}
} else {
sqlSession.delete(deleteStatement, persistentObject);
}
}
示例10: flushUpdates
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
protected void flushUpdates(List<PersistentObject> updatedObjects) {
for (PersistentObject updatedObject: updatedObjects) {
String updateStatement = dbSqlSessionFactory.getUpdateStatement(updatedObject);
updateStatement = dbSqlSessionFactory.mapStatement(updateStatement);
if (updateStatement==null) {
throw new ActivitiException("no update statement for "+updatedObject.getClass()+" in the ibatis mapping files");
}
log.debug("updating: {}", updatedObject);
int updatedRecords = sqlSession.update(updateStatement, updatedObject);
if (updatedRecords!=1) {
throw new ActivitiOptimisticLockingException(updatedObject + " was updated by another transaction concurrently");
}
// See http://jira.codehaus.org/browse/ACT-1290
if (updatedObject instanceof HasRevision) {
((HasRevision) updatedObject).setRevision(((HasRevision) updatedObject).getRevisionNext());
}
}
updatedObjects.clear();
}
示例11: testOptimisticLockingThrownOnMultipleUpdates
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
public void testOptimisticLockingThrownOnMultipleUpdates() {
Task task = taskService.newTask();
taskService.saveTask(task);
String taskId = task.getId();
// first modification
Task task1 = taskService.createTaskQuery().taskId(taskId).singleResult();
Task task2 = taskService.createTaskQuery().taskId(taskId).singleResult();
task1.setDescription("first modification");
taskService.saveTask(task1);
// second modification on the initial instance
task2.setDescription("second modification");
try {
taskService.saveTask(task2);
fail("should get an exception here as the task was modified by someone else.");
} catch (ActivitiOptimisticLockingException expected) {
// exception was thrown as expected
}
taskService.deleteTask(taskId, true);
}
示例12: testUserTaskOptimisticLocking
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testUserTaskOptimisticLocking() {
runtimeService.startProcessInstanceByKey("oneTaskProcess");
Task task1 = taskService.createTaskQuery().singleResult();
Task task2 = taskService.createTaskQuery().singleResult();
task1.setDescription("test description one");
taskService.saveTask(task1);
try {
task2.setDescription("test description two");
taskService.saveTask(task2);
fail("Expecting exception");
} catch(ActivitiOptimisticLockingException e) {
// Expected exception
}
}
示例13: testUserOptimisticLockingException
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
public void testUserOptimisticLockingException() {
User user = identityService.newUser("kermit");
identityService.saveUser(user);
User user1 = identityService.createUserQuery().singleResult();
User user2 = identityService.createUserQuery().singleResult();
user1.setFirstName("name one");
identityService.saveUser(user1);
try {
user2.setFirstName("name two");
identityService.saveUser(user2);
fail("Expected an exception");
} catch (ActivitiOptimisticLockingException e) {
// Expected an exception
}
identityService.deleteUser(user.getId());
}
示例14: testGroupOptimisticLockingException
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
public void testGroupOptimisticLockingException() {
Group group = identityService.newGroup("group");
identityService.saveGroup(group);
Group group1 = identityService.createGroupQuery().singleResult();
Group group2 = identityService.createGroupQuery().singleResult();
group1.setName("name one");
identityService.saveGroup(group1);
try {
group2.setName("name two");
identityService.saveGroup(group2);
fail("Expected an exception");
} catch (ActivitiOptimisticLockingException e) {
// Expected an exception
}
identityService.deleteGroup(group.getId());
}
示例15: flushUpdates
import org.activiti.engine.ActivitiOptimisticLockingException; //导入依赖的package包/类
protected void flushUpdates(List<PersistentObject> updatedObjects) {
for (PersistentObject updatedObject: updatedObjects) {
String updateStatement = dbSqlSessionFactory.getUpdateStatement(updatedObject);
updateStatement = dbSqlSessionFactory.mapStatement(updateStatement);
if (updateStatement==null) {
throw new ActivitiException("no update statement for "+updatedObject.getClass()+" in the ibatis mapping files");
}
log.fine("updating: "+toString(updatedObject)+"]");
int updatedRecords = sqlSession.update(updateStatement, updatedObject);
if (updatedRecords!=1) {
throw new ActivitiOptimisticLockingException(toString(updatedObject)+" was updated by another transaction concurrently");
}
}
updatedObjects.clear();
}