提交 157dcab5 编写于 作者: J Juergen Hoeller

Cleanup of remaining direct BeanWrapper usage

Issue: SPR-14121
上级 5c1d3fca
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -48,6 +48,19 @@ import java.beans.PropertyDescriptor;
*/
public interface BeanWrapper extends ConfigurablePropertyAccessor {
/**
* Specify a limit for array and collection auto-growing.
* <p>Default is unlimited on a plain BeanWrapper.
* @since 4.1
*/
void setAutoGrowCollectionLimit(int autoGrowCollectionLimit);
/**
* Return the limit for array and collection auto-growing.
* @since 4.1
*/
int getAutoGrowCollectionLimit();
/**
* Return the bean instance wrapped by this object, if any.
* @return the bean instance, or {@code null} if none set
......@@ -78,15 +91,4 @@ public interface BeanWrapper extends ConfigurablePropertyAccessor {
*/
PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException;
/**
* Specify a limit for array and collection auto-growing.
* <p>Default is unlimited on a plain BeanWrapper.
*/
void setAutoGrowCollectionLimit(int autoGrowCollectionLimit);
/**
* Return the limit for array and collection auto-growing.
*/
int getAutoGrowCollectionLimit();
}
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -72,8 +72,8 @@ public class SpringBeanJobFactory extends AdaptableJobFactory implements Schedul
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
Object job = super.createJobInstance(bundle);
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
if (isEligibleForPropertyPopulation(job)) {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
MutablePropertyValues pvs = new MutablePropertyValues();
if (this.schedulerContext != null) {
pvs.addPropertyValues(this.schedulerContext);
......
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -61,9 +61,6 @@ public class ExecutorBeanDefinitionParser extends AbstractSingleBeanDefinitionPa
return;
}
String prefix = "java.util.concurrent.ThreadPoolExecutor.";
if (builder.getRawBeanDefinition().getBeanClassName().contains("backport")) {
prefix = "edu.emory.mathcs.backport." + prefix;
}
String policyClassName;
if (rejectionPolicy.equals("ABORT")) {
policyClassName = prefix + "AbortPolicy";
......
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -16,8 +16,8 @@
package org.springframework.scheduling.config;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import java.util.concurrent.RejectedExecutionHandler;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
......@@ -27,8 +27,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.StringUtils;
/**
* FactoryBean for creating ThreadPoolTaskExecutor instances, choosing
* between the standard concurrent and the backport-concurrent variant.
* {@link FactoryBean} for creating {@link ThreadPoolTaskExecutor} instances,
* primarily used behind the XML task namespace.
*
* @author Mark Fisher
* @author Juergen Hoeller
......@@ -41,13 +41,13 @@ public class TaskExecutorFactoryBean implements
private Integer queueCapacity;
private Object rejectedExecutionHandler;
private RejectedExecutionHandler rejectedExecutionHandler;
private Integer keepAliveSeconds;
private String beanName;
private TaskExecutor target;
private ThreadPoolTaskExecutor target;
public void setPoolSize(String poolSize) {
......@@ -58,7 +58,7 @@ public class TaskExecutorFactoryBean implements
this.queueCapacity = queueCapacity;
}
public void setRejectedExecutionHandler(Object rejectedExecutionHandler) {
public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) {
this.rejectedExecutionHandler = rejectedExecutionHandler;
}
......@@ -73,28 +73,25 @@ public class TaskExecutorFactoryBean implements
@Override
public void afterPropertiesSet() throws Exception {
BeanWrapper bw = new BeanWrapperImpl(ThreadPoolTaskExecutor.class);
determinePoolSizeRange(bw);
public void afterPropertiesSet() {
this.target = new ThreadPoolTaskExecutor();
determinePoolSizeRange();
if (this.queueCapacity != null) {
bw.setPropertyValue("queueCapacity", this.queueCapacity);
this.target.setQueueCapacity(this.queueCapacity);
}
if (this.keepAliveSeconds != null) {
bw.setPropertyValue("keepAliveSeconds", this.keepAliveSeconds);
this.target.setKeepAliveSeconds(this.keepAliveSeconds);
}
if (this.rejectedExecutionHandler != null) {
bw.setPropertyValue("rejectedExecutionHandler", this.rejectedExecutionHandler);
this.target.setRejectedExecutionHandler(this.rejectedExecutionHandler);
}
if (this.beanName != null) {
bw.setPropertyValue("threadNamePrefix", this.beanName + "-");
}
this.target = (TaskExecutor) bw.getWrappedInstance();
if (this.target instanceof InitializingBean) {
((InitializingBean) this.target).afterPropertiesSet();
this.target.setThreadNamePrefix(this.beanName + "-");
}
this.target.afterPropertiesSet();
}
private void determinePoolSizeRange(BeanWrapper bw) {
private void determinePoolSizeRange() {
if (StringUtils.hasText(this.poolSize)) {
try {
int corePoolSize;
......@@ -108,15 +105,15 @@ public class TaskExecutorFactoryBean implements
"Lower bound of pool-size range must not exceed the upper bound");
}
if (this.queueCapacity == null) {
// no queue-capacity provided, so unbounded
// No queue-capacity provided, so unbounded
if (corePoolSize == 0) {
// actually set 'corePoolSize' to the upper bound of the range
// but allow core threads to timeout
bw.setPropertyValue("allowCoreThreadTimeOut", true);
// Actually set 'corePoolSize' to the upper bound of the range
// but allow core threads to timeout...
this.target.setAllowCoreThreadTimeOut(true);
corePoolSize = maxPoolSize;
}
else {
// non-zero lower bound implies a core-max size range
// Non-zero lower bound implies a core-max size range...
throw new IllegalArgumentException(
"A non-zero lower bound for the size range requires a queue-capacity value");
}
......@@ -127,8 +124,8 @@ public class TaskExecutorFactoryBean implements
corePoolSize = value;
maxPoolSize = value;
}
bw.setPropertyValue("corePoolSize", corePoolSize);
bw.setPropertyValue("maxPoolSize", maxPoolSize);
this.target.setCorePoolSize(corePoolSize);
this.target.setMaxPoolSize(maxPoolSize);
}
catch (NumberFormatException ex) {
throw new IllegalArgumentException("Invalid pool-size value [" + this.poolSize + "]: only single " +
......@@ -155,10 +152,8 @@ public class TaskExecutorFactoryBean implements
@Override
public void destroy() throws Exception {
if (this.target instanceof DisposableBean) {
((DisposableBean) this.target).destroy();
}
public void destroy() {
this.target.destroy();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册