[embjopr-commits] EMBJOPR SVN: r116 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.
embjopr-commits at lists.jboss.org
embjopr-commits at lists.jboss.org
Tue Jan 20 16:55:11 EST 2009
Author: ozizka at redhat.com
Date: 2009-01-20 16:55:10 -0500 (Tue, 20 Jan 2009)
New Revision: 116
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java
Log:
A tool for JMX operations
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java 2009-01-20 21:55:10 UTC (rev 116)
@@ -0,0 +1,74 @@
+package org.jboss.jopr.jsfunit;
+
+import java.io.IOException;
+import java.util.Hashtable;
+import javax.management.*;
+import javax.naming.*;
+import org.jboss.mx.util.MBeanServerLocator;
+
+/**
+ * JMX utilities.
+ * TODO: Write set, invoke if needed. Possibly also remote JMX support (will we ever need it?).
+ * @author ondra
+ */
+public final class JMXUtils{
+
+ private final MBeanServerConnection jmxServer;
+ private static final String RMI_ADAPTOR_JNDI_NAME = "jmx/invoker/RMIAdaptor";
+
+ private JMXUtils(MBeanServer jmxServer) {
+ this.jmxServer = jmxServer;
+ }
+
+ public static JMXUtils getInstanceForLocalJBoss(){
+ return new JMXUtils( MBeanServerLocator.locateJBoss() );
+ }
+
+ /**
+ * This can come handy later...
+ * @param host JBoss host.
+ * @param port RMI connector port.
+ * @return An instance of callable MBeanServerConnection.
+ * TODO: Needs dependency: jmx-adaptor-plugin - which version?
+ */
+ public static JMXUtils getInstanceForRemoteJBoss( String host, Integer port ) throws NamingException{
+
+ // Setup context environment.
+ Hashtable env = new Hashtable();
+ env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ String providerURL = "jnp://" + host + ":"+ port.toString() +"/";
+ env.put("java.naming.provider.url", providerURL);
+ env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+
+ // Do not let another partition member to respond.
+ env.put("jnp.disableDiscovery", "true");
+
+ //log.info("Looking for InitialContext for "+providerURL + " ...");
+
+ InitialContext context = new InitialContext(env);
+
+ //log.info("Found InitialContext: "+ context.toString() );
+
+ // lookup JMX mbean RMI adaptor
+ //RMIAdaptor server = (RMIAdaptor) ic.lookup(RMI_ADAPTOR_JNDI_NAME);
+ //return new JMXUtils( context );
+
+ throw new UnsupportedOperationException(
+ "This uses RMIAdaptor and thus introduces unnecesarry dependency.");
+
+ }// getInstanceForRemoteJBoss()
+
+ public static JMXUtils getInstanceForRemoteJBoss( String host ) throws NamingException {
+ return getInstanceForRemoteJBoss(host, 1099);
+ }
+
+
+ public Object getMBeanAttribute( String mBeanName, String attribute ) throws JMException, IOException {
+ return this.getMBeanAttribute( new ObjectName(mBeanName), attribute );
+ }
+
+ public Object getMBeanAttribute( ObjectName mBeanName, String attribute ) throws JMException, IOException {
+ return jmxServer.getAttribute( mBeanName, attribute );
+ }
+
+}// class JMXUtils
More information about the embjopr-commits
mailing list