From fbf34e261ee78c81fb46ccb117120366d6629b49 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 30 Mar 2015 10:37:02 -0700 Subject: [PATCH] Polish --- .../endpoint/jmx/DataEndpointMBean.java | 13 ++++++++++ .../actuate/endpoint/jmx/EndpointMBean.java | 16 ++++++++++--- .../endpoint/jmx/EndpointMBeanExporter.java | 9 ++++++- .../endpoint/jmx/ShutdownEndpointMBean.java | 17 +++++++++++-- .../jmx/EndpointMBeanExporterTests.java | 24 +++---------------- ...EnableAutoConfigurationImportSelector.java | 3 +-- .../condition/ConditionEvaluationReport.java | 19 ++++++++------- 7 files changed, 63 insertions(+), 38 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java index 9e769a25f9a..d3eeb166ca0 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java @@ -32,11 +32,24 @@ import com.fasterxml.jackson.databind.ObjectMapper; @ManagedResource public class DataEndpointMBean extends EndpointMBean { + /** + * Create a new {@link DataEndpointMBean} instance. + * @param beanName the bean name + * @param endpoint the endpoint to wrap + * @deprecated since 1.3 in favor of + * {@link #DataEndpointMBean(String, Endpoint, ObjectMapper)} + */ @Deprecated public DataEndpointMBean(String beanName, Endpoint endpoint) { super(beanName, endpoint); } + /** + * Create a new {@link DataEndpointMBean} instance. + * @param beanName the bean name + * @param endpoint the endpoint to wrap + * @param objectMapper the {@link ObjectMapper} used to convert the payload + */ public DataEndpointMBean(String beanName, Endpoint endpoint, ObjectMapper objectMapper) { super(beanName, endpoint, objectMapper); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java index 064b9f41643..8f29721d036 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java @@ -40,11 +40,24 @@ public class EndpointMBean { private final ObjectMapper mapper; + /** + * Create a new {@link EndpointMBean} instance. + * @param beanName the bean name + * @param endpoint the endpoint to wrap + * @deprecated since 1.3 in favor of + * {@link #EndpointMBean(String, Endpoint, ObjectMapper)} + */ @Deprecated public EndpointMBean(String beanName, Endpoint endpoint) { this(beanName, endpoint, new ObjectMapper()); } + /** + * Create a new {@link EndpointMBean} instance. + * @param beanName the bean name + * @param endpoint the endpoint to wrap + * @param objectMapper the {@link ObjectMapper} used to convert the payload + */ public EndpointMBean(String beanName, Endpoint endpoint, ObjectMapper objectMapper) { Assert.notNull(beanName, "BeanName must not be null"); Assert.notNull(endpoint, "Endpoint must not be null"); @@ -71,15 +84,12 @@ public class EndpointMBean { if (result == null) { return null; } - if (result instanceof String) { return result; } - if (result.getClass().isArray() || result instanceof List) { return this.mapper.convertValue(result, List.class); } - return this.mapper.convertValue(result, Map.class); } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporter.java index c602ec2d1b5..9894d47ce26 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporter.java @@ -96,12 +96,19 @@ public class EndpointMBeanExporter extends MBeanExporter implements SmartLifecyc private final ObjectMapper objectMapper; + /** + * Create a new {@link EndpointMBeanExporter} instance. + */ public EndpointMBeanExporter() { this(null); } + /** + * Create a new {@link EndpointMBeanExporter} instance. + * @param objectMapper the object mapper + */ public EndpointMBeanExporter(ObjectMapper objectMapper) { - this.objectMapper = objectMapper == null ? new ObjectMapper() : objectMapper; + this.objectMapper = (objectMapper == null ? new ObjectMapper() : objectMapper); setAutodetect(false); setNamingStrategy(this.defaultNamingStrategy); setAssembler(this.assembler); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java index 854df90ba57..0ebe83ae84a 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java @@ -32,14 +32,27 @@ import com.fasterxml.jackson.databind.ObjectMapper; @ManagedResource public class ShutdownEndpointMBean extends EndpointMBean { + /** + * Create a new {@link ShutdownEndpointMBean} instance. + * @param beanName the bean name + * @param endpoint the endpoint to wrap + * @deprecated since 1.3 in favor of + * {@link #ShutdownEndpointMBean(String, Endpoint, ObjectMapper)} + */ @Deprecated public ShutdownEndpointMBean(String beanName, Endpoint endpoint) { super(beanName, endpoint); } + /** + * Create a new {@link ShutdownEndpointMBean} instance. + * @param beanName the bean name + * @param endpoint the endpoint to wrap + * @param objectMapper the {@link ObjectMapper} used to convert the payload + */ public ShutdownEndpointMBean(String beanName, Endpoint endpoint, - ObjectMapper mapper) { - super(beanName, endpoint, mapper); + ObjectMapper objectMapper) { + super(beanName, endpoint, objectMapper); } @ManagedOperation(description = "Shutdown the ApplicationContext") diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java index 3b546bb51c6..152711f0ab6 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java @@ -73,9 +73,7 @@ public class EndpointMBeanExporterTests { this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition( TestEndpoint.class)); this.context.refresh(); - MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - MBeanInfo mbeanInfo = mbeanExporter.getServer().getMBeanInfo( getObjectName("endpoint1", this.context)); assertNotNull(mbeanInfo); @@ -93,9 +91,7 @@ public class EndpointMBeanExporterTests { this.context.registerBeanDefinition("endpoint2", new RootBeanDefinition( TestEndpoint.class)); this.context.refresh(); - MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer().getMBeanInfo( getObjectName("endpoint1", this.context))); assertNotNull(mbeanExporter.getServer().getMBeanInfo( @@ -113,9 +109,7 @@ public class EndpointMBeanExporterTests { this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition( TestEndpoint.class)); this.context.refresh(); - MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer().getMBeanInfo( getObjectName("test-domain", "endpoint1", false, this.context))); } @@ -132,9 +126,7 @@ public class EndpointMBeanExporterTests { this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition( TestEndpoint.class)); this.context.refresh(); - MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer().getMBeanInfo( getObjectName("test-domain", "endpoint1", true, this.context))); } @@ -156,9 +148,7 @@ public class EndpointMBeanExporterTests { this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition( TestEndpoint.class)); this.context.refresh(); - MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer().getMBeanInfo( ObjectNameManager.getInstance(getObjectName("test-domain", "endpoint1", true, this.context).toString() @@ -173,13 +163,10 @@ public class EndpointMBeanExporterTests { this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition( TestEndpoint.class)); GenericApplicationContext parent = new GenericApplicationContext(); - this.context.setParent(parent); parent.refresh(); this.context.refresh(); - MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer().getMBeanInfo( getObjectName("endpoint1", this.context))); @@ -194,12 +181,10 @@ public class EndpointMBeanExporterTests { this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition( JsonConversionEndpoint.class)); this.context.refresh(); - MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); Object response = mbeanExporter.getServer().invoke( getObjectName("endpoint1", this.context), "getData", new Object[0], new String[0]); - assertThat(response, is(instanceOf(Map.class))); assertThat(((Map) response).get("date"), is(instanceOf(Long.class))); } @@ -217,12 +202,10 @@ public class EndpointMBeanExporterTests { this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition( JsonConversionEndpoint.class)); this.context.refresh(); - MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); Object response = mbeanExporter.getServer().invoke( getObjectName("endpoint1", this.context), "getData", new Object[0], new String[0]); - assertThat(response, is(instanceOf(Map.class))); assertThat(((Map) response).get("date"), is(instanceOf(String.class))); } @@ -242,10 +225,8 @@ public class EndpointMBeanExporterTests { .getIdentityHexString(applicationContext .getBean(beanKey)))); } - else { - return ObjectNameManager.getInstance(String.format( - "%s:type=Endpoint,name=%s", domain, beanKey)); - } + return ObjectNameManager.getInstance(String.format("%s:type=Endpoint,name=%s", + domain, beanKey)); } public static class TestEndpoint extends AbstractEndpoint { @@ -258,6 +239,7 @@ public class EndpointMBeanExporterTests { public String invoke() { return "hello world"; } + } public static class JsonConversionEndpoint extends diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java index 37075e8e68e..7388d0cdc18 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java @@ -73,8 +73,7 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector, this.beanClassLoader))); // Remove those specifically disabled - List excluded = new ArrayList(Arrays.asList(attributes - .getStringArray("exclude"))); + List excluded = Arrays.asList(attributes.getStringArray("exclude")); factories.removeAll(excluded); ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java index 8cb7e34437b..bb470e1869d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.condition; +import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; @@ -87,7 +88,7 @@ public class ConditionEvaluationReport { */ public void recordExclusions(List exclusions) { Assert.notNull(exclusions, "exclusions must not be null"); - this.exclusions = exclusions; + this.exclusions = new ArrayList(exclusions); } /** @@ -106,14 +107,6 @@ public class ConditionEvaluationReport { return Collections.unmodifiableMap(this.outcomes); } - /** - * Returns the name of the classes that have been excluded from condition evaluation. - * @return the names of the excluded classes - */ - public List getExclusions() { - return Collections.unmodifiableList(this.exclusions); - } - private void addNoMatchOutcomeToAncestors(String source) { String prefix = source + "$"; for (Entry entry : this.outcomes.entrySet()) { @@ -125,6 +118,14 @@ public class ConditionEvaluationReport { } } + /** + * Returns the name of the classes that have been excluded from condition evaluation. + * @return the names of the excluded classes + */ + public List getExclusions() { + return Collections.unmodifiableList(this.exclusions); + } + /** * The parent report (from a parent BeanFactory if there is one). * @return the parent report (or null if there isn't one)