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