use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.
the class CdiProcessEngineTestCase method waitForJobExecutorToProcessAllJobs.
// ////////////////////// copied from AbstractActivitiTestcase
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) {
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
try {
Timer timer = new Timer();
InteruptTask task = new InteruptTask(Thread.currentThread());
timer.schedule(task, maxMillisToWait);
boolean areJobsAvailable = true;
try {
while (areJobsAvailable && !task.isTimeLimitExceeded()) {
Thread.sleep(intervalMillis);
areJobsAvailable = areJobsAvailable();
}
} catch (InterruptedException e) {
} finally {
timer.cancel();
}
if (areJobsAvailable) {
throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
}
} finally {
jobExecutor.shutdown();
}
}
use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.
the class JBossSubsystemXMLTest method testInstallSubsystemWithJobExecutorAndPropertiesXml.
@Test
public void testInstallSubsystemWithJobExecutorAndPropertiesXml() throws Exception {
String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_JOB_EXECUTOR_AND_PROPERTIES);
KernelServices services = createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build();
ServiceContainer container = services.getContainer();
commonSubsystemServicesAreInstalled(container);
// "default" job acquisition ///////////////////////////////////////////////////////////
ServiceController<?> defaultJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("default"));
assertNotNull("platform job acquisition service 'default' should be installed", defaultJobAcquisitionService);
Object value = defaultJobAcquisitionService.getValue();
assertNotNull(value);
assertTrue(value instanceof JobExecutor);
JobExecutor defaultJobExecutor = (JobExecutor) value;
assertEquals(300000, defaultJobExecutor.getLockTimeInMillis());
assertEquals(5000, defaultJobExecutor.getWaitTimeInMillis());
assertEquals(3, defaultJobExecutor.getMaxJobsPerAcquisition());
// ServiceName: 'org.camunda.bpm.platform.job-executor.job-executor-tp'
ServiceController<ManagedQueueExecutorService> managedQueueExecutorServiceController = (ServiceController<ManagedQueueExecutorService>) container.getService(ServiceNames.forManagedThreadPool(SubsystemAttributeDefinitons.DEFAULT_JOB_EXECUTOR_THREADPOOL_NAME));
assertNotNull(managedQueueExecutorServiceController);
ManagedQueueExecutorService managedQueueExecutorService = managedQueueExecutorServiceController.getValue();
assertNotNull(managedQueueExecutorService);
assertEquals("Number of core threads is wrong", SubsystemAttributeDefinitons.DEFAULT_CORE_THREADS, managedQueueExecutorService.getCoreThreads());
assertEquals("Number of max threads is wrong", SubsystemAttributeDefinitons.DEFAULT_MAX_THREADS, managedQueueExecutorService.getMaxThreads());
assertEquals(SubsystemAttributeDefinitons.DEFAULT_KEEPALIVE_TIME, TimeUnit.NANOSECONDS.toSeconds(managedQueueExecutorService.getKeepAlive()));
assertEquals(false, managedQueueExecutorService.isBlocking());
assertEquals(SubsystemAttributeDefinitons.DEFAULT_ALLOW_CORE_TIMEOUT, managedQueueExecutorService.isAllowCoreTimeout());
ServiceController<ThreadFactoryService> threadFactoryService = (ServiceController<ThreadFactoryService>) container.getService(ServiceNames.forThreadFactoryService(SubsystemAttributeDefinitons.DEFAULT_JOB_EXECUTOR_THREADPOOL_NAME));
assertNotNull(threadFactoryService);
// "anders" job acquisition /////////////////////////////////////////////////////////
ServiceController<?> andersJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("anders"));
assertNotNull("platform job acquisition service 'anders' should be installed", andersJobAcquisitionService);
value = andersJobAcquisitionService.getValue();
assertNotNull(value);
assertTrue(value instanceof JobExecutor);
JobExecutor andersJobExecutor = (JobExecutor) value;
assertEquals(600000, andersJobExecutor.getLockTimeInMillis());
assertEquals(10000, andersJobExecutor.getWaitTimeInMillis());
assertEquals(5, andersJobExecutor.getMaxJobsPerAcquisition());
// "mixed" job acquisition /////////////////////////////////////////////////////////
ServiceController<?> mixedJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("mixed"));
assertNotNull("platform job acquisition service 'mixed' should be installed", mixedJobAcquisitionService);
value = mixedJobAcquisitionService.getValue();
assertNotNull(value);
assertTrue(value instanceof JobExecutor);
JobExecutor mixedJobExecutor = (JobExecutor) value;
assertEquals(500000, mixedJobExecutor.getLockTimeInMillis());
// default values
assertEquals(5000, mixedJobExecutor.getWaitTimeInMillis());
assertEquals(3, mixedJobExecutor.getMaxJobsPerAcquisition());
}
use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.
the class StartProcessEngineStep method performOperationStep.
public void performOperationStep(DeploymentOperation operationContext) {
final PlatformServiceContainer serviceContainer = operationContext.getServiceContainer();
final AbstractProcessApplication processApplication = operationContext.getAttachment(PROCESS_APPLICATION);
ClassLoader classLoader = null;
if (processApplication != null) {
classLoader = processApplication.getProcessApplicationClassloader();
}
String configurationClassName = processEngineXml.getConfigurationClass();
if (configurationClassName == null || configurationClassName.isEmpty()) {
configurationClassName = StandaloneProcessEngineConfiguration.class.getName();
}
// create & instantiate configuration class
Class<? extends ProcessEngineConfigurationImpl> configurationClass = loadClass(configurationClassName, classLoader, ProcessEngineConfigurationImpl.class);
ProcessEngineConfigurationImpl configuration = createInstance(configurationClass);
// set UUid generator
// TODO: move this to configuration and use as default?
ProcessEngineConfigurationImpl configurationImpl = configuration;
configurationImpl.setIdGenerator(new StrongUuidGenerator());
// set configuration values
String name = processEngineXml.getName();
configuration.setProcessEngineName(name);
String datasourceJndiName = processEngineXml.getDatasource();
configuration.setDataSourceJndiName(datasourceJndiName);
// apply properties
Map<String, String> properties = processEngineXml.getProperties();
setJobExecutorActivate(configuration, properties);
PropertyHelper.applyProperties(configuration, properties);
// instantiate plugins:
configurePlugins(configuration, processEngineXml, classLoader);
if (processEngineXml.getJobAcquisitionName() != null && !processEngineXml.getJobAcquisitionName().isEmpty()) {
JobExecutor jobExecutor = getJobExecutorService(serviceContainer);
ensureNotNull("Cannot find referenced job executor with name '" + processEngineXml.getJobAcquisitionName() + "'", "jobExecutor", jobExecutor);
// set JobExecutor on process engine
configurationImpl.setJobExecutor(jobExecutor);
}
// start the process engine inside the container.
JmxManagedProcessEngine managedProcessEngineService = createProcessEngineControllerInstance(configuration);
serviceContainer.startService(ServiceTypes.PROCESS_ENGINE, configuration.getProcessEngineName(), managedProcessEngineService);
}
use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.
the class JobRetryCmd method notifyAcquisition.
protected void notifyAcquisition(CommandContext commandContext) {
JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
MessageAddedNotification messageAddedNotification = new MessageAddedNotification(jobExecutor);
TransactionContext transactionContext = commandContext.getTransactionContext();
transactionContext.addTransactionListener(TransactionState.COMMITTED, messageAddedNotification);
}
use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.
the class AbstractProcessEngineTestCase method waitForJobExecutorOnCondition.
public void waitForJobExecutorOnCondition(long maxMillisToWait, Callable<Boolean> condition) {
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
long intervalMillis = 500;
if (maxMillisToWait < (jobExecutor.getWaitTimeInMillis() * 2)) {
maxMillisToWait = (jobExecutor.getWaitTimeInMillis() * 2);
}
try {
Timer timer = new Timer();
InterruptTask task = new InterruptTask(Thread.currentThread());
timer.schedule(task, maxMillisToWait);
boolean conditionIsViolated = true;
try {
while (conditionIsViolated && !task.isTimeLimitExceeded()) {
Thread.sleep(intervalMillis);
conditionIsViolated = !condition.call();
}
} catch (InterruptedException e) {
} catch (Exception e) {
throw new ProcessEngineException("Exception while waiting on condition: " + e.getMessage(), e);
} finally {
timer.cancel();
}
if (conditionIsViolated) {
throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
}
} finally {
jobExecutor.shutdown();
}
}
Aggregations