Permalink
Browse files

feat(spring): add additional config options as app.properties params

* Make possible to add some configuration options from bpm-platform.xml as
application.properties parameters.
* Process engine
  * camunda.bpm.default-number-of-retries
  * camunda.bpm.job-executor-acquire-by-priority
* Thread pool task executor:
  * camunda.bpm.job-execution.queue-capacity
  * camunda.bpm.job-execution.keep-alive-seconds
* Job executor:
  * camunda.bpm.job-execution.lock-time-in-millis
  * camunda.bpm.job-execution.max-jobs-per-acquisition
  * camunda.bpm.job-execution.wait-time-in-millis
* If no value present the defaults will be used (though not configured in the Spring Boot starter).
* IntelliJ file based projects added to .gitignore

Related to #299, CAM-9163
  • Loading branch information...
ninckblokje authored and koevskinikola committed Jun 25, 2018
1 parent 43438ab commit 919f1404d8ac2ffc24b5d395df4b4b12b0529e84
View
@@ -8,6 +8,8 @@
.factorypath
.idea/
*.iml
*.ipr
*.iws
.DS_Store
#
# MAVEN
@@ -3,6 +3,7 @@
import static org.camunda.bpm.spring.boot.starter.util.CamundaSpringBootUtil.join;
import java.util.List;
import java.util.Optional;
import org.camunda.bpm.engine.impl.jobexecutor.CallerRunsRejectedJobsHandler;
import org.camunda.bpm.engine.impl.jobexecutor.JobExecutor;
@@ -22,6 +23,8 @@
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import javax.swing.text.html.Option;
/**
* Prepares JobExecutor and registers all known custom JobHandlers.
*/
@@ -71,6 +74,10 @@ public static TaskExecutor camundaTaskExecutor(CamundaBpmProperties properties)
threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
Optional.ofNullable(properties.getJobExecution().getKeepAliveSeconds())
.ifPresent(threadPoolTaskExecutor::setKeepAliveSeconds);
Optional.ofNullable(properties.getJobExecution().getQueueCapacity())
.ifPresent(threadPoolTaskExecutor::setQueueCapacity);
LOG.configureJobExecutorPool(corePoolSize, maxPoolSize);
return threadPoolTaskExecutor;
@@ -79,11 +86,18 @@ public static TaskExecutor camundaTaskExecutor(CamundaBpmProperties properties)
@Bean
@ConditionalOnMissingBean(JobExecutor.class)
@ConditionalOnProperty(prefix = "camunda.bpm.job-execution", name = "enabled", havingValue = "true", matchIfMissing = true)
public static JobExecutor jobExecutor(@Qualifier(CAMUNDA_TASK_EXECUTOR_QUALIFIER) final TaskExecutor taskExecutor) {
public static JobExecutor jobExecutor(@Qualifier(CAMUNDA_TASK_EXECUTOR_QUALIFIER) final TaskExecutor taskExecutor, CamundaBpmProperties properties) {
final SpringJobExecutor springJobExecutor = new SpringJobExecutor();
springJobExecutor.setTaskExecutor(taskExecutor);
springJobExecutor.setRejectedJobsHandler(new CallerRunsRejectedJobsHandler());
Optional.ofNullable(properties.getJobExecution().getLockTimeInMillis())
.ifPresent(springJobExecutor::setLockTimeInMillis);
Optional.ofNullable(properties.getJobExecution().getMaxJobsPerAcquisition())
.ifPresent(springJobExecutor::setMaxJobsPerAcquisition);
Optional.ofNullable(properties.getJobExecution().getWaitTimeInMillis())
.ifPresent(springJobExecutor::setWaitTimeInMillis);
return springJobExecutor;
}
@@ -18,6 +18,8 @@ public void preInit(SpringProcessEngineConfiguration configuration) {
setProcessEngineName(configuration);
setDefaultSerializationFormat(configuration);
setIdGenerator(configuration);
setJobExecutorAcquireByPriority(configuration);
setDefaultNumberOfRetries(configuration);
}
private void setIdGenerator(SpringProcessEngineConfiguration configuration) {
@@ -42,5 +44,13 @@ private void setProcessEngineName(SpringProcessEngineConfiguration configuration
}
}
private void setJobExecutorAcquireByPriority(SpringProcessEngineConfiguration configuration) {
Optional.ofNullable(camundaBpmProperties.getJobExecutorAcquireByPriority())
.ifPresent(configuration::setJobExecutorAcquireByPriority);
}
private void setDefaultNumberOfRetries(SpringProcessEngineConfiguration configuration) {
Optional.ofNullable(camundaBpmProperties.getDefaultNumberOfRetries())
.ifPresent(configuration::setDefaultNumberOfRetries);
}
}
@@ -48,6 +48,10 @@ static StringJoiner joinOn(final Class<?> clazz) {
private String idGenerator = IdGeneratorConfiguration.STRONG;
private Boolean jobExecutorAcquireByPriority = null;
private Integer defaultNumberOfRetries = null;
/**
* the history level to use
*/
@@ -272,6 +276,22 @@ public void setIdGenerator(String idGenerator) {
this.idGenerator = idGenerator;
}
public Boolean getJobExecutorAcquireByPriority() {
return jobExecutorAcquireByPriority;
}
public void setJobExecutorAcquireByPriority(Boolean jobExecutorAcquireByPriority) {
this.jobExecutorAcquireByPriority = jobExecutorAcquireByPriority;
}
public Integer getDefaultNumberOfRetries() {
return defaultNumberOfRetries;
}
public void setDefaultNumberOfRetries(Integer defaultNumberOfRetries) {
this.defaultNumberOfRetries = defaultNumberOfRetries;
}
public boolean isEnabled() {
return enabled;
}
@@ -302,6 +322,8 @@ public String toString() {
.add("adminUser=" + adminUser)
.add("filter=" + filter)
.add("idGenerator=" + idGenerator)
.add("jobExecutorAcquireByPriority=" + jobExecutorAcquireByPriority)
.add("defaultNumberOfRetries" + defaultNumberOfRetries)
.toString();
}
@@ -15,7 +15,16 @@
private boolean deploymentAware;
private int corePoolSize = 3;
private Integer keepAliveSeconds;
private int maxPoolSize = 10;
private Integer queueCapacity;
/*
* properties for job executor
*/
private Integer lockTimeInMillis;
private Integer maxJobsPerAcquisition;
private Integer waitTimeInMillis;
public boolean isEnabled() {
return enabled;
@@ -49,13 +58,58 @@ public void setMaxPoolSize(int maxPoolSize) {
this.maxPoolSize = maxPoolSize;
}
public Integer getQueueCapacity() {
return queueCapacity;
}
public void setQueueCapacity(Integer queueCapacity) {
this.queueCapacity = queueCapacity;
}
public Integer getLockTimeInMillis() {
return lockTimeInMillis;
}
public void setLockTimeInMillis(Integer lockTimeInMillis) {
this.lockTimeInMillis = lockTimeInMillis;
}
public Integer getMaxJobsPerAcquisition() {
return maxJobsPerAcquisition;
}
public void setMaxJobsPerAcquisition(Integer maxJobsPerAcquisition) {
this.maxJobsPerAcquisition = maxJobsPerAcquisition;
}
public Integer getWaitTimeInMillis() {
return waitTimeInMillis;
}
public void setWaitTimeInMillis(Integer waitTimeInMillis) {
this.waitTimeInMillis = waitTimeInMillis;
}
public Integer getKeepAliveSeconds() {
return keepAliveSeconds;
}
public void setKeepAliveSeconds(Integer keepAliveSeconds) {
this.keepAliveSeconds = keepAliveSeconds;
}
@Override
public String toString() {
return joinOn(this.getClass())
.add("enabled=" + enabled)
.add("deploymentAware=" + deploymentAware)
.add("corePoolSize=" + corePoolSize)
.add("maxPoolSize=" + maxPoolSize)
.add("queueCapacity=" + queueCapacity)
.add("lockTimeInMillis=" + lockTimeInMillis)
.add("maxJobsPerAcquisition=" + maxJobsPerAcquisition)
.add("waitTimeInMillis=" + waitTimeInMillis)
.add("keepAliveSeconds=" + keepAliveSeconds)
.toString();
}
@@ -73,6 +73,28 @@ public void setDefaultSerializationFormat_ignore_empty() {
assertThat(configuration.getDefaultSerializationFormat()).isEqualTo(defaultSerializationFormat);
}
@Test
public void setJobExecutorAcquireByPriority() {
properties.setJobExecutorAcquireByPriority(null);
instance.preInit(configuration);
assertThat(configuration.isJobExecutorAcquireByPriority()).isEqualTo(false);
properties.setJobExecutorAcquireByPriority(true);
instance.preInit(configuration);
assertThat(configuration.isJobExecutorAcquireByPriority()).isEqualTo(true);
}
@Test
public void setDefaultNumberOfRetries() {
properties.setDefaultNumberOfRetries(null);
instance.preInit(configuration);
assertThat(configuration.getDefaultNumberOfRetries()).isEqualTo(3);
properties.setDefaultNumberOfRetries(1);
instance.preInit(configuration);
assertThat(configuration.getDefaultNumberOfRetries()).isEqualTo(1);
}
private void initIdGenerator(IdGenerator idGenerator) {
ReflectionTestUtils.setField(instance, "idGenerator", Optional.ofNullable(idGenerator));
}

0 comments on commit 919f140

Please sign in to comment.