Skip to content

Commit f532de5

Browse files
committed
Polishing
1 parent 6b3dd07 commit f532de5

File tree

10 files changed

+87
-85
lines changed

10 files changed

+87
-85
lines changed

spring-beans/spring-beans.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ dependencies {
1212
testCompile("org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}")
1313
}
1414

15-
// This modules does joint compilation for Java and Groovy code,
16-
// with the compileGroovy task.
15+
// This module does joint compilation for Java and Groovy code with the compileGroovy task.
1716
sourceSets {
1817
main.groovy.srcDirs += "src/main/java"
1918
main.java.srcDirs = []
@@ -24,9 +23,8 @@ compileGroovy {
2423
targetCompatibility = 1.8
2524
}
2625

27-
// This module also builds Kotlin code and the compileKotlin task
28-
// naturally depends on compileJava.
29-
// We need to redefine dependencies to break task cycles.
26+
// This module also builds Kotlin code and the compileKotlin task naturally depends on
27+
// compileJava. We need to redefine dependencies to break task cycles.
3028
compileGroovy.dependsOn = compileGroovy.taskDependencies.values - 'compileJava'
3129
compileKotlin.dependsOn(compileGroovy)
3230
compileKotlin.classpath += files(compileGroovy.destinationDir)

spring-context/src/main/java/org/springframework/context/Lifecycle.java

Lines changed: 12 additions & 10 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-2018 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.
@@ -34,10 +34,11 @@
3434
* restricting the visibility of activity-controlled components to the Lifecycle
3535
* interface.
3636
*
37-
* <p>Note that the Lifecycle interface is only supported on <b>top-level singleton
38-
* beans</b>. On any other component, the Lifecycle interface will remain undetected
39-
* and hence ignored. Also, note that the extended {@link SmartLifecycle} interface
40-
* provides integration with the application context's startup and shutdown phases.
37+
* <p>Note that the present {@code Lifecycle} interface is only supported on
38+
* <b>top-level singleton beans</b>. On any other component, the {@code Lifecycle}
39+
* interface will remain undetected and hence ignored. Also, note that the extended
40+
* {@link SmartLifecycle} interface provides sophisticated integration with the
41+
* application context's startup and shutdown phases.
4142
*
4243
* @author Juergen Hoeller
4344
* @since 2.0
@@ -61,11 +62,12 @@ public interface Lifecycle {
6162
* Stop this component, typically in a synchronous fashion, such that the component is
6263
* fully stopped upon return of this method. Consider implementing {@link SmartLifecycle}
6364
* and its {@code stop(Runnable)} variant when asynchronous stop behavior is necessary.
64-
* <p>Note that this stop notification is not guaranteed to come before destruction: On
65-
* regular shutdown, {@code Lifecycle} beans will first receive a stop notification before
66-
* the general destruction callbacks are being propagated; however, on hot refresh during a
67-
* context's lifetime or on aborted refresh attempts, only destroy methods will be called.
68-
* <p>Should not throw an exception if the component isn't started yet.
65+
* <p>Note that this stop notification is not guaranteed to come before destruction:
66+
* On regular shutdown, {@code Lifecycle} beans will first receive a stop notification
67+
* before the general destruction callbacks are being propagated; however, on hot
68+
* refresh during a context's lifetime or on aborted refresh attempts, a given bean's
69+
* destroy method will be called without any consideration of stop signals upfront.
70+
* <p>Should not throw an exception if the component is not running (not started yet).
6971
* <p>In the case of a container, this will propagate the stop signal to all components
7072
* that apply.
7173
* @see SmartLifecycle#stop(Runnable)

spring-context/src/main/java/org/springframework/context/SmartLifecycle.java

Lines changed: 22 additions & 22 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-2018 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.
@@ -23,35 +23,35 @@
2323
* be started at the time of a context refresh. The callback-accepting
2424
* {@link #stop(Runnable)} method is useful for objects that have an asynchronous
2525
* shutdown process. Any implementation of this interface <i>must</i> invoke the
26-
* callback's run() method upon shutdown completion to avoid unnecessary delays
27-
* in the overall ApplicationContext shutdown.
26+
* callback's {@code run()} method upon shutdown completion to avoid unnecessary
27+
* delays in the overall ApplicationContext shutdown.
2828
*
2929
* <p>This interface extends {@link Phased}, and the {@link #getPhase()} method's
3030
* return value indicates the phase within which this Lifecycle component should
31-
* be started and stopped. The startup process begins with the <i>lowest</i>
32-
* phase value and ends with the <i>highest</i> phase value (Integer.MIN_VALUE
33-
* is the lowest possible, and Integer.MAX_VALUE is the highest possible). The
34-
* shutdown process will apply the reverse order. Any components with the
31+
* be started and stopped. The startup process begins with the <i>lowest</i> phase
32+
* value and ends with the <i>highest</i> phase value ({@code Integer.MIN_VALUE}
33+
* is the lowest possible, and {@code Integer.MAX_VALUE} is the highest possible).
34+
* The shutdown process will apply the reverse order. Any components with the
3535
* same value will be arbitrarily ordered within the same phase.
3636
*
37-
* <p>Example: if component B depends on component A having already started, then
38-
* component A should have a lower phase value than component B. During the
39-
* shutdown process, component B would be stopped before component A.
37+
* <p>Example: if component B depends on component A having already started,
38+
* then component A should have a lower phase value than component B. During
39+
* the shutdown process, component B would be stopped before component A.
4040
*
41-
* <p>Any explicit "depends-on" relationship will take precedence over
42-
* the phase order such that the dependent bean always starts after its
43-
* dependency and always stops before its dependency.
41+
* <p>Any explicit "depends-on" relationship will take precedence over the phase
42+
* order such that the dependent bean always starts after its dependency and
43+
* always stops before its dependency.
4444
*
45-
* <p>Any Lifecycle components within the context that do not also implement
46-
* SmartLifecycle will be treated as if they have a phase value of 0. That
47-
* way a SmartLifecycle implementation may start before those Lifecycle
48-
* components if it has a negative phase value, or it may start after
49-
* those components if it has a positive phase value.
45+
* <p>Any {@code Lifecycle} components within the context that do not also
46+
* implement {@code SmartLifecycle} will be treated as if they have a phase
47+
* value of 0. That way a {@code SmartLifecycle} implementation may start
48+
* before those {@code Lifecycle} components if it has a negative phase value,
49+
* or it may start after those components if it has a positive phase value.
5050
*
51-
* <p>Note that, due to the auto-startup support in SmartLifecycle,
52-
* a SmartLifecycle bean instance will get initialized on startup of the
53-
* application context in any case. As a consequence, the bean definition
54-
* lazy-init flag has very limited actual effect on SmartLifecycle beans.
51+
* <p>Note that, due to the auto-startup support in {@code SmartLifecycle}, a
52+
* {@code SmartLifecycle} bean instance will usually get initialized on startup
53+
* of the application context in any case. As a consequence, the bean definition
54+
* lazy-init flag has very limited actual effect on {@code SmartLifecycle} beans.
5555
*
5656
* @author Mark Fisher
5757
* @since 3.0

spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ private void stopBeans() {
195195
Map<String, Lifecycle> lifecycleBeans = getLifecycleBeans();
196196
Map<Integer, LifecycleGroup> phases = new HashMap<>();
197197
lifecycleBeans.forEach((beanName, bean) -> {
198-
int shutdownOrder = getPhase(bean);
199-
LifecycleGroup group = phases.get(shutdownOrder);
198+
int shutdownPhase = getPhase(bean);
199+
LifecycleGroup group = phases.get(shutdownPhase);
200200
if (group == null) {
201-
group = new LifecycleGroup(shutdownOrder, this.timeoutPerShutdownPhase, lifecycleBeans, false);
202-
phases.put(shutdownOrder, group);
201+
group = new LifecycleGroup(shutdownPhase, this.timeoutPerShutdownPhase, lifecycleBeans, false);
202+
phases.put(shutdownPhase, group);
203203
}
204204
group.add(beanName, bean);
205205
});
@@ -302,11 +302,11 @@ private boolean matchesBeanType(Class<?> targetType, String beanName, BeanFactor
302302

303303
/**
304304
* Determine the lifecycle phase of the given bean.
305-
* <p>The default implementation checks for the {@link Phased} interface.
306-
* Can be overridden to apply other/further policies.
305+
* <p>The default implementation checks for the {@link Phased} interface, using
306+
* a default of 0 otherwise. Can be overridden to apply other/further policies.
307307
* @param bean the bean to introspect
308-
* @return the phase an integer value. The suggested default is 0.
309-
* @see Phased
308+
* @return the phase (an integer value)
309+
* @see Phased#getPhase()
310310
* @see SmartLifecycle
311311
*/
312312
protected int getPhase(Lifecycle bean) {
@@ -412,9 +412,9 @@ private class LifecycleGroupMember implements Comparable<LifecycleGroupMember> {
412412

413413
@Override
414414
public int compareTo(LifecycleGroupMember other) {
415-
int thisOrder = getPhase(this.bean);
416-
int otherOrder = getPhase(other.bean);
417-
return Integer.compare(thisOrder, otherOrder);
415+
int thisPhase = getPhase(this.bean);
416+
int otherPhase = getPhase(other.bean);
417+
return Integer.compare(thisPhase, otherPhase);
418418
}
419419
}
420420

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -103,8 +103,8 @@ public MessageListenerContainer getListenerContainer(String id) {
103103

104104
/**
105105
* Return the ids of the managed {@link MessageListenerContainer} instance(s).
106-
* @see #getListenerContainer(String)
107106
* @since 4.2.3
107+
* @see #getListenerContainer(String)
108108
*/
109109
public Set<String> getListenerContainerIds() {
110110
return Collections.unmodifiableSet(this.listenerContainers.keySet());
@@ -194,13 +194,13 @@ protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint e
194194
// Delegating implementation of SmartLifecycle
195195

196196
@Override
197-
public int getPhase() {
198-
return this.phase;
197+
public boolean isAutoStartup() {
198+
return true;
199199
}
200200

201201
@Override
202-
public boolean isAutoStartup() {
203-
return true;
202+
public int getPhase() {
203+
return this.phase;
204204
}
205205

206206
@Override

spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public Validator getValidator() {
231231
}
232232

233233
/**
234-
* Set the Validator instance used for validating @Payload arguments
234+
* Set the Validator instance used for validating {@code @Payload} arguments.
235235
* @see org.springframework.validation.annotation.Validated
236236
* @see PayloadArgumentResolver
237237
*/

spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ public MessageHeaderInitializer getHeaderInitializer() {
148148

149149

150150
@Override
151-
public int getPhase() {
152-
return Integer.MAX_VALUE;
151+
public boolean isAutoStartup() {
152+
return true;
153153
}
154154

155155
@Override
156-
public boolean isAutoStartup() {
157-
return true;
156+
public int getPhase() {
157+
return Integer.MAX_VALUE;
158158
}
159159

160160
@Override

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,11 @@ public ModelAndView resolveException(
135135
prepareResponse(ex, response);
136136
ModelAndView result = doResolveException(request, response, handler, ex);
137137
if (result != null) {
138-
139-
// Print warn message, when warn logger is not enabled..
138+
// Print warn message when warn logger is not enabled...
140139
if (logger.isWarnEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
141140
logger.warn("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
142141
}
143-
144-
// warnLogger with full stack trace (requires explicit config)..
142+
// warnLogger with full stack trace (requires explicit config)
145143
logException(ex, request);
146144
}
147145
return result;
@@ -204,7 +202,7 @@ protected void logException(Exception ex, HttpServletRequest request) {
204202
* @return the log message to use
205203
*/
206204
protected String buildLogMessage(Exception ex, HttpServletRequest request) {
207-
return "Resolved exception caused by Handler execution: " + ex;
205+
return "Resolved exception caused by handler execution: " + ex;
208206
}
209207

210208
/**

spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ public boolean isRunning() {
212212
* when connected on the STOMP level after the CONNECTED frame is received.
213213
* @param url the url to connect to
214214
* @param handler the session handler
215-
* @param uriVars URI variables to expand into the URL
216-
* @return ListenableFuture for access to the session when ready for use
215+
* @param uriVars the URI variables to expand into the URL
216+
* @return a ListenableFuture for access to the session when ready for use
217217
*/
218218
public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) {
219219
return connect(url, null, handler, uriVars);
@@ -226,8 +226,8 @@ public ListenableFuture<StompSession> connect(String url, StompSessionHandler ha
226226
* @param url the url to connect to
227227
* @param handshakeHeaders the headers for the WebSocket handshake
228228
* @param handler the session handler
229-
* @param uriVariables URI variables to expand into the URL
230-
* @return ListenableFuture for access to the session when ready for use
229+
* @param uriVariables the URI variables to expand into the URL
230+
* @return a ListenableFuture for access to the session when ready for use
231231
*/
232232
public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
233233
StompSessionHandler handler, Object... uriVariables) {
@@ -244,8 +244,8 @@ public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHtt
244244
* @param handshakeHeaders headers for the WebSocket handshake
245245
* @param connectHeaders headers for the STOMP CONNECT frame
246246
* @param handler the session handler
247-
* @param uriVariables URI variables to expand into the URL
248-
* @return ListenableFuture for access to the session when ready for use
247+
* @param uriVariables the URI variables to expand into the URL
248+
* @return a ListenableFuture for access to the session when ready for use
249249
*/
250250
public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
251251
@Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {
@@ -263,7 +263,7 @@ public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHtt
263263
* @param handshakeHeaders the headers for the WebSocket handshake
264264
* @param connectHeaders headers for the STOMP CONNECT frame
265265
* @param sessionHandler the STOMP session handler
266-
* @return ListenableFuture for access to the session when ready for use
266+
* @return a ListenableFuture for access to the session when ready for use
267267
*/
268268
public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders,
269269
@Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) {
@@ -396,15 +396,18 @@ public ListenableFuture<Void> send(Message<byte[]> message) {
396396
}
397397

398398
private void updateLastWriteTime() {
399-
this.lastWriteTime = (this.lastWriteTime != -1 ? System.currentTimeMillis() : -1);
399+
long lastWriteTime = this.lastWriteTime;
400+
if (lastWriteTime != -1) {
401+
this.lastWriteTime = System.currentTimeMillis();
402+
}
400403
}
401404

402405
@Override
403406
public void onReadInactivity(final Runnable runnable, final long duration) {
404407
Assert.state(getTaskScheduler() != null, "No TaskScheduler configured");
405408
this.lastReadTime = System.currentTimeMillis();
406409
this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> {
407-
if (System.currentTimeMillis() - lastReadTime > duration) {
410+
if (System.currentTimeMillis() - this.lastReadTime > duration) {
408411
try {
409412
runnable.run();
410413
}
@@ -422,17 +425,17 @@ public void onWriteInactivity(final Runnable runnable, final long duration) {
422425
Assert.state(getTaskScheduler() != null, "No TaskScheduler configured");
423426
this.lastWriteTime = System.currentTimeMillis();
424427
this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> {
425-
if (System.currentTimeMillis() - lastWriteTime > duration) {
426-
try {
427-
runnable.run();
428-
}
429-
catch (Throwable ex) {
430-
if (logger.isDebugEnabled()) {
431-
logger.debug("WriteInactivityTask failure", ex);
432-
}
433-
}
434-
}
435-
}, duration / 2));
428+
if (System.currentTimeMillis() - this.lastWriteTime > duration) {
429+
try {
430+
runnable.run();
431+
}
432+
catch (Throwable ex) {
433+
if (logger.isDebugEnabled()) {
434+
logger.debug("WriteInactivityTask failure", ex);
435+
}
436+
}
437+
}
438+
}, duration / 2));
436439
}
437440

438441
@Override

spring-websocket/src/main/java/org/springframework/web/socket/server/support/WebSocketHandlerMapping.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -46,6 +46,7 @@ protected void initServletContext(ServletContext servletContext) {
4646
}
4747
}
4848

49+
4950
@Override
5051
public boolean isAutoStartup() {
5152
return true;

0 commit comments

Comments
 (0)