Browse Source

Rename invoke JMX operation

Rename invoke JMX operation to getData for endpoints that provide actuator data. Special case for ShutdownEndpoint to provide a shutdown method.
pull/176/head
Christian Dupuis 12 years ago
parent
commit
72ae5d5a97
  1. 41
      spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java
  2. 17
      spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java
  3. 10
      spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporter.java
  4. 38
      spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java
  5. 6
      spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java

41
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
/*
* Copyright 2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.endpoint.jmx;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
/**
* Simple wrapper around {@link Endpoint} implementations that provide actuator data of
* some sort.
*
* @author Christian Dupuis
*/
@ManagedResource
public class DataEndpointMBean extends EndpointMBean {
public DataEndpointMBean(String beanName, Endpoint<?> endpoint) {
super(beanName, endpoint);
}
@ManagedAttribute(description = "Invoke the underlying endpoint")
public Object getData() {
return convert(getEndpoint().invoke());
}
}

17
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java

@ -69,9 +69,16 @@ public class EndpointMBean implements SelfNaming { @@ -69,9 +69,16 @@ public class EndpointMBean implements SelfNaming {
return this.endpoint.isSensitive();
}
@ManagedAttribute(description = "Invoke the underlying endpoint")
public Object invoke() {
Object result = this.endpoint.invoke();
@Override
public ObjectName getObjectName() throws MalformedObjectNameException {
return this.metadataNamingStrategy.getObjectName(this, this.beanName);
}
public Endpoint<?> getEndpoint() {
return this.endpoint;
}
protected Object convert(Object result) {
if (result == null) {
return null;
}
@ -87,8 +94,4 @@ public class EndpointMBean implements SelfNaming { @@ -87,8 +94,4 @@ public class EndpointMBean implements SelfNaming {
return this.mapper.convertValue(result, Map.class);
}
@Override
public ObjectName getObjectName() throws MalformedObjectNameException {
return this.metadataNamingStrategy.getObjectName(this, this.beanName);
}
}

10
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporter.java

@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.endpoint.ShutdownEndpoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
@ -95,13 +96,20 @@ public class EndpointMBeanExporter implements SmartLifecycle, ApplicationContext @@ -95,13 +96,20 @@ public class EndpointMBeanExporter implements SmartLifecycle, ApplicationContext
protected void registerEndpoint(String beanName, Endpoint<?> endpoint,
MBeanExporter mbeanExporter) {
try {
mbeanExporter.registerManagedResource(new EndpointMBean(beanName, endpoint));
mbeanExporter.registerManagedResource(getEndpointMBean(beanName, endpoint));
}
catch (MBeanExportException ex) {
logger.error("Could not register MBean for endpoint [" + beanName + "]", ex);
}
}
protected EndpointMBean getEndpointMBean(String beanName, Endpoint<?> endpoint) {
if (endpoint instanceof ShutdownEndpoint) {
return new ShutdownEndpointMBean(beanName, endpoint);
}
return new DataEndpointMBean(beanName, endpoint);
}
// SmartLifeCycle implementation
public final int getPhase() {

38
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
/*
* Copyright 2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.endpoint.jmx;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.endpoint.ShutdownEndpoint;
import org.springframework.jmx.export.annotation.ManagedOperation;
/**
* Special endpoint wrapper for {@link ShutdownEndpoint}.
*
* @author Christian Dupuis
*/
public class ShutdownEndpointMBean extends EndpointMBean {
public ShutdownEndpointMBean(String beanName, Endpoint<?> endpoint) {
super(beanName, endpoint);
}
@ManagedOperation(description = "Shutdown the ApplicationContext")
public Object shutdown() {
return convert(getEndpoint().invoke());
}
}

6
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java

@ -70,8 +70,8 @@ public class EndpointMBeanExporterTests { @@ -70,8 +70,8 @@ public class EndpointMBeanExporterTests {
MBeanInfo mbeanInfo = mbeanExporter.getServer().getMBeanInfo(
getObjectName("endpoint1", this.context));
assertNotNull(mbeanInfo);
assertEquals(4, mbeanInfo.getOperations().length);
assertEquals(3, mbeanInfo.getAttributes().length);
assertEquals(5, mbeanInfo.getOperations().length);
assertEquals(5, mbeanInfo.getAttributes().length);
}
@Test
@ -127,7 +127,7 @@ public class EndpointMBeanExporterTests { @@ -127,7 +127,7 @@ public class EndpointMBeanExporterTests {
private ObjectName getObjectName(String beanKey, ApplicationContext applicationContext)
throws MalformedObjectNameException {
return new EndpointMBean(beanKey,
return new DataEndpointMBean(beanKey,
(Endpoint<?>) applicationContext.getBean(beanKey)).getObjectName();
}

Loading…
Cancel
Save