use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.
the class JobQueryTest method createJobWithoutExceptionMsg.
private void createJobWithoutExceptionMsg() {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
JobEntityManager jobManager = commandContext.getJobEntityManager();
timerEntity = new TimerEntity();
timerEntity.setLockOwner(UUID.randomUUID().toString());
timerEntity.setDuedate(new Date());
timerEntity.setRetries(0);
StringWriter stringWriter = new StringWriter();
NullPointerException exception = new NullPointerException();
exception.printStackTrace(new PrintWriter(stringWriter));
timerEntity.setExceptionStacktrace(stringWriter.toString());
jobManager.insert(timerEntity);
assertNotNull(timerEntity.getId());
return null;
}
});
}
use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.
the class ProcessEngineConfigurationImpl method initIdGenerator.
// id generator /////////////////////////////////////////////////////////////
protected void initIdGenerator() {
if (idGenerator == null) {
CommandExecutor idGeneratorCommandExecutor = null;
if (idGeneratorDataSource != null) {
ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneProcessEngineConfiguration();
processEngineConfiguration.setDataSource(idGeneratorDataSource);
processEngineConfiguration.setDatabaseSchemaUpdate(DB_SCHEMA_UPDATE_FALSE);
processEngineConfiguration.init();
idGeneratorCommandExecutor = processEngineConfiguration.getCommandExecutor();
} else if (idGeneratorDataSourceJndiName != null) {
ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneProcessEngineConfiguration();
processEngineConfiguration.setDataSourceJndiName(idGeneratorDataSourceJndiName);
processEngineConfiguration.setDatabaseSchemaUpdate(DB_SCHEMA_UPDATE_FALSE);
processEngineConfiguration.init();
idGeneratorCommandExecutor = processEngineConfiguration.getCommandExecutor();
} else {
idGeneratorCommandExecutor = getCommandExecutor();
}
DbIdGenerator dbIdGenerator = new DbIdGenerator();
dbIdGenerator.setIdBlockSize(idBlockSize);
dbIdGenerator.setCommandExecutor(idGeneratorCommandExecutor);
dbIdGenerator.setCommandConfig(getDefaultCommandConfig().transactionRequiresNew());
idGenerator = dbIdGenerator;
}
}
use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.
the class StandaloneMybatisTransactionContext method fireTransactionEvent.
/**
* Fires the event for the provided {@link TransactionState}.
*
* @param transactionState The {@link TransactionState} for which the listeners will be called.
* @param executeInNewContext If true, the listeners will be called in a new command context.
* This is needed for example when firing the {@link TransactionState#COMMITTED}
* event: the transaction is already committed and executing logic in the same
* context could lead to strange behaviour (for example doing a {@link SqlSession#update(String)}
* would actually roll back the update (as the MyBatis context is already committed
* and the internal flags have not been correctly set).
*/
protected void fireTransactionEvent(TransactionState transactionState, boolean executeInNewContext) {
if (stateTransactionListeners == null) {
return;
}
final List<TransactionListener> transactionListeners = stateTransactionListeners.get(transactionState);
if (transactionListeners == null) {
return;
}
if (executeInNewContext) {
CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
commandExecutor.execute(commandConfig, new Command<Void>() {
public Void execute(CommandContext commandContext) {
executeTransactionListeners(transactionListeners, commandContext);
return null;
}
});
} else {
executeTransactionListeners(transactionListeners, commandContext);
}
}
use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.
the class DbSchemaDrop method main.
public static void main(String[] args) {
ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new Command<Object>() {
public Object execute(CommandContext commandContext) {
commandContext.getSession(DbSqlSession.class).dbSchemaDrop();
return null;
}
});
}
use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.
the class AcquireJobsRunnableImpl method run.
public synchronized void run() {
log.info("{} starting to acquire jobs", jobExecutor.getName());
final CommandExecutor commandExecutor = jobExecutor.getCommandExecutor();
while (!isInterrupted) {
isJobAdded = false;
int maxJobsPerAcquisition = jobExecutor.getMaxJobsPerAcquisition();
try {
AcquiredJobs acquiredJobs = commandExecutor.execute(jobExecutor.getAcquireJobsCmd());
for (List<String> jobIds : acquiredJobs.getJobIdBatches()) {
jobExecutor.executeJobs(jobIds);
}
// if all jobs were executed
millisToWait = jobExecutor.getWaitTimeInMillis();
int jobsAcquired = acquiredJobs.getJobIdBatches().size();
if (jobsAcquired >= maxJobsPerAcquisition) {
millisToWait = 0;
}
} catch (ActivitiOptimisticLockingException optimisticLockingException) {
// See https://activiti.atlassian.net/browse/ACT-1390
if (log.isDebugEnabled()) {
log.debug("Optimistic locking exception during job acquisition. If you have multiple job executors running against the same database, " + "this exception means that this thread tried to acquire a job, which already was acquired by another job executor acquisition 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 e) {
log.error("exception during job acquisition: {}", e.getMessage(), e);
millisToWait = jobExecutor.getWaitTimeInMillis();
}
if ((millisToWait > 0) && (!isJobAdded)) {
try {
if (log.isDebugEnabled()) {
log.debug("job acquisition thread sleeping for {} millis", millisToWait);
}
synchronized (MONITOR) {
if (!isInterrupted) {
isWaiting.set(true);
MONITOR.wait(millisToWait);
}
}
if (log.isDebugEnabled()) {
log.debug("job acquisition thread woke up");
}
} catch (InterruptedException e) {
if (log.isDebugEnabled()) {
log.debug("job acquisition wait interrupted");
}
} finally {
isWaiting.set(false);
}
}
}
log.info("{} stopped job acquisition", jobExecutor.getName());
}
Aggregations