-
1. Re: How to write Jython scripts to communicate with MBeans
maxdiconoclast Feb 4, 2009 6:34 AM (in response to 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. -
2. Re: How to write Jython scripts to communicate with MBeans
erabeck Aug 18, 2010 4:48 PM (in response to maxdiconoclast)Manav,
This is great. I've been considering doing some similar monitoring and would rather wrap things in a single script than calling twiddle.sh over and over again. Do you have any more code you'd be willing to share and/or links to the resources you used to get this far?
Thanks,
--Evan