Polishing
This commit is contained in:
parent
d554229981
commit
26378cd604
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 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.
|
||||||
|
@ -398,7 +398,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||||
/**
|
/**
|
||||||
* Various reference types supported by this map.
|
* Various reference types supported by this map.
|
||||||
*/
|
*/
|
||||||
public static enum ReferenceType {
|
public enum ReferenceType {
|
||||||
|
|
||||||
/** Use {@link SoftReference}s */
|
/** Use {@link SoftReference}s */
|
||||||
SOFT,
|
SOFT,
|
||||||
|
@ -636,7 +636,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||||
* A reference to an {@link Entry} contained in the map. Implementations are usually
|
* A reference to an {@link Entry} contained in the map. Implementations are usually
|
||||||
* wrappers around specific Java reference implementations (e.g., {@link SoftReference}).
|
* wrappers around specific Java reference implementations (e.g., {@link SoftReference}).
|
||||||
*/
|
*/
|
||||||
protected static interface Reference<K, V> {
|
protected interface Reference<K, V> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the referenced entry or {@code null} if the entry is no longer
|
* Returns the referenced entry or {@code null} if the entry is no longer
|
||||||
|
@ -765,7 +765,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||||
/**
|
/**
|
||||||
* Various options supported by a {@code Task}.
|
* Various options supported by a {@code Task}.
|
||||||
*/
|
*/
|
||||||
private static enum TaskOption {
|
private enum TaskOption {
|
||||||
|
|
||||||
RESTRUCTURE_BEFORE, RESTRUCTURE_AFTER, SKIP_IF_EMPTY, RESIZE
|
RESTRUCTURE_BEFORE, RESTRUCTURE_AFTER, SKIP_IF_EMPTY, RESIZE
|
||||||
}
|
}
|
||||||
|
@ -912,7 +912,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||||
/**
|
/**
|
||||||
* The types of restructuring that can be performed.
|
* The types of restructuring that can be performed.
|
||||||
*/
|
*/
|
||||||
protected static enum Restructure {
|
protected enum Restructure {
|
||||||
|
|
||||||
WHEN_NECESSARY, NEVER
|
WHEN_NECESSARY, NEVER
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.BeanInitializationException;
|
import org.springframework.beans.factory.BeanInitializationException;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
@ -72,11 +71,19 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
||||||
|
|
||||||
private boolean contextRefreshed;
|
private boolean contextRefreshed;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||||
|
if (event.getApplicationContext() == this.applicationContext) {
|
||||||
|
this.contextRefreshed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link MessageListenerContainer} with the specified id or
|
* Return the {@link MessageListenerContainer} with the specified id or
|
||||||
|
@ -107,7 +114,6 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
||||||
return Collections.unmodifiableCollection(this.listenerContainers.values());
|
return Collections.unmodifiableCollection(this.listenerContainers.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a message listener container for the given {@link JmsListenerEndpoint}.
|
* Create a message listener container for the given {@link JmsListenerEndpoint}.
|
||||||
* <p>This create the necessary infrastructure to honor that endpoint
|
* <p>This create the necessary infrastructure to honor that endpoint
|
||||||
|
@ -129,8 +135,9 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
||||||
String id = endpoint.getId();
|
String id = endpoint.getId();
|
||||||
Assert.notNull(id, "Endpoint id must not be null");
|
Assert.notNull(id, "Endpoint id must not be null");
|
||||||
synchronized (this.listenerContainers) {
|
synchronized (this.listenerContainers) {
|
||||||
Assert.state(!this.listenerContainers.containsKey(id),
|
if (this.listenerContainers.containsKey(id)) {
|
||||||
"Another endpoint is already registered with id '" + id + "'");
|
throw new IllegalStateException("Another endpoint is already registered with id '" + id + "'");
|
||||||
|
}
|
||||||
MessageListenerContainer container = createListenerContainer(endpoint, factory);
|
MessageListenerContainer container = createListenerContainer(endpoint, factory);
|
||||||
this.listenerContainers.put(id, container);
|
this.listenerContainers.put(id, container);
|
||||||
if (startImmediately) {
|
if (startImmediately) {
|
||||||
|
@ -181,28 +188,6 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
for (MessageListenerContainer listenerContainer : getListenerContainers()) {
|
|
||||||
if (listenerContainer instanceof DisposableBean) {
|
|
||||||
try {
|
|
||||||
((DisposableBean) listenerContainer).destroy();
|
|
||||||
}
|
|
||||||
catch (Throwable ex) {
|
|
||||||
logger.warn("Failed to destroy message listener container", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
|
||||||
if (event.getApplicationContext().equals(this.applicationContext)) {
|
|
||||||
this.contextRefreshed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delegating implementation of SmartLifecycle
|
// Delegating implementation of SmartLifecycle
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -259,6 +244,20 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
for (MessageListenerContainer listenerContainer : getListenerContainers()) {
|
||||||
|
if (listenerContainer instanceof DisposableBean) {
|
||||||
|
try {
|
||||||
|
((DisposableBean) listenerContainer).destroy();
|
||||||
|
}
|
||||||
|
catch (Throwable ex) {
|
||||||
|
logger.warn("Failed to destroy message listener container", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class AggregatingCallback implements Runnable {
|
private static class AggregatingCallback implements Runnable {
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public void unknownFactory() {
|
public void unknownFactory() {
|
||||||
thrown.expect(BeanCreationException.class);
|
thrown.expect(BeanCreationException.class);
|
||||||
thrown.expectMessage("customFactory"); // Not found
|
thrown.expectMessage("customFactory"); // not found
|
||||||
new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class);
|
new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,11 +199,11 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
|
context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
|
||||||
assertEquals(0, defaultFactory.getListenerContainers().size());
|
assertEquals(0, defaultFactory.getListenerContainers().size());
|
||||||
|
|
||||||
context.getBean(LazyBean.class); // trigger lazy resolution
|
context.getBean(LazyBean.class); // trigger lazy resolution
|
||||||
assertEquals(1, defaultFactory.getListenerContainers().size());
|
assertEquals(1, defaultFactory.getListenerContainers().size());
|
||||||
MessageListenerTestContainer container = defaultFactory.getListenerContainers().get(0);
|
MessageListenerTestContainer container = defaultFactory.getListenerContainers().get(0);
|
||||||
assertTrue("Should have been started " + container, container.isStarted());
|
assertTrue("Should have been started " + container, container.isStarted());
|
||||||
context.close(); // Close and stop the listeners
|
context.close(); // close and stop the listeners
|
||||||
assertTrue("Should have been stopped " + container, container.isStopped());
|
assertTrue("Should have been stopped " + container, container.isStopped());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,6 +339,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableJms
|
@EnableJms
|
||||||
static class EnableJmsAutoStartupFalseConfig implements JmsListenerConfigurer {
|
static class EnableJmsAutoStartupFalseConfig implements JmsListenerConfigurer {
|
||||||
|
@ -378,6 +379,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
String concurrency() default "";
|
String concurrency() default "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JmsListener(destination = "billingQueue")
|
@JmsListener(destination = "billingQueue")
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
private @interface BillingQueueListener {
|
private @interface BillingQueueListener {
|
||||||
|
@ -389,6 +391,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
String concurrency() default "";
|
String concurrency() default "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class ComposedJmsListenersBean {
|
static class ComposedJmsListenersBean {
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,12 @@ public class JmsListenerContainerTestFactory implements JmsListenerContainerFact
|
||||||
private final Map<String, MessageListenerTestContainer> listenerContainers =
|
private final Map<String, MessageListenerTestContainer> listenerContainers =
|
||||||
new LinkedHashMap<>();
|
new LinkedHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
public void setAutoStartup(boolean autoStartup) {
|
public void setAutoStartup(boolean autoStartup) {
|
||||||
this.autoStartup = autoStartup;
|
this.autoStartup = autoStartup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<MessageListenerTestContainer> getListenerContainers() {
|
public List<MessageListenerTestContainer> getListenerContainers() {
|
||||||
return new ArrayList<>(this.listenerContainers.values());
|
return new ArrayList<>(this.listenerContainers.values());
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ import org.springframework.jms.support.destination.DestinationResolver;
|
||||||
/**
|
/**
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class MessageListenerTestContainer
|
public class MessageListenerTestContainer implements MessageListenerContainer, InitializingBean, DisposableBean {
|
||||||
implements MessageListenerContainer, InitializingBean, DisposableBean {
|
|
||||||
|
|
||||||
private final JmsListenerEndpoint endpoint;
|
private final JmsListenerEndpoint endpoint;
|
||||||
|
|
||||||
|
@ -41,10 +40,12 @@ public class MessageListenerTestContainer
|
||||||
|
|
||||||
private boolean destroyInvoked;
|
private boolean destroyInvoked;
|
||||||
|
|
||||||
|
|
||||||
MessageListenerTestContainer(JmsListenerEndpoint endpoint) {
|
MessageListenerTestContainer(JmsListenerEndpoint endpoint) {
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setAutoStartup(boolean autoStartup) {
|
public void setAutoStartup(boolean autoStartup) {
|
||||||
this.autoStartup = autoStartup;
|
this.autoStartup = autoStartup;
|
||||||
}
|
}
|
||||||
|
@ -133,8 +134,7 @@ public class MessageListenerTestContainer
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
if (!stopInvoked) {
|
if (!stopInvoked) {
|
||||||
throw new IllegalStateException("Stop should have been invoked before " +
|
throw new IllegalStateException("Stop should have been invoked before " + "destroy on " + this);
|
||||||
"destroy on " + this);
|
|
||||||
}
|
}
|
||||||
destroyInvoked = true;
|
destroyInvoked = true;
|
||||||
}
|
}
|
||||||
|
@ -150,4 +150,5 @@ public class MessageListenerTestContainer
|
||||||
sb.append('}');
|
sb.append('}');
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 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.
|
||||||
|
@ -132,7 +132,7 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
|
||||||
|
|
||||||
public SockJsMessageCodec getMessageCodec() {
|
public SockJsMessageCodec getMessageCodec() {
|
||||||
Assert.state(this.messageCodec != null, "A SockJsMessageCodec is required but not available: " +
|
Assert.state(this.messageCodec != null, "A SockJsMessageCodec is required but not available: " +
|
||||||
"Add Jackson 2 to the classpath, or configure a custom SockJsMessageCodec.");
|
"Add Jackson to the classpath, or configure a custom SockJsMessageCodec.");
|
||||||
return this.messageCodec;
|
return this.messageCodec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue