Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Sep 5, 2018
1 parent 0252e54 commit c3de4c8
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 134 deletions.
Expand Up @@ -101,7 +101,6 @@ private void assertUniqueObjectName() {
public void generateObjectNameWithUniqueNamesDeprecatedPropertyMismatchMainProperty() {
this.environment.setProperty("spring.jmx.unique-names", "false");
this.properties.setUniqueNames(true);

this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("spring.jmx.unique-names");
this.thrown.expectMessage("management.endpoints.jmx.unique-names");
Expand Down
Expand Up @@ -72,10 +72,8 @@ static class LoggingCodecConfiguration {

@Bean
public CodecCustomizer loggingCodecCustomizer(InsightsProperties properties) {
return (configurer) -> {
configurer.defaultCodecs().enableLoggingRequestDetails(
properties.getWeb().isLogRequestDetails());
};
return (configurer) -> configurer.defaultCodecs().enableLoggingRequestDetails(
properties.getWeb().isLogRequestDetails());
}

}
Expand Down
Expand Up @@ -56,15 +56,12 @@ public KafkaStreamsConfiguration defaultKafkaStreamsConfig(Environment environme
Map<String, Object> streamsProperties = this.properties.buildStreamsProperties();
if (this.properties.getStreams().getApplicationId() == null) {
String applicationName = environment.getProperty("spring.application.name");
if (applicationName != null) {
streamsProperties.put(StreamsConfig.APPLICATION_ID_CONFIG,
applicationName);
}
else {
if (applicationName == null) {
throw new InvalidConfigurationPropertyValueException(
"spring.kafka.streams.application-id", null,
"This property is mandatory and fallback 'spring.application.name' is not set either.");
}
streamsProperties.put(StreamsConfig.APPLICATION_ID_CONFIG, applicationName);
}
return new KafkaStreamsConfiguration(streamsProperties);
}
Expand Down
Expand Up @@ -17,7 +17,6 @@
package org.springframework.boot.autoconfigure.task;

import java.util.concurrent.Executor;
import java.util.stream.Collectors;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Expand Down Expand Up @@ -66,14 +65,16 @@ public TaskExecutionAutoConfiguration(TaskExecutionProperties properties,
@ConditionalOnMissingBean
public TaskExecutorBuilder taskExecutorBuilder() {
TaskExecutionProperties.Pool pool = this.properties.getPool();
return new TaskExecutorBuilder().queueCapacity(pool.getQueueCapacity())
.corePoolSize(pool.getCoreSize()).maxPoolSize(pool.getMaxSize())
.allowCoreThreadTimeOut(pool.isAllowCoreThreadTimeout())
.keepAlive(pool.getKeepAlive())
.threadNamePrefix(this.properties.getThreadNamePrefix())
.customizers(this.taskExecutorCustomizers.stream()
.collect(Collectors.toList()))
.taskDecorator(this.taskDecorator.getIfUnique());
TaskExecutorBuilder builder = new TaskExecutorBuilder();
builder = builder.queueCapacity(pool.getQueueCapacity());
builder = builder.corePoolSize(pool.getCoreSize());
builder = builder.maxPoolSize(pool.getMaxSize());
builder = builder.allowCoreThreadTimeOut(pool.isAllowCoreThreadTimeout());
builder = builder.keepAlive(pool.getKeepAlive());
builder = builder.threadNamePrefix(this.properties.getThreadNamePrefix());
builder = builder.customizers(this.taskExecutorCustomizers);
builder = builder.taskDecorator(this.taskDecorator.getIfUnique());
return builder;
}

@Bean(name = APPLICATION_TASK_EXECUTOR_BEAN_NAME)
Expand Down
Expand Up @@ -16,8 +16,6 @@

package org.springframework.boot.autoconfigure.task;

import java.util.stream.Collectors;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
Expand Down Expand Up @@ -55,9 +53,11 @@ public ThreadPoolTaskScheduler taskScheduler(TaskSchedulerBuilder builder) {
@ConditionalOnMissingBean
public TaskSchedulerBuilder taskSchedulerBuilder(TaskSchedulingProperties properties,
ObjectProvider<TaskSchedulerCustomizer> taskSchedulerCustomizers) {
return new TaskSchedulerBuilder().poolSize(properties.getPool().getSize())
.threadNamePrefix(properties.getThreadNamePrefix()).customizers(
taskSchedulerCustomizers.stream().collect(Collectors.toList()));
TaskSchedulerBuilder builder = new TaskSchedulerBuilder();
builder = builder.poolSize(properties.getPool().getSize());
builder = builder.threadNamePrefix(properties.getThreadNamePrefix());
builder = builder.customizers(taskSchedulerCustomizers);
return builder;
}

}
Expand Up @@ -5879,9 +5879,9 @@ The following code shows a typical example:
----



[[boot-features-webclient-runtime]]
=== WebClient Runtime

Spring Boot will auto-detect which `ClientHttpConnector` to drive `WebClient`, depending
on the libraries available on the application classpath.

Expand All @@ -5901,6 +5901,7 @@ You can learn more about the
options in the Spring Framework reference documentation].



[[boot-features-webclient-customization]]
=== WebClient Customization
There are three main approaches to `WebClient` customization, depending on how broadly you
Expand Down
Expand Up @@ -18,7 +18,6 @@

import java.time.Duration;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
Expand Down Expand Up @@ -59,34 +58,31 @@ public class TaskExecutorBuilder {

private final TaskDecorator taskDecorator;

private final Set<TaskExecutorCustomizer> taskExecutorCustomizers;
private final Set<TaskExecutorCustomizer> customizers;

public TaskExecutorBuilder(TaskExecutorCustomizer... taskExecutorCustomizers) {
Assert.notNull(taskExecutorCustomizers,
"TaskExecutorCustomizers must not be null");
public TaskExecutorBuilder() {
this.queueCapacity = null;
this.corePoolSize = null;
this.maxPoolSize = null;
this.allowCoreThreadTimeOut = null;
this.keepAlive = null;
this.threadNamePrefix = null;
this.taskDecorator = null;
this.taskExecutorCustomizers = Collections.unmodifiableSet(
new LinkedHashSet<>(Arrays.asList(taskExecutorCustomizers)));
this.customizers = null;
}

public TaskExecutorBuilder(Integer queueCapacity, Integer corePoolSize,
private TaskExecutorBuilder(Integer queueCapacity, Integer corePoolSize,
Integer maxPoolSize, Boolean allowCoreThreadTimeOut, Duration keepAlive,
String threadNamePrefix, TaskDecorator taskDecorator,
Set<TaskExecutorCustomizer> taskExecutorCustomizers) {
Set<TaskExecutorCustomizer> customizers) {
this.queueCapacity = queueCapacity;
this.corePoolSize = corePoolSize;
this.maxPoolSize = maxPoolSize;
this.allowCoreThreadTimeOut = allowCoreThreadTimeOut;
this.keepAlive = keepAlive;
this.threadNamePrefix = threadNamePrefix;
this.taskDecorator = taskDecorator;
this.taskExecutorCustomizers = taskExecutorCustomizers;
this.customizers = customizers;
}

/**
Expand All @@ -98,7 +94,7 @@ public TaskExecutorBuilder(Integer queueCapacity, Integer corePoolSize,
public TaskExecutorBuilder queueCapacity(int queueCapacity) {
return new TaskExecutorBuilder(queueCapacity, this.corePoolSize, this.maxPoolSize,
this.allowCoreThreadTimeOut, this.keepAlive, this.threadNamePrefix,
this.taskDecorator, this.taskExecutorCustomizers);
this.taskDecorator, this.customizers);
}

/**
Expand All @@ -113,7 +109,7 @@ public TaskExecutorBuilder queueCapacity(int queueCapacity) {
public TaskExecutorBuilder corePoolSize(int corePoolSize) {
return new TaskExecutorBuilder(this.queueCapacity, corePoolSize, this.maxPoolSize,
this.allowCoreThreadTimeOut, this.keepAlive, this.threadNamePrefix,
this.taskDecorator, this.taskExecutorCustomizers);
this.taskDecorator, this.customizers);
}

/**
Expand All @@ -128,7 +124,7 @@ public TaskExecutorBuilder corePoolSize(int corePoolSize) {
public TaskExecutorBuilder maxPoolSize(int maxPoolSize) {
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, maxPoolSize,
this.allowCoreThreadTimeOut, this.keepAlive, this.threadNamePrefix,
this.taskDecorator, this.taskExecutorCustomizers);
this.taskDecorator, this.customizers);
}

/**
Expand All @@ -140,7 +136,7 @@ public TaskExecutorBuilder maxPoolSize(int maxPoolSize) {
public TaskExecutorBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) {
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize,
this.maxPoolSize, allowCoreThreadTimeOut, this.keepAlive,
this.threadNamePrefix, this.taskDecorator, this.taskExecutorCustomizers);
this.threadNamePrefix, this.taskDecorator, this.customizers);
}

/**
Expand All @@ -151,7 +147,7 @@ public TaskExecutorBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut
public TaskExecutorBuilder keepAlive(Duration keepAlive) {
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize,
this.maxPoolSize, this.allowCoreThreadTimeOut, keepAlive,
this.threadNamePrefix, this.taskDecorator, this.taskExecutorCustomizers);
this.threadNamePrefix, this.taskDecorator, this.customizers);
}

/**
Expand All @@ -162,7 +158,7 @@ public TaskExecutorBuilder keepAlive(Duration keepAlive) {
public TaskExecutorBuilder threadNamePrefix(String threadNamePrefix) {
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize,
this.maxPoolSize, this.allowCoreThreadTimeOut, this.keepAlive,
threadNamePrefix, this.taskDecorator, this.taskExecutorCustomizers);
threadNamePrefix, this.taskDecorator, this.customizers);
}

/**
Expand All @@ -173,76 +169,68 @@ public TaskExecutorBuilder threadNamePrefix(String threadNamePrefix) {
public TaskExecutorBuilder taskDecorator(TaskDecorator taskDecorator) {
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize,
this.maxPoolSize, this.allowCoreThreadTimeOut, this.keepAlive,
this.threadNamePrefix, taskDecorator, this.taskExecutorCustomizers);
this.threadNamePrefix, taskDecorator, this.customizers);
}

/**
* Set the {@link TaskExecutorCustomizer TaskExecutorCustomizers} that should be
* applied to the {@link ThreadPoolTaskExecutor}. Customizers are applied in the order
* that they were added after builder configuration has been applied. Setting this
* value will replace any previously configured customizers.
* @param taskExecutorCustomizers the customizers to set
* @param customizers the customizers to set
* @return a new builder instance
* @see #additionalCustomizers(TaskExecutorCustomizer...)
*/
public TaskExecutorBuilder customizers(
TaskExecutorCustomizer... taskExecutorCustomizers) {
Assert.notNull(taskExecutorCustomizers,
"TaskExecutorCustomizers must not be null");
return customizers(Arrays.asList(taskExecutorCustomizers));
public TaskExecutorBuilder customizers(TaskExecutorCustomizer... customizers) {
Assert.notNull(customizers, "Customizers must not be null");
return customizers(Arrays.asList(customizers));
}

/**
* Set the {@link TaskExecutorCustomizer TaskExecutorCustomizers} that should be
* applied to the {@link ThreadPoolTaskExecutor}. Customizers are applied in the order
* that they were added after builder configuration has been applied. Setting this
* value will replace any previously configured customizers.
* @param taskExecutorCustomizers the customizers to set
* @param customizers the customizers to set
* @return a new builder instance
* @see #additionalCustomizers(TaskExecutorCustomizer...)
*/
public TaskExecutorBuilder customizers(
Collection<? extends TaskExecutorCustomizer> taskExecutorCustomizers) {
Assert.notNull(taskExecutorCustomizers,
"TaskExecutorCustomizers must not be null");
public TaskExecutorBuilder customizers(Iterable<TaskExecutorCustomizer> customizers) {
Assert.notNull(customizers, "Customizers must not be null");
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize,
this.maxPoolSize, this.allowCoreThreadTimeOut, this.keepAlive,
this.threadNamePrefix, this.taskDecorator,
Collections.unmodifiableSet(new LinkedHashSet<TaskExecutorCustomizer>(
taskExecutorCustomizers)));
this.threadNamePrefix, this.taskDecorator, append(null, customizers));
}

/**
* Add {@link TaskExecutorCustomizer TaskExecutorCustomizers} that should be applied
* to the {@link ThreadPoolTaskExecutor}. Customizers are applied in the order that
* they were added after builder configuration has been applied.
* @param taskExecutorCustomizers the customizers to add
* @param customizers the customizers to add
* @return a new builder instance
* @see #customizers(TaskExecutorCustomizer...)
*/
public TaskExecutorBuilder additionalCustomizers(
TaskExecutorCustomizer... taskExecutorCustomizers) {
Assert.notNull(taskExecutorCustomizers,
"TaskExecutorCustomizers must not be null");
return additionalCustomizers(Arrays.asList(taskExecutorCustomizers));
TaskExecutorCustomizer... customizers) {
Assert.notNull(customizers, "Customizers must not be null");
return additionalCustomizers(Arrays.asList(customizers));
}

/**
* Add {@link TaskExecutorCustomizer TaskExecutorCustomizers} that should be applied
* to the {@link ThreadPoolTaskExecutor}. Customizers are applied in the order that
* they were added after builder configuration has been applied.
* @param taskExecutorCustomizers the customizers to add
* @param customizers the customizers to add
* @return a new builder instance
* @see #customizers(TaskExecutorCustomizer...)
*/
public TaskExecutorBuilder additionalCustomizers(
Collection<? extends TaskExecutorCustomizer> taskExecutorCustomizers) {
Assert.notNull(taskExecutorCustomizers,
"TaskExecutorCustomizers must not be null");
Iterable<TaskExecutorCustomizer> customizers) {
Assert.notNull(customizers, "Customizers must not be null");
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize,
this.maxPoolSize, this.allowCoreThreadTimeOut, this.keepAlive,
this.threadNamePrefix, this.taskDecorator,
append(this.taskExecutorCustomizers, taskExecutorCustomizers));
append(this.customizers, customizers));
}

/**
Expand Down Expand Up @@ -288,18 +276,15 @@ public <T extends ThreadPoolTaskExecutor> T configure(T taskExecutor) {
map.from(this.threadNamePrefix).whenHasText()
.to(taskExecutor::setThreadNamePrefix);
map.from(this.taskDecorator).to(taskExecutor::setTaskDecorator);

if (!CollectionUtils.isEmpty(this.taskExecutorCustomizers)) {
for (TaskExecutorCustomizer customizer : this.taskExecutorCustomizers) {
customizer.customize(taskExecutor);
}
if (!CollectionUtils.isEmpty(this.customizers)) {
this.customizers.forEach((customizer) -> customizer.customize(taskExecutor));
}
return taskExecutor;
}

private static <T> Set<T> append(Set<T> set, Collection<? extends T> additions) {
private <T> Set<T> append(Set<T> set, Iterable<? extends T> additions) {
Set<T> result = new LinkedHashSet<>((set != null) ? set : Collections.emptySet());
result.addAll(additions);
additions.forEach(result::add);
return Collections.unmodifiableSet(result);
}

Expand Down

0 comments on commit c3de4c8

Please sign in to comment.