Polishing
This commit is contained in:
@@ -12,8 +12,7 @@ dependencies {
|
||||
testCompile("org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}")
|
||||
}
|
||||
|
||||
// This modules does joint compilation for Java and Groovy code,
|
||||
// with the compileGroovy task.
|
||||
// This module does joint compilation for Java and Groovy code with the compileGroovy task.
|
||||
sourceSets {
|
||||
main.groovy.srcDirs += "src/main/java"
|
||||
main.java.srcDirs = []
|
||||
@@ -24,9 +23,8 @@ compileGroovy {
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
|
||||
// This module also builds Kotlin code and the compileKotlin task
|
||||
// naturally depends on compileJava.
|
||||
// We need to redefine dependencies to break task cycles.
|
||||
// This module also builds Kotlin code and the compileKotlin task naturally depends on
|
||||
// compileJava. We need to redefine dependencies to break task cycles.
|
||||
compileGroovy.dependsOn = compileGroovy.taskDependencies.values - 'compileJava'
|
||||
compileKotlin.dependsOn(compileGroovy)
|
||||
compileKotlin.classpath += files(compileGroovy.destinationDir)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -34,10 +34,11 @@ package org.springframework.context;
|
||||
* restricting the visibility of activity-controlled components to the Lifecycle
|
||||
* interface.
|
||||
*
|
||||
* <p>Note that the Lifecycle interface is only supported on <b>top-level singleton
|
||||
* beans</b>. On any other component, the Lifecycle interface will remain undetected
|
||||
* and hence ignored. Also, note that the extended {@link SmartLifecycle} interface
|
||||
* provides integration with the application context's startup and shutdown phases.
|
||||
* <p>Note that the present {@code Lifecycle} interface is only supported on
|
||||
* <b>top-level singleton beans</b>. On any other component, the {@code Lifecycle}
|
||||
* interface will remain undetected and hence ignored. Also, note that the extended
|
||||
* {@link SmartLifecycle} interface provides sophisticated integration with the
|
||||
* application context's startup and shutdown phases.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
@@ -61,11 +62,12 @@ public interface Lifecycle {
|
||||
* Stop this component, typically in a synchronous fashion, such that the component is
|
||||
* fully stopped upon return of this method. Consider implementing {@link SmartLifecycle}
|
||||
* and its {@code stop(Runnable)} variant when asynchronous stop behavior is necessary.
|
||||
* <p>Note that this stop notification is not guaranteed to come before destruction: On
|
||||
* regular shutdown, {@code Lifecycle} beans will first receive a stop notification before
|
||||
* the general destruction callbacks are being propagated; however, on hot refresh during a
|
||||
* context's lifetime or on aborted refresh attempts, only destroy methods will be called.
|
||||
* <p>Should not throw an exception if the component isn't started yet.
|
||||
* <p>Note that this stop notification is not guaranteed to come before destruction:
|
||||
* On regular shutdown, {@code Lifecycle} beans will first receive a stop notification
|
||||
* before the general destruction callbacks are being propagated; however, on hot
|
||||
* refresh during a context's lifetime or on aborted refresh attempts, a given bean's
|
||||
* destroy method will be called without any consideration of stop signals upfront.
|
||||
* <p>Should not throw an exception if the component is not running (not started yet).
|
||||
* <p>In the case of a container, this will propagate the stop signal to all components
|
||||
* that apply.
|
||||
* @see SmartLifecycle#stop(Runnable)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -23,35 +23,35 @@ package org.springframework.context;
|
||||
* be started at the time of a context refresh. The callback-accepting
|
||||
* {@link #stop(Runnable)} method is useful for objects that have an asynchronous
|
||||
* shutdown process. Any implementation of this interface <i>must</i> invoke the
|
||||
* callback's run() method upon shutdown completion to avoid unnecessary delays
|
||||
* in the overall ApplicationContext shutdown.
|
||||
* callback's {@code run()} method upon shutdown completion to avoid unnecessary
|
||||
* delays in the overall ApplicationContext shutdown.
|
||||
*
|
||||
* <p>This interface extends {@link Phased}, and the {@link #getPhase()} method's
|
||||
* return value indicates the phase within which this Lifecycle component should
|
||||
* be started and stopped. The startup process begins with the <i>lowest</i>
|
||||
* phase value and ends with the <i>highest</i> phase value (Integer.MIN_VALUE
|
||||
* is the lowest possible, and Integer.MAX_VALUE is the highest possible). The
|
||||
* shutdown process will apply the reverse order. Any components with the
|
||||
* be started and stopped. The startup process begins with the <i>lowest</i> phase
|
||||
* value and ends with the <i>highest</i> phase value ({@code Integer.MIN_VALUE}
|
||||
* is the lowest possible, and {@code Integer.MAX_VALUE} is the highest possible).
|
||||
* The shutdown process will apply the reverse order. Any components with the
|
||||
* same value will be arbitrarily ordered within the same phase.
|
||||
*
|
||||
* <p>Example: if component B depends on component A having already started, then
|
||||
* component A should have a lower phase value than component B. During the
|
||||
* shutdown process, component B would be stopped before component A.
|
||||
* <p>Example: if component B depends on component A having already started,
|
||||
* then component A should have a lower phase value than component B. During
|
||||
* the shutdown process, component B would be stopped before component A.
|
||||
*
|
||||
* <p>Any explicit "depends-on" relationship will take precedence over
|
||||
* the phase order such that the dependent bean always starts after its
|
||||
* dependency and always stops before its dependency.
|
||||
* <p>Any explicit "depends-on" relationship will take precedence over the phase
|
||||
* order such that the dependent bean always starts after its dependency and
|
||||
* always stops before its dependency.
|
||||
*
|
||||
* <p>Any Lifecycle components within the context that do not also implement
|
||||
* SmartLifecycle will be treated as if they have a phase value of 0. That
|
||||
* way a SmartLifecycle implementation may start before those Lifecycle
|
||||
* components if it has a negative phase value, or it may start after
|
||||
* those components if it has a positive phase value.
|
||||
* <p>Any {@code Lifecycle} components within the context that do not also
|
||||
* implement {@code SmartLifecycle} will be treated as if they have a phase
|
||||
* value of 0. That way a {@code SmartLifecycle} implementation may start
|
||||
* before those {@code Lifecycle} components if it has a negative phase value,
|
||||
* or it may start after those components if it has a positive phase value.
|
||||
*
|
||||
* <p>Note that, due to the auto-startup support in SmartLifecycle,
|
||||
* a SmartLifecycle bean instance will get initialized on startup of the
|
||||
* application context in any case. As a consequence, the bean definition
|
||||
* lazy-init flag has very limited actual effect on SmartLifecycle beans.
|
||||
* <p>Note that, due to the auto-startup support in {@code SmartLifecycle}, a
|
||||
* {@code SmartLifecycle} bean instance will usually get initialized on startup
|
||||
* of the application context in any case. As a consequence, the bean definition
|
||||
* lazy-init flag has very limited actual effect on {@code SmartLifecycle} beans.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 3.0
|
||||
|
||||
@@ -195,11 +195,11 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
Map<String, Lifecycle> lifecycleBeans = getLifecycleBeans();
|
||||
Map<Integer, LifecycleGroup> phases = new HashMap<>();
|
||||
lifecycleBeans.forEach((beanName, bean) -> {
|
||||
int shutdownOrder = getPhase(bean);
|
||||
LifecycleGroup group = phases.get(shutdownOrder);
|
||||
int shutdownPhase = getPhase(bean);
|
||||
LifecycleGroup group = phases.get(shutdownPhase);
|
||||
if (group == null) {
|
||||
group = new LifecycleGroup(shutdownOrder, this.timeoutPerShutdownPhase, lifecycleBeans, false);
|
||||
phases.put(shutdownOrder, group);
|
||||
group = new LifecycleGroup(shutdownPhase, this.timeoutPerShutdownPhase, lifecycleBeans, false);
|
||||
phases.put(shutdownPhase, group);
|
||||
}
|
||||
group.add(beanName, bean);
|
||||
});
|
||||
@@ -302,11 +302,11 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
|
||||
/**
|
||||
* Determine the lifecycle phase of the given bean.
|
||||
* <p>The default implementation checks for the {@link Phased} interface.
|
||||
* Can be overridden to apply other/further policies.
|
||||
* <p>The default implementation checks for the {@link Phased} interface, using
|
||||
* a default of 0 otherwise. Can be overridden to apply other/further policies.
|
||||
* @param bean the bean to introspect
|
||||
* @return the phase an integer value. The suggested default is 0.
|
||||
* @see Phased
|
||||
* @return the phase (an integer value)
|
||||
* @see Phased#getPhase()
|
||||
* @see SmartLifecycle
|
||||
*/
|
||||
protected int getPhase(Lifecycle bean) {
|
||||
@@ -412,9 +412,9 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
|
||||
@Override
|
||||
public int compareTo(LifecycleGroupMember other) {
|
||||
int thisOrder = getPhase(this.bean);
|
||||
int otherOrder = getPhase(other.bean);
|
||||
return Integer.compare(thisOrder, otherOrder);
|
||||
int thisPhase = getPhase(this.bean);
|
||||
int otherPhase = getPhase(other.bean);
|
||||
return Integer.compare(thisPhase, otherPhase);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -103,8 +103,8 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
||||
|
||||
/**
|
||||
* Return the ids of the managed {@link MessageListenerContainer} instance(s).
|
||||
* @see #getListenerContainer(String)
|
||||
* @since 4.2.3
|
||||
* @see #getListenerContainer(String)
|
||||
*/
|
||||
public Set<String> getListenerContainerIds() {
|
||||
return Collections.unmodifiableSet(this.listenerContainers.keySet());
|
||||
@@ -194,13 +194,13 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
||||
// Delegating implementation of SmartLifecycle
|
||||
|
||||
@Override
|
||||
public int getPhase() {
|
||||
return this.phase;
|
||||
public boolean isAutoStartup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoStartup() {
|
||||
return true;
|
||||
public int getPhase() {
|
||||
return this.phase;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -231,7 +231,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Validator instance used for validating @Payload arguments
|
||||
* Set the Validator instance used for validating {@code @Payload} arguments.
|
||||
* @see org.springframework.validation.annotation.Validated
|
||||
* @see PayloadArgumentResolver
|
||||
*/
|
||||
|
||||
@@ -148,13 +148,13 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
|
||||
|
||||
|
||||
@Override
|
||||
public int getPhase() {
|
||||
return Integer.MAX_VALUE;
|
||||
public boolean isAutoStartup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoStartup() {
|
||||
return true;
|
||||
public int getPhase() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -135,13 +135,11 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||
prepareResponse(ex, response);
|
||||
ModelAndView result = doResolveException(request, response, handler, ex);
|
||||
if (result != null) {
|
||||
|
||||
// Print warn message, when warn logger is not enabled..
|
||||
// Print warn message when warn logger is not enabled...
|
||||
if (logger.isWarnEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
|
||||
logger.warn("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
|
||||
}
|
||||
|
||||
// warnLogger with full stack trace (requires explicit config)..
|
||||
// warnLogger with full stack trace (requires explicit config)
|
||||
logException(ex, request);
|
||||
}
|
||||
return result;
|
||||
@@ -204,7 +202,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||
* @return the log message to use
|
||||
*/
|
||||
protected String buildLogMessage(Exception ex, HttpServletRequest request) {
|
||||
return "Resolved exception caused by Handler execution: " + ex;
|
||||
return "Resolved exception caused by handler execution: " + ex;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -212,8 +212,8 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
* when connected on the STOMP level after the CONNECTED frame is received.
|
||||
* @param url the url to connect to
|
||||
* @param handler the session handler
|
||||
* @param uriVars URI variables to expand into the URL
|
||||
* @return ListenableFuture for access to the session when ready for use
|
||||
* @param uriVars the URI variables to expand into the URL
|
||||
* @return a ListenableFuture for access to the session when ready for use
|
||||
*/
|
||||
public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) {
|
||||
return connect(url, null, handler, uriVars);
|
||||
@@ -226,8 +226,8 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
* @param url the url to connect to
|
||||
* @param handshakeHeaders the headers for the WebSocket handshake
|
||||
* @param handler the session handler
|
||||
* @param uriVariables URI variables to expand into the URL
|
||||
* @return ListenableFuture for access to the session when ready for use
|
||||
* @param uriVariables the URI variables to expand into the URL
|
||||
* @return a ListenableFuture for access to the session when ready for use
|
||||
*/
|
||||
public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
|
||||
StompSessionHandler handler, Object... uriVariables) {
|
||||
@@ -244,8 +244,8 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
* @param handshakeHeaders headers for the WebSocket handshake
|
||||
* @param connectHeaders headers for the STOMP CONNECT frame
|
||||
* @param handler the session handler
|
||||
* @param uriVariables URI variables to expand into the URL
|
||||
* @return ListenableFuture for access to the session when ready for use
|
||||
* @param uriVariables the URI variables to expand into the URL
|
||||
* @return a ListenableFuture for access to the session when ready for use
|
||||
*/
|
||||
public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
|
||||
@Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {
|
||||
@@ -263,7 +263,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
* @param handshakeHeaders the headers for the WebSocket handshake
|
||||
* @param connectHeaders headers for the STOMP CONNECT frame
|
||||
* @param sessionHandler the STOMP session handler
|
||||
* @return ListenableFuture for access to the session when ready for use
|
||||
* @return a ListenableFuture for access to the session when ready for use
|
||||
*/
|
||||
public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders,
|
||||
@Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) {
|
||||
@@ -396,7 +396,10 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
}
|
||||
|
||||
private void updateLastWriteTime() {
|
||||
this.lastWriteTime = (this.lastWriteTime != -1 ? System.currentTimeMillis() : -1);
|
||||
long lastWriteTime = this.lastWriteTime;
|
||||
if (lastWriteTime != -1) {
|
||||
this.lastWriteTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -404,7 +407,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
Assert.state(getTaskScheduler() != null, "No TaskScheduler configured");
|
||||
this.lastReadTime = System.currentTimeMillis();
|
||||
this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> {
|
||||
if (System.currentTimeMillis() - lastReadTime > duration) {
|
||||
if (System.currentTimeMillis() - this.lastReadTime > duration) {
|
||||
try {
|
||||
runnable.run();
|
||||
}
|
||||
@@ -422,17 +425,17 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
Assert.state(getTaskScheduler() != null, "No TaskScheduler configured");
|
||||
this.lastWriteTime = System.currentTimeMillis();
|
||||
this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> {
|
||||
if (System.currentTimeMillis() - lastWriteTime > duration) {
|
||||
try {
|
||||
runnable.run();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("WriteInactivityTask failure", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, duration / 2));
|
||||
if (System.currentTimeMillis() - this.lastWriteTime > duration) {
|
||||
try {
|
||||
runnable.run();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("WriteInactivityTask failure", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, duration / 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -46,6 +46,7 @@ public class WebSocketHandlerMapping extends SimpleUrlHandlerMapping implements
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAutoStartup() {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user