Skip to content

Commit 1e491f1

Browse files
committed
Polishing
(cherry picked from commit 8c139ef)
1 parent 68cdd5d commit 1e491f1

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

spring-context/src/main/java/org/springframework/scheduling/config/TriggerTask.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,8 +19,8 @@
1919
import org.springframework.scheduling.Trigger;
2020

2121
/**
22-
* {@link Task} implementation defining a {@code Runnable} to be executed according to a
23-
* given {@link Trigger}.
22+
* {@link Task} implementation defining a {@code Runnable} to be executed
23+
* according to a given {@link Trigger}.
2424
*
2525
* @author Chris Beams
2626
* @since 3.2
@@ -45,6 +45,7 @@ public TriggerTask(Runnable runnable, Trigger trigger) {
4545

4646

4747
public Trigger getTrigger() {
48-
return trigger;
48+
return this.trigger;
4949
}
50+
5051
}

spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -198,8 +198,8 @@ public Object postProcessAfterInitialization(final Object bean, String beanName)
198198
new MethodIntrospector.MetadataLookup<Set<JmsListener>>() {
199199
@Override
200200
public Set<JmsListener> inspect(Method method) {
201-
Set<JmsListener> listenerMethods =
202-
AnnotationUtils.getRepeatableAnnotations(method, JmsListener.class, JmsListeners.class);
201+
Set<JmsListener> listenerMethods = AnnotationUtils.getRepeatableAnnotations(
202+
method, JmsListener.class, JmsListeners.class);
203203
return (!listenerMethods.isEmpty() ? listenerMethods : null);
204204
}
205205
});
@@ -293,15 +293,9 @@ private String getEndpointId(JmsListener jmsListener) {
293293
}
294294
}
295295

296-
/**
297-
* Resolve the specified value if possible.
298-
* @see ConfigurableBeanFactory#resolveEmbeddedValue
299-
*/
300296
private String resolve(String value) {
301-
if (this.beanFactory instanceof ConfigurableBeanFactory) {
302-
return ((ConfigurableBeanFactory) this.beanFactory).resolveEmbeddedValue(value);
303-
}
304-
return value;
297+
return (this.beanFactory instanceof ConfigurableBeanFactory ?
298+
((ConfigurableBeanFactory) this.beanFactory).resolveEmbeddedValue(value) : value);
305299
}
306300

307301

spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistrar.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -136,7 +136,7 @@ protected void registerAllEndpoints() {
136136
this.endpointRegistry.registerListenerContainer(
137137
descriptor.endpoint, resolveContainerFactory(descriptor));
138138
}
139-
startImmediately = true; // trigger immediate startup
139+
this.startImmediately = true; // trigger immediate startup
140140
}
141141
}
142142

@@ -149,9 +149,10 @@ else if (this.containerFactory != null) {
149149
}
150150
else if (this.containerFactoryBeanName != null) {
151151
Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
152+
// Consider changing this if live change of the factory is required...
152153
this.containerFactory = this.beanFactory.getBean(
153154
this.containerFactoryBeanName, JmsListenerContainerFactory.class);
154-
return this.containerFactory; // Consider changing this if live change of the factory is required
155+
return this.containerFactory;
155156
}
156157
else {
157158
throw new IllegalStateException("Could not resolve the " +
@@ -169,10 +170,12 @@ else if (this.containerFactoryBeanName != null) {
169170
public void registerEndpoint(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory) {
170171
Assert.notNull(endpoint, "Endpoint must be set");
171172
Assert.hasText(endpoint.getId(), "Endpoint id must be set");
173+
172174
// Factory may be null, we defer the resolution right before actually creating the container
173175
JmsListenerEndpointDescriptor descriptor = new JmsListenerEndpointDescriptor(endpoint, factory);
176+
174177
synchronized (this.mutex) {
175-
if (startImmediately) { // Register and start immediately
178+
if (this.startImmediately) { // register and start immediately
176179
this.endpointRegistry.registerListenerContainer(descriptor.endpoint,
177180
resolveContainerFactory(descriptor), true);
178181
}

src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020

2121
import org.junit.Before;
2222
import org.junit.Test;
23+
2324
import org.springframework.aop.support.AopUtils;
2425
import org.springframework.beans.factory.BeanCreationException;
2526
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -55,13 +56,14 @@ public void setUp() {
5556
Assume.group(TestGroup.PERFORMANCE);
5657
}
5758

59+
5860
@Test
5961
public void failsWhenJdkProxyAndScheduledMethodNotPresentOnInterface() {
6062
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
6163
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigA.class);
6264
try {
6365
ctx.refresh();
64-
fail("expected exception");
66+
fail("Should have thrown BeanCreationException");
6567
}
6668
catch (BeanCreationException ex) {
6769
assertTrue(ex.getRootCause().getMessage().startsWith("@Scheduled method 'scheduled' found"));
@@ -101,28 +103,36 @@ public void succeedsWhenJdkProxyAndScheduledMethodIsPresentOnInterface() throws
101103

102104
@Configuration
103105
@EnableTransactionManagement
104-
static class JdkProxyTxConfig { }
106+
static class JdkProxyTxConfig {
107+
}
108+
105109

106110
@Configuration
107111
@EnableTransactionManagement(proxyTargetClass=true)
108-
static class SubclassProxyTxConfig { }
112+
static class SubclassProxyTxConfig {
113+
}
114+
109115

110116
@Configuration
111117
static class RepoConfigA {
118+
112119
@Bean
113120
public MyRepository repository() {
114121
return new MyRepositoryImpl();
115122
}
116123
}
117124

125+
118126
@Configuration
119127
static class RepoConfigB {
128+
120129
@Bean
121130
public MyRepositoryWithScheduledMethod repository() {
122131
return new MyRepositoryWithScheduledMethodImpl();
123132
}
124133
}
125134

135+
126136
@Configuration
127137
@EnableScheduling
128138
static class Config {
@@ -139,15 +149,17 @@ public PlatformTransactionManager txManager() {
139149

140150
@Bean
141151
public PersistenceExceptionTranslator peTranslator() {
142-
PersistenceExceptionTranslator txlator = mock(PersistenceExceptionTranslator.class);
143-
return txlator;
152+
return mock(PersistenceExceptionTranslator.class);
144153
}
145154
}
146155

156+
147157
public interface MyRepository {
158+
148159
int getInvocationCount();
149160
}
150161

162+
151163
@Repository
152164
static class MyRepositoryImpl implements MyRepository {
153165

@@ -165,11 +177,15 @@ public int getInvocationCount() {
165177
}
166178
}
167179

180+
168181
public interface MyRepositoryWithScheduledMethod {
182+
169183
int getInvocationCount();
170-
public void scheduled();
184+
185+
void scheduled();
171186
}
172187

188+
173189
@Repository
174190
static class MyRepositoryWithScheduledMethodImpl implements MyRepositoryWithScheduledMethod {
175191

0 commit comments

Comments
 (0)