Skip to content

Commit 5bd4f88

Browse files
committed
Polishing
1 parent b16a322 commit 5bd4f88

File tree

9 files changed

+73
-69
lines changed

9 files changed

+73
-69
lines changed

Diff for: spring-context/src/main/java/org/springframework/context/Lifecycle.java

+12-10
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)

Diff for: spring-context/src/main/java/org/springframework/context/SmartLifecycle.java

+22-22
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

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ private void stopBeans() {
187187
Map<Integer, LifecycleGroup> phases = new HashMap<Integer, LifecycleGroup>();
188188
for (Map.Entry<String, Lifecycle> entry : lifecycleBeans.entrySet()) {
189189
Lifecycle bean = entry.getValue();
190-
int shutdownOrder = getPhase(bean);
191-
LifecycleGroup group = phases.get(shutdownOrder);
190+
int shutdownPhase = getPhase(bean);
191+
LifecycleGroup group = phases.get(shutdownPhase);
192192
if (group == null) {
193-
group = new LifecycleGroup(shutdownOrder, this.timeoutPerShutdownPhase, lifecycleBeans, false);
194-
phases.put(shutdownOrder, group);
193+
group = new LifecycleGroup(shutdownPhase, this.timeoutPerShutdownPhase, lifecycleBeans, false);
194+
phases.put(shutdownPhase, group);
195195
}
196196
group.add(entry.getKey(), bean);
197197
}
@@ -291,11 +291,11 @@ protected Map<String, Lifecycle> getLifecycleBeans() {
291291

292292
/**
293293
* Determine the lifecycle phase of the given bean.
294-
* <p>The default implementation checks for the {@link Phased} interface.
295-
* Can be overridden to apply other/further policies.
294+
* <p>The default implementation checks for the {@link Phased} interface, using
295+
* a default of 0 otherwise. Can be overridden to apply other/further policies.
296296
* @param bean the bean to introspect
297-
* @return the phase an integer value. The suggested default is 0.
298-
* @see Phased
297+
* @return the phase (an integer value)
298+
* @see Phased#getPhase()
299299
* @see SmartLifecycle
300300
*/
301301
protected int getPhase(Lifecycle bean) {
@@ -402,9 +402,9 @@ private class LifecycleGroupMember implements Comparable<LifecycleGroupMember> {
402402

403403
@Override
404404
public int compareTo(LifecycleGroupMember other) {
405-
int thisOrder = getPhase(this.bean);
406-
int otherOrder = getPhase(other.bean);
407-
return (thisOrder == otherOrder ? 0 : (thisOrder < otherOrder) ? -1 : 1);
405+
int thisPhase = getPhase(this.bean);
406+
int otherPhase = getPhase(other.bean);
407+
return (thisPhase == otherPhase ? 0 : (thisPhase < otherPhase) ? -1 : 1);
408408
}
409409
}
410410

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

+7-7
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.
@@ -100,8 +100,8 @@ public MessageListenerContainer getListenerContainer(String id) {
100100

101101
/**
102102
* Return the ids of the managed {@link MessageListenerContainer} instance(s).
103-
* @see #getListenerContainer(String)
104103
* @since 4.2.3
104+
* @see #getListenerContainer(String)
105105
*/
106106
public Set<String> getListenerContainerIds() {
107107
return Collections.unmodifiableSet(this.listenerContainers.keySet());
@@ -131,9 +131,9 @@ public void registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerC
131131

132132
Assert.notNull(endpoint, "Endpoint must not be null");
133133
Assert.notNull(factory, "Factory must not be null");
134-
135134
String id = endpoint.getId();
136135
Assert.notNull(id, "Endpoint id must not be null");
136+
137137
synchronized (this.listenerContainers) {
138138
if (this.listenerContainers.containsKey(id)) {
139139
throw new IllegalStateException("Another endpoint is already registered with id '" + id + "'");
@@ -191,13 +191,13 @@ protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint e
191191
// Delegating implementation of SmartLifecycle
192192

193193
@Override
194-
public int getPhase() {
195-
return this.phase;
194+
public boolean isAutoStartup() {
195+
return true;
196196
}
197197

198198
@Override
199-
public boolean isAutoStartup() {
200-
return true;
199+
public int getPhase() {
200+
return this.phase;
201201
}
202202

203203
@Override

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

+1-1
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
*/

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ public MessageHeaderInitializer getHeaderInitializer() {
143143

144144

145145
@Override
146-
public int getPhase() {
147-
return Integer.MAX_VALUE;
146+
public boolean isAutoStartup() {
147+
return true;
148148
}
149149

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

155155
@Override

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,11 @@ public ModelAndView resolveException(
131131
prepareResponse(ex, response);
132132
ModelAndView result = doResolveException(request, response, handler, ex);
133133
if (result != null) {
134-
135-
// Print warn message, when warn logger is not enabled..
134+
// Print warn message when warn logger is not enabled...
136135
if (logger.isWarnEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
137136
logger.warn("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
138137
}
139-
140-
// warnLogger with full stack trace (requires explicit config)..
138+
// warnLogger with full stack trace (requires explicit config)
141139
logException(ex, request);
142140
}
143141
return result;
@@ -200,7 +198,7 @@ protected void logException(Exception ex, HttpServletRequest request) {
200198
* @return the log message to use
201199
*/
202200
protected String buildLogMessage(Exception ex, HttpServletRequest request) {
203-
return "Resolved exception caused by Handler execution: " + ex;
201+
return "Resolved exception caused by handler execution: " + ex;
204202
}
205203

206204
/**

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ public boolean isRunning() {
211211
* when connected on the STOMP level after the CONNECTED frame is received.
212212
* @param url the url to connect to
213213
* @param handler the session handler
214-
* @param uriVars URI variables to expand into the URL
215-
* @return ListenableFuture for access to the session when ready for use
214+
* @param uriVars the URI variables to expand into the URL
215+
* @return a ListenableFuture for access to the session when ready for use
216216
*/
217217
public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) {
218218
return connect(url, null, handler, uriVars);
@@ -225,8 +225,8 @@ public ListenableFuture<StompSession> connect(String url, StompSessionHandler ha
225225
* @param url the url to connect to
226226
* @param handshakeHeaders the headers for the WebSocket handshake
227227
* @param handler the session handler
228-
* @param uriVariables URI variables to expand into the URL
229-
* @return ListenableFuture for access to the session when ready for use
228+
* @param uriVariables the URI variables to expand into the URL
229+
* @return a ListenableFuture for access to the session when ready for use
230230
*/
231231
public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders handshakeHeaders,
232232
StompSessionHandler handler, Object... uriVariables) {
@@ -243,8 +243,8 @@ public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders h
243243
* @param handshakeHeaders headers for the WebSocket handshake
244244
* @param connectHeaders headers for the STOMP CONNECT frame
245245
* @param handler the session handler
246-
* @param uriVariables URI variables to expand into the URL
247-
* @return ListenableFuture for access to the session when ready for use
246+
* @param uriVariables the URI variables to expand into the URL
247+
* @return a ListenableFuture for access to the session when ready for use
248248
*/
249249
public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders handshakeHeaders,
250250
StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {
@@ -262,7 +262,7 @@ public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders h
262262
* @param handshakeHeaders the headers for the WebSocket handshake
263263
* @param connectHeaders headers for the STOMP CONNECT frame
264264
* @param sessionHandler the STOMP session handler
265-
* @return ListenableFuture for access to the session when ready for use
265+
* @return a ListenableFuture for access to the session when ready for use
266266
*/
267267
public ListenableFuture<StompSession> connect(URI url, WebSocketHttpHeaders handshakeHeaders,
268268
StompHeaders connectHeaders, StompSessionHandler sessionHandler) {
@@ -392,7 +392,10 @@ public ListenableFuture<Void> send(Message<byte[]> message) {
392392
}
393393

394394
private void updateLastWriteTime() {
395-
this.lastWriteTime = (this.lastWriteTime != -1 ? System.currentTimeMillis() : -1);
395+
long lastWriteTime = this.lastWriteTime;
396+
if (lastWriteTime != -1) {
397+
this.lastWriteTime = System.currentTimeMillis();
398+
}
396399
}
397400

398401
@Override

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

+2-1
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)