[jboss-cvs] jboss-profiler/java/src/expansion/org/jboss/profiler/exp/adaptor ...
Takuro Okada
t2-okada at nri.co.jp
Thu Oct 26 04:58:57 EDT 2006
User: tokada
Date: 06/10/26 04:58:57
Added: java/src/expansion/org/jboss/profiler/exp/adaptor Tag:
JBossProfiler_Expansion ServiceManager.java
Log:
Revision Changes Path
No revision
No revision
1.1.2.1 +144 -0 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: ServiceManager.java
diff -N ServiceManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ServiceManager.java 26 Oct 2006 08:58:57 -0000 1.1.2.1
@@ -0,0 +1,144 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.profiler.exp.adaptor;
+
+import java.util.List;
+import java.util.Properties;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerFactory;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.log4j.Logger;
+
+/**
+ * The adaptor to connect to JMX Services.
+ *
+ * @author Takuro Okada (Nomura Research Institute, Ltd.)
+ * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
+ * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
+ * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
+ */
+public class ServiceManager {
+
+ private static final String REMOTE_ADAPTER_JNDI_DEFAULT = "jmx/invoker/RMIAdaptor";
+
+ private static Logger logger = Logger.getLogger(ServiceManager.class);
+
+ /**
+ * Invokes JMX service by local access.
+ * @param serviceName - JMX service name
+ * @param operationName - operation name of JMX service
+ * @return
+ */
+ public static Object invokeLocal(String serviceName, String operationName) {
+ Object result = null;
+ MBeanServer mbeanServer = findMbeanServer();
+ if(mbeanServer==null) return result;
+ try {
+ result = mbeanServer.invoke(new ObjectName(serviceName), operationName, null, null);
+ }catch(Exception e) {
+ logger.error("failed to invoke JMX service in local.");
+ }
+ return result;
+ }
+
+ /**
+ * Invokes JMX service by remote access.
+ * @param adaptorJndiUrl - address of remote host
+ * @param serviceName - JMX service name
+ * @param operationName - operation name of JMX service
+ * @return
+ */
+ public static Object invokeRemote(String adaptorJndiUrl, String serviceName, String operationName) {
+ Object result = null;
+ try {
+ MBeanServerConnection mbeanServer = findMbeanServer(adaptorJndiUrl);
+ if(mbeanServer==null) return result;
+ result = mbeanServer.invoke(new ObjectName(serviceName), operationName, null, null);
+ }catch(Exception e) {
+ logger.error("failed to invoke JMX service in remote.");
+ }
+ return result;
+ }
+
+ /**
+ * Create the proxy object of JMX service by local access.
+ * @param serviceName - JMX service name
+ * @param type - type of proxy object
+ * @return
+ */
+ public static Object createLocalProxy(String serviceName, Class type) {
+ Object result = null;
+ MBeanServer mbeanServer = findMbeanServer();
+ if(mbeanServer==null) return result;
+ try {
+ result = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, new ObjectName(serviceName), type, false);
+ } catch (Exception e) {
+ logger.error("failed to invoke JMX service in local.");
+ }
+ return result;
+ }
+
+ /**
+ * Create the proxy object of JMX service by remote access.
+ * @param adaptorJndiUrl - address of remote host
+ * @param serviceName - JMX service name
+ * @param type - type of proxy object
+ * @return
+ */
+ public static Object createRemoteProxy(String adaptorJndiUrl, String serviceName, Class type) {
+ Object result = null;
+ try {
+ MBeanServerConnection mbeanServer = findMbeanServer(adaptorJndiUrl);
+ if(mbeanServer==null) return result;
+ result = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, new ObjectName(serviceName), type, false);
+ } catch (Exception e) {
+ logger.error("failed to invoke JMX service in local.");
+ }
+ return result;
+ }
+
+ private static MBeanServer findMbeanServer() {
+ MBeanServer mbeanServer = null;
+ List mbeanServers = MBeanServerFactory.findMBeanServer(null);
+ if(mbeanServers.size()>0) mbeanServer = (MBeanServer)mbeanServers.get(0);
+ return mbeanServer;
+ }
+
+ private static MBeanServerConnection findMbeanServer(String url) throws NamingException {
+ MBeanServerConnection mbeanServer = null;
+ 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.PROVIDER_URL, url);
+ Context ctx = new InitialContext(properties);
+ mbeanServer = (MBeanServerConnection)ctx.lookup(REMOTE_ADAPTER_JNDI_DEFAULT);
+ return mbeanServer;
+ }
+}
More information about the jboss-cvs-commits
mailing list