[Management, JMX/JBoss] - Re: How to write Jython scripts to communicate with MBeans
by maxdiconoclast
I seemed to have found the answer, what I was doing wrong was that, the RMI connxn was not being initialized correctly to the server.
Below is a small snippet which worked for me.
from java.util import Properties
from java.lang import System
from javax.naming import InitialContext
from javax.management import NotificationListener,ObjectName,MBeanInfo,MBeanAttributeInfo
class ClientListener(NotificationListener):
print "Will it work :("
props = Properties(System.getProperties())
props.put("java.naming.provider.url", "jnp://localhost:1099")
props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory")
props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces")
ctx = InitialContext(props)
adapterName = "jmx/invoker/RMIAdaptor"
server = ctx.lookup(adapterName)
ctx.close()
name = ObjectName("jboss:service=JNDIView")
info = server.getMBeanInfo(name)
print "JNDIView Class: " + info.getClassName()
print " "
aValue = server.getAttribute(name,"HANamingService")
print "Value of HANamingService is::: " + aValue
print "It worked Bye Bye! :)"
+++++++++++++++++++++++++++++++++++++++++++++
This made the communication with the MBean server and fetched me a dummy value of the configured MBean.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4206889#4206889
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4206889
17 years, 2 months