-
Sep 8th, 2008, 01:10 PM
#1
ManagedOperations not getting detected
Please can you advise me on below.
I have used Spring's MBeanExporter to define two JMX MBean but for some reason, Spring cant detect the operations defined in the second bean.
My bean definitions are :
1. JJSSLF4JLoggerLevelChanger
@ManagedResource(objectName="bean:name=JJSSLF4JLog gerLevelChanger", description="Changes Logging Levels")
public class JJSSLF4JLoggerLevelChanger {
private final org.slf4j.Logger logger = LoggerFactory.getLogger(JJSSLF4JLoggerLevelChanger .class);
@ManagedOperation(description="Set Logger Level")
@ManagedOperationParameters({
@ManagedOperationParameter(name = "aLoggerName", description = "Logger Name"),
@ManagedOperationParameter(name = "aLevel", description = "Logger Level")})
public void setLoggerLevel(String aLoggerName,String aLevel)
{
String validLoggingLevelsInSequence = "TRACE DEBUGALL DEBUG INFO WARN ERROR FATAL";
String updatedLoggerLevel = aLevel.toUpperCase();
if (validLoggingLevelsInSequence.indexOf(updatedLogge rLevel) == -1) {
updatedLoggerLevel = "WARN";
logger.error("Invalid Logging Level [" + aLevel + "], using Level [" + updatedLoggerLevel + "]");
}
else {
if (updatedLoggerLevel.equals("DEBUGALL")) {
updatedLoggerLevel = "DEBUG";
}
}
Logger.getLogger(aLoggerName).setLevel(Level.toLev el(aLevel));
}
}
2. JJSSLF4JRootLoggerLevelChanger
@ManagedResource(objectName="bean:name=JJSSLF4JRoo tLoggerLevelChanger", description="Changes Root Logging Levels")
public class JJSSLF4JRootLoggerLevelChanger {
private final org.slf4j.Logger logger = LoggerFactory.getLogger(JJSSLF4JRootLoggerLevelCha nger.class);
@ManagedOperation(description="Set Root Logger Level")
@ManagedOperationParameters({
@ManagedOperationParameter(name = "aLevel", description = "Root Logger Level")})
public void setRootLoggerLevel(String aLevel)
{
String validLoggingLevelsInSequence = "TRACE DEBUGALL DEBUG INFO WARN ERROR FATAL";
String updatedRootLoggerLevel = aLevel.toUpperCase();
if (validLoggingLevelsInSequence.indexOf(updatedRootL oggerLevel) == -1) {
updatedRootLoggerLevel = "WARN";
logger.error("Invalid Logging Level [" + aLevel + "], using Level [" + updatedRootLoggerLevel + "]");
}
else {
if (updatedRootLoggerLevel.equals("DEBUGALL")) {
updatedRootLoggerLevel = "DEBUG";
}
}
Logger.getRootLogger().setLevel(Level.toLevel(aLev el));
}
}
and the Spring context file is
<bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.A nnotationJmxAttributeSource"/>
<bean id="assembler" class="org.springframework.jmx.export.assembler.Me tadataMBeanInfoAssembler">
<property name="attributeSource" ref="jmxAttributeSource"/>
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.WebSphereMB eanServerFactoryBean"/>
<bean id="beanExporter" class="org.springframework.jmx.export.MBeanExporte r" lazy-init="false">
<property name="server" ref="mbeanServer"/>
<property name="assembler" ref="assembler"/>
</bean>
<bean id="jjsSLF4JLoggerLevelChanger" class="JJSSLF4JLoggerLevelChanger"/>
<bean id="jjsSLF4JRootLoggerLevelChanger" class="JJSSLF4JRootLoggerLevelChanger"/>
I get a message on console saying jjsSLF4JRootLoggerLevelChanger(my second bean) has been autodetected as JMX Bean but no attibutes or operations have been defined.
Cheers,
Sanjay Patil
Last edited by Sanjay Patil; Sep 8th, 2008 at 01:17 PM.
-
Sep 9th, 2008, 11:23 PM
#2
Differentiate Between Operations and Attributes
In JMX, the difference is significant between setter/getter methods (considered attributes) and other methods (considered operations). The Spring annotation-based metadata handling continues this. So, for methods that set your data members, like the set method, you need to use @ManagedAttribute rather than @ManagedOperation. See Using Spring Metadata MBean Exporter for Greater Descriptive Detail for additional details.
-
Sep 10th, 2008, 07:55 AM
#3
ManagedOperations not getting detected
Hi,
If I make that method as ManagedAttribute, it tries to execute the method with the name as rootLoggerLevel and fails saying, it can find that method.
and if I change the method name as rootLoggerLevel, it doesnt get detected.
I got this working by adding an extra argument in the method and using ManagedOperations. Please suggest, if you have any other suggestion.
Also, I m using IBM's MBeanInspector to invoke my JMX at runtime but I get below error.
javax.management.MBeanException: RuntimeException thrown in RequiredModelMBean while trying to invoke operation setRootLoggerLevel
at javax.management.modelmbean.RequiredModelMBean.inv okeMethod(RequiredModelMBean.java:1106)
at javax.management.modelmbean.RequiredModelMBean.inv oke(RequiredModelMBean.java:971)
at org.springframework.jmx.export.SpringModelMBean.in voke(SpringModelMBean.java:88)
at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke (DynamicMetaDataImpl.java:231)
at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDa taImpl.java:238)
at com.sun.jmx.interceptor.DefaultMBeanServerIntercep tor.invoke(DefaultMBeanServerInterceptor.java:833)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxM BeanServer.java:802)
at com.ibm.ws.management.AdminServiceImpl$1.run(Admin ServiceImpl.java:1081)
at com.ibm.ws.security.util.AccessController.doPrivil eged(AccessController.java:118)
at com.ibm.ws.management.AdminServiceImpl.invoke(Admi nServiceImpl.java:974)
at com.ibm.ws.management.connector.AdminServiceDelega tor.invoke(AdminServiceDelegator.java:139)
at com.ibm.ws.management.connector.rmi.RMIConnectorSe rvice.invoke(RMIConnectorService.java:179)
at com.ibm.ws.management.connector.rmi._RMIConnectorS ervice_Tie.invoke(_RMIConnectorService_Tie.java:39 5)
at com.ibm.ws.management.connector.rmi._RMIConnectorS ervice_Tie._invoke(_RMIConnectorService_Tie.java:1 60)
at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHa ndler(ServerDelegate.java:613)
at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerD elegate.java:466)
at com.ibm.rmi.iiop.ORB.process(ORB.java:503)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:1552)
at com.ibm.rmi.iiop.Connection.respondTo(Connection.j ava:2673)
at com.ibm.rmi.iiop.Connection.doWork(Connection.java :2551)
at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl. java:62)
at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.ja va:118)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava:1473)
Caused by: java.lang.NullPointerException
at com.johnlewis.jjs2.common.logging.jmx.JJSSLF4JLogg erLevelChanger.setRootLoggerLevel(JJSSLF4JLoggerLe velChanger.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java :62)
at sun.reflect.GeneratedMethodAccessor55.invoke(Unkno wn Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java :265)
at javax.management.modelmbean.RequiredModelMBean.inv okeMethod(RequiredModelMBean.java:1089)
... 22 more
Basically, I want to invoke my JMX Beans via WAS 6.1 admin console or any other utility, which my WAS support team can use. Do u have any suggestion here. Please advise.
-
Sep 10th, 2008, 07:45 PM
#4
"Get" Method Not Setting Class Data Member
It makes sense that it works as an operation with an extra parameter because, with the extra parameter, it no longer matches the definition of a get/set method. Similarly, you could have essentially the same thing as a "get" method that returns a class member, but if you leave the get off of it, it is treated as a JMX operation.
I noticed in your example, your setLoggerLevel actually sets a local String variable rather than a class member that is a String. I'd try adding loggerLevel as a member of your class and then having the setLoggerLevel method set this.loggerLevel to the value you pass in to the set method. With that annotated as an @ManagedAttribute, you should have a writable attribute. You probably want to provide a get method as well so that you have a readable attribute.
-
Sep 12th, 2008, 03:39 AM
#5
ManagedOperations not getting detected
Hi,
Could you please suggest me on the error I am getting while trying to invoke my JMX Bean via MBeanInspector. Also, are there any other ways of invoking JMx Beans on WAS 6.1 server.
Cheers,
Sanjay Patil
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules