本文整理汇总了Java中org.springframework.jmx.support.JmxUtils类的典型用法代码示例。如果您正苦于以下问题:Java JmxUtils类的具体用法?Java JmxUtils怎么用?Java JmxUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JmxUtils类属于org.springframework.jmx.support包,在下文中一共展示了JmxUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeOperation
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
/**
* Routes a method invocation (not a property get/set) to the corresponding
* operation on the managed resource.
* @param method the method corresponding to operation on the managed resource.
* @param args the invocation arguments
* @return the value returned by the method invocation.
*/
private Object invokeOperation(Method method, Object[] args) throws JMException, IOException {
MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes());
MBeanOperationInfo info = this.allowedOperations.get(key);
if (info == null) {
throw new InvalidInvocationException("Operation '" + method.getName() +
"' is not exposed on the management interface");
}
String[] signature = null;
synchronized (this.signatureCache) {
signature = this.signatureCache.get(method);
if (signature == null) {
signature = JmxUtils.getMethodSignature(method);
this.signatureCache.put(method, signature);
}
}
return this.serverToUse.invoke(this.objectName, method.getName(), args, signature);
}
示例2: connect
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
/**
* Connects to the remote {@code MBeanServer} using the configured {@code JMXServiceURL}:
* to the specified JMX service, or to a local MBeanServer if no service URL specified.
* @param serviceUrl the JMX service URL to connect to (may be {@code null})
* @param environment the JMX environment for the connector (may be {@code null})
* @param agentId the local JMX MBeanServer's agent id (may be {@code null})
*/
public MBeanServerConnection connect(JMXServiceURL serviceUrl, Map<String, ?> environment, String agentId)
throws MBeanServerNotFoundException {
if (serviceUrl != null) {
if (logger.isDebugEnabled()) {
logger.debug("Connecting to remote MBeanServer at URL [" + serviceUrl + "]");
}
try {
this.connector = JMXConnectorFactory.connect(serviceUrl, environment);
return this.connector.getMBeanServerConnection();
}
catch (IOException ex) {
throw new MBeanServerNotFoundException("Could not connect to remote MBeanServer [" + serviceUrl + "]", ex);
}
}
else {
logger.debug("Attempting to locate local MBeanServer");
return JmxUtils.locateMBeanServer(agentId);
}
}
示例3: afterPropertiesSet
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
/**
* Kick off bean registration automatically when deployed in an
* {@code ApplicationContext}.
* @see #registerBeans()
*/
@Override
public void afterPropertiesSet() {
// If no server was provided then try to find one. This is useful in an environment
// where there is already an MBeanServer loaded.
if (this.server == null) {
this.server = JmxUtils.locateMBeanServer();
}
try {
logger.info("Registering beans for JMX exposure on startup");
registerBeans();
registerNotificationListeners();
}
catch (RuntimeException ex) {
// Unregister beans already registered by this exporter.
unregisterNotificationListeners();
unregisterBeans();
throw ex;
}
}
示例4: registerManagedResource
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
@Override
public ObjectName registerManagedResource(Object managedResource) throws MBeanExportException {
Assert.notNull(managedResource, "Managed resource must not be null");
ObjectName objectName;
try {
objectName = getObjectName(managedResource, null);
if (this.ensureUniqueRuntimeObjectNames) {
objectName = JmxUtils.appendIdentityToObjectName(objectName, managedResource);
}
}
catch (Exception ex) {
throw new MBeanExportException("Unable to generate ObjectName for MBean [" + managedResource + "]", ex);
}
registerManagedResource(managedResource, objectName);
return objectName;
}
示例5: adaptMBeanIfPossible
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
/**
* Build an adapted MBean for the given bean instance, if possible.
* <p>The default implementation builds a JMX 1.2 StandardMBean
* for the target's MBean/MXBean interface in case of an AOP proxy,
* delegating the interface's management operations to the proxy.
* @param bean the original bean instance
* @return the adapted MBean, or {@code null} if not possible
*/
@SuppressWarnings("unchecked")
protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException {
Class<?> targetClass = AopUtils.getTargetClass(bean);
if (targetClass != bean.getClass()) {
Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
if (ifc != null) {
if (!ifc.isInstance(bean)) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MXBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ((Class<Object>) ifc), true);
}
else {
ifc = JmxUtils.getMBeanInterface(targetClass);
if (ifc != null) {
if (!ifc.isInstance(bean)) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ((Class<Object>) ifc));
}
}
}
return null;
}
示例6: afterPropertiesSet
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
/**
* Start bean registration automatically when deployed in an
* {@code ApplicationContext}.
* @see #registerBeans()
*/
@Override
public void afterPropertiesSet() {
// If no server was provided then try to find one. This is useful in an environment
// such as JDK 1.5, Tomcat or JBoss where there is already an MBeanServer loaded.
if (this.server == null) {
this.server = JmxUtils.locateMBeanServer();
}
try {
logger.info("Registering beans for JMX exposure on startup");
registerBeans();
registerNotificationListeners();
}
catch (RuntimeException ex) {
// Unregister beans already registered by this exporter.
unregisterNotificationListeners();
unregisterBeans();
throw ex;
}
}
示例7: adaptMBeanIfPossible
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
/**
* Build an adapted MBean for the given bean instance, if possible.
* <p>The default implementation builds a JMX 1.2 StandardMBean
* for the target's MBean/MXBean interface in case of an AOP proxy,
* delegating the interface's management operations to the proxy.
* @param bean the original bean instance
* @return the adapted MBean, or {@code null} if not possible
*/
@SuppressWarnings("unchecked")
protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException {
Class<?> targetClass = AopUtils.getTargetClass(bean);
if (targetClass != bean.getClass()) {
Class<Object> ifc = (Class<Object>) JmxUtils.getMXBeanInterface(targetClass);
if (ifc != null) {
if (!(ifc.isInstance(bean))) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MXBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ifc, true);
}
else {
ifc = (Class<Object>) JmxUtils.getMBeanInterface(targetClass);
if (ifc != null) {
if (!(ifc.isInstance(bean))) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ifc);
}
}
}
return null;
}
示例8: findJmxInterface
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
private Class findJmxInterface(String beanKey, Class<?> beanClass) {
Class cachedInterface = interfaceCache.get(beanKey);
if (cachedInterface != null) {
return cachedInterface;
}
Class mbeanInterface = JmxUtils.getMBeanInterface(beanClass);
if (mbeanInterface != null) { // found with MBean ending
interfaceCache.put(beanKey, mbeanInterface);
return mbeanInterface;
}
Class[] ifaces = ClassUtils.getAllInterfacesForClass(beanClass);
for (Class ifc : ifaces) {
ManagedResource metadata = attributeSource.getManagedResource(ifc);
if (metadata != null) { // found with @ManagedResource annotation
interfaceCache.put(beanKey, ifc);
return ifc;
}
}
String msg = "Bean " + beanKey + " doesn't implement management interfaces. " +
"Management interface should either follow naming scheme or be annotated by @ManagedResource";
throw new IllegalArgumentException(msg);
}
示例9: testEnpointConfigurationCanBeSetViaJMX
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
@Test
public void testEnpointConfigurationCanBeSetViaJMX() throws Exception {
Set s = getMBeanServer().queryNames(new ObjectName("org.apache.camel:type=endpoints,name=\"zookeeper:*\",*"), null);
assertEquals("Could not find zookeper endpoint: " + s, 1, s.size());
ObjectName zepName = new ArrayList<ObjectName>(s).get(0);
verifyManagedAttribute(zepName, "Path", "/node");
verifyManagedAttribute(zepName, "Create", false);
verifyManagedAttribute(zepName, "Repeat", false);
verifyManagedAttribute(zepName, "ListChildren", false);
verifyManagedAttribute(zepName, "Timeout", 1000);
verifyManagedAttribute(zepName, "Backoff", 2000L);
getMBeanServer().invoke(zepName, "clearServers", null, JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("clearServers", null)));
getMBeanServer().invoke(zepName, "addServer", new Object[]{"someserver:12345"},
JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("addServer", new Class[]{String.class})));
}
示例10: afterPropertiesSet
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
/**
* Kick off bean registration automatically when deployed in an
* {@code ApplicationContext}.
* @see #registerBeans()
*/
public void afterPropertiesSet() {
// If no server was provided then try to find one. This is useful in an environment
// where there is already an MBeanServer loaded.
if (this.server == null) {
this.server = JmxUtils.locateMBeanServer();
}
try {
logger.info("Registering beans for JMX exposure on startup");
registerBeans();
registerNotificationListeners();
}
catch (RuntimeException ex) {
// Unregister beans already registered by this exporter.
unregisterNotificationListeners();
unregisterBeans();
throw ex;
}
}
示例11: prepare
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
/**
* Ensures that an {@code MBeanServerConnection} is configured and attempts
* to detect a local connection if one is not supplied.
*/
public void prepare() {
synchronized (this.preparationMonitor) {
if (this.server != null) {
this.serverToUse = this.server;
}
else {
this.serverToUse = null;
this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId);
}
this.invocationHandler = null;
if (this.useStrictCasing) {
// Use the JDK's own MBeanServerInvocationHandler,
// in particular for native MXBean support on Java 6.
if (JmxUtils.isMXBeanSupportAvailable()) {
this.invocationHandler =
new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
}
else {
this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName);
}
}
else {
// Non-strict casing can only be achieved through custom
// invocation handling. Only partial MXBean support available!
retrieveMBeanInfo();
}
}
}
示例12: invokeAttribute
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation)
throws JMException, IOException {
String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing);
MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
// If no attribute is returned, we know that it is not defined in the
// management interface.
if (inf == null) {
throw new InvalidInvocationException(
"Attribute '" + pd.getName() + "' is not exposed on the management interface");
}
if (invocation.getMethod().equals(pd.getReadMethod())) {
if (inf.isReadable()) {
return this.serverToUse.getAttribute(this.objectName, attributeName);
}
else {
throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable");
}
}
else if (invocation.getMethod().equals(pd.getWriteMethod())) {
if (inf.isWritable()) {
this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0]));
return null;
}
else {
throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable");
}
}
else {
throw new IllegalStateException(
"Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter");
}
}
示例13: afterPropertiesSet
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
// If no server was provided then try to find one. This is useful in an environment
// where there is already an MBeanServer loaded.
if (this.server == null) {
this.server = JmxUtils.locateMBeanServer();
}
}
示例14: excludeMBeanIfNecessary
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
private void excludeMBeanIfNecessary(Object candidate, String beanName) {
try {
MBeanExporter mbeanExporter = this.context.getBean(MBeanExporter.class);
if (JmxUtils.isMBean(candidate.getClass())) {
mbeanExporter.addExcludedBean(beanName);
}
}
catch (NoSuchBeanDefinitionException ex) {
// No exporter. Exclusion is unnecessary
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:JndiDataSourceAutoConfiguration.java
示例15: registerManagedResource
import org.springframework.jmx.support.JmxUtils; //导入依赖的package包/类
public ObjectName registerManagedResource(Object managedResource) throws MBeanExportException {
Assert.notNull(managedResource, "Managed resource must not be null");
ObjectName objectName;
try {
objectName = getObjectName(managedResource, null);
if (this.ensureUniqueRuntimeObjectNames) {
objectName = JmxUtils.appendIdentityToObjectName(objectName, managedResource);
}
}
catch (Exception ex) {
throw new MBeanExportException("Unable to generate ObjectName for MBean [" + managedResource + "]", ex);
}
registerManagedResource(managedResource, objectName);
return objectName;
}