[jboss-cvs] jboss-profiler/java/src/expansion/org/jboss/profiler/exp/adaptor ...
Takuro Okada
t2-okada at nri.co.jp
Mon Feb 19 05:50:56 EST 2007
User: tokada
Date: 07/02/19 05:50:56
Modified: java/src/expansion/org/jboss/profiler/exp/adaptor Tag:
JBossProfiler_Expansion ServiceManager.java
Log:
Modified some interfaces.
Revision Changes Path
No revision
No revision
1.1.2.6 +37 -23 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/adaptor/Attic/ServiceManager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ServiceManager.java
===================================================================
RCS file: /cvsroot/jboss/jboss-profiler/java/src/expansion/org/jboss/profiler/exp/adaptor/Attic/ServiceManager.java,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -b -r1.1.2.5 -r1.1.2.6
--- ServiceManager.java 22 Nov 2006 09:09:02 -0000 1.1.2.5
+++ ServiceManager.java 19 Feb 2007 10:50:56 -0000 1.1.2.6
@@ -22,7 +22,10 @@
package org.jboss.profiler.exp.adaptor;
+import java.io.IOException;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import javax.management.MBeanServer;
@@ -30,6 +33,9 @@
import javax.management.MBeanServerFactory;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -46,8 +52,6 @@
*/
public class ServiceManager {
- private static final String REMOTE_ADAPTER_JNDI_DEFAULT = "jmx/invoker/RMIAdaptor";
-
private static Logger logger = Logger.getLogger(ServiceManager.class);
/**
@@ -70,16 +74,16 @@
/**
* Gets an atribute of JMX service by local access
- * @param serviceName - JMX service name
+ * @param agentConfig - configuration of remote agent
* @param attributeName - attribute name of JMX service
* @return attribute value
*/
- public static Object getAttributeRemote(String adaptorJndiUrl, String serviceName, String attributeName) {
+ public static Object getAttributeRemote(AgentConfig agentConfig, String attributeName) {
Object result = null;
try {
- MBeanServerConnection mbeanServer = findMbeanServer(adaptorJndiUrl);
+ MBeanServerConnection mbeanServer = findMbeanServer(agentConfig);
if(mbeanServer==null) return result;
- result = mbeanServer.getAttribute(new ObjectName(serviceName), attributeName);
+ result = mbeanServer.getAttribute(new ObjectName(agentConfig.getServiceName()), attributeName);
}catch(Exception e) {
logger.error("failed to get an attribute of JMX service in remote.");
}
@@ -106,17 +110,16 @@
/**
* Invokes JMX service by remote access.
- * @param adaptorJndiUrl - address of remote host
- * @param serviceName - JMX service name
+ * @param agentConfig - configuration of remote agent
* @param operationName - operation name of JMX service
* @return return value of the operation
*/
- public static Object invokeRemote(String adaptorJndiUrl, String serviceName, String operationName, Object... parameters) {
+ public static Object invokeRemote(AgentConfig agentConfig, String operationName, Object... parameters) {
Object result = null;
try {
- MBeanServerConnection mbeanServer = findMbeanServer(adaptorJndiUrl);
+ MBeanServerConnection mbeanServer = findMbeanServer(agentConfig);
if(mbeanServer==null) return result;
- result = mbeanServer.invoke(new ObjectName(serviceName), operationName, parameters, classifyParameters(parameters));
+ result = mbeanServer.invoke(new ObjectName(agentConfig.getServiceName()), operationName, parameters, classifyParameters(parameters));
}catch(Exception e) {
logger.error("failed to invoke JMX service in remote.");
}
@@ -143,17 +146,16 @@
/**
* Creates the proxy object of JMX service by remote access.
- * @param adaptorJndiUrl - address of remote host
- * @param serviceName - JMX service name
+ * @param agentConfig - configuration of remote agent
* @param type - type of proxy object
* @return the proxy object
*/
- public static Object createRemoteProxy(String adaptorJndiUrl, String serviceName, Class type) {
+ public static Object createRemoteProxy(AgentConfig agentConfig, Class type) {
Object result = null;
try {
- MBeanServerConnection mbeanServer = findMbeanServer(adaptorJndiUrl);
+ MBeanServerConnection mbeanServer = findMbeanServer(agentConfig);
if(mbeanServer==null) return result;
- result = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, new ObjectName(serviceName), type, false);
+ result = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, new ObjectName(agentConfig.getServiceName()), type, false);
} catch (Exception e) {
logger.error("failed to create JMX service proxy in remote.");
}
@@ -167,14 +169,26 @@
return mbeanServer;
}
- private static MBeanServerConnection findMbeanServer(String url) throws NamingException {
+ private static MBeanServerConnection findMbeanServer(AgentConfig agentConfig) throws NamingException, IOException {
MBeanServerConnection mbeanServer = null;
+ String url = agentConfig.getJmxConnectorUrl();
+ if(url.startsWith("service:")) {
+ Map<String, String[]> environment = null;
+ if(agentConfig.getJaasUserName()!=null) {
+ environment = new HashMap<String, String[]>();
+ environment.put(JMXConnector.CREDENTIALS, new String[] {agentConfig.getJaasUserName(), agentConfig.getJaasPassword()});
+ }
+ JMXServiceURL serviceURL = new JMXServiceURL(url);
+ JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, environment);
+ mbeanServer = jmxConnector.getMBeanServerConnection();
+ }else {
+ // JBoss AS has not been supported JMXConnector yet...
Properties properties = new Properties();
- properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
- properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+ properties.put(Context.INITIAL_CONTEXT_FACTORY, agentConfig.getJmxConnectorJndiContextFactory());
properties.put(Context.PROVIDER_URL, url);
- Context ctx = new InitialContext(properties);
- mbeanServer = (MBeanServerConnection)ctx.lookup(REMOTE_ADAPTER_JNDI_DEFAULT);
+ Context context = new InitialContext(properties);
+ mbeanServer = (MBeanServerConnection)context.lookup(agentConfig.getJmxConnectorJndiName());
+ }
return mbeanServer;
}
More information about the jboss-cvs-commits
mailing list