[jboss-cvs] jboss-profiler/java/src/expansion/org/jboss/profiler/adaptor ...

Takuro Okada t2-okada at nri.co.jp
Wed Apr 11 07:13:11 EDT 2007


  User: tokada  
  Date: 07/04/11 07:13:11

  Added:       java/src/expansion/org/jboss/profiler/adaptor   Tag:
                        JBossProfiler_Expansion ServiceManager.java
                        AgentConfig.java
  Log:
  Moved to another directory
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +203 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/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	11 Apr 2007 11:13:11 -0000	1.1.2.1
  @@ -0,0 +1,203 @@
  +/*
  + * 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.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;
  +import javax.management.MBeanServerConnection;
  +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;
  +
  +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 Logger logger = Logger.getLogger(ServiceManager.class);
  +    
  +    /**
  +     * Gets an atribute of JMX service by local access
  +     * @param serviceName - JMX service name
  +     * @param attributeName - attribute name of JMX service
  +     * @return attribute value
  +     */
  +    public static Object getAttributeLocal(String serviceName, String attributeName) {
  +        Object result = null;
  +        MBeanServer mbeanServer = findMbeanServer();
  +        if(mbeanServer==null) return result;
  +        try {
  +            result = mbeanServer.getAttribute(new ObjectName(serviceName), attributeName);
  +        }catch(Exception e) {
  +            logger.error("failed to get an attribute of JMX service in local.");
  +        }
  +        return result;
  +    }
  +    
  +    /**
  +     * Gets an atribute of JMX service by local access
  +     * @param agentConfig - configuration of remote agent
  +     * @param attributeName - attribute name of JMX service
  +     * @return attribute value
  +     */
  +    public static Object getAttributeRemote(AgentConfig agentConfig, String attributeName) {
  +        Object result = null;
  +        try {
  +            MBeanServerConnection mbeanServer = findMbeanServer(agentConfig);
  +            if(mbeanServer==null) return result;
  +            result = mbeanServer.getAttribute(new ObjectName(agentConfig.getServiceName()), attributeName);
  +        }catch(Exception e) {
  +            logger.error("failed to get an attribute of JMX service in remote.");
  +        }
  +        return result;
  +    }
  +    
  +    /**
  +     * Invokes JMX service by local access.
  +     * @param serviceName - JMX service name
  +     * @param operationName - operation name of JMX service
  +     * @return return value of the operation
  +     */
  +    public static Object invokeLocal(String serviceName, String operationName, Object... parameters) {
  +        Object result = null;
  +        MBeanServer mbeanServer = findMbeanServer();
  +        if(mbeanServer==null) return result;
  +        try {
  +            result = mbeanServer.invoke(new ObjectName(serviceName), operationName, parameters, classifyParameters(parameters));
  +        }catch(Exception e) {
  +            logger.error("failed to invoke JMX service in local.");
  +        }
  +        return result;
  +    }
  +    
  +    /**
  +     * Invokes JMX service by remote access.
  +     * @param agentConfig - configuration of remote agent
  +     * @param operationName - operation name of JMX service
  +     * @return return value of the operation
  +     */
  +    public static Object invokeRemote(AgentConfig agentConfig, String operationName, Object... parameters) {
  +        Object result = null;
  +        try {
  +            MBeanServerConnection mbeanServer = findMbeanServer(agentConfig);
  +            if(mbeanServer==null) return result;
  +            result = mbeanServer.invoke(new ObjectName(agentConfig.getServiceName()), operationName, parameters, classifyParameters(parameters));
  +        }catch(Exception e) {
  +            logger.error("failed to invoke JMX service in remote.");
  +        }
  +        return result;
  +    }
  +    
  +    /**
  +     * Creates the proxy object of JMX service by local access.
  +     * @param serviceName - JMX service name
  +     * @param type - type of proxy object
  +     * @return the proxy object
  +     */
  +    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 create JMX service proxy in local.");
  +        }
  +        return result;
  +    }
  +    
  +    /**
  +     * Creates the proxy object of JMX service by remote access.
  +     * @param agentConfig - configuration of remote agent
  +     * @param type - type of proxy object
  +     * @return the proxy object
  +     */
  +    public static Object createRemoteProxy(AgentConfig agentConfig, Class type) {
  +        Object result = null;
  +        try {
  +            MBeanServerConnection mbeanServer = findMbeanServer(agentConfig);
  +            if(mbeanServer==null) return result;
  +            result = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, new ObjectName(agentConfig.getServiceName()), type, false);
  +        } catch (Exception e) {
  +            logger.error("failed to create JMX service proxy in remote.");
  +        }
  +        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(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, agentConfig.getJmxConnectorJndiContextFactory());
  +            properties.put(Context.PROVIDER_URL, url);
  +            Context context = new InitialContext(properties);
  +            mbeanServer = (MBeanServerConnection)context.lookup(agentConfig.getJmxConnectorJndiName());
  +        }
  +        return mbeanServer;
  +    }
  +    
  +    private static String[] classifyParameters(Object[] parameters) {
  +        String[] result = new String[parameters.length];
  +        for(int i=0; i<parameters.length; i++) {
  +            result[i] = parameters[i].getClass().getName();
  +        }
  +        return result;
  +    }
  +
  +}
  
  
  
  1.1.2.1   +81 -0     jboss-profiler/java/src/expansion/org/jboss/profiler/adaptor/Attic/AgentConfig.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AgentConfig.java
  ===================================================================
  RCS file: AgentConfig.java
  diff -N AgentConfig.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ AgentConfig.java	11 Apr 2007 11:13:11 -0000	1.1.2.1
  @@ -0,0 +1,81 @@
  +/*
  + * 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.adaptor;
  +
  +import java.io.Serializable;
  +
  +/**
  + * The connection information of the remote agent.
  + * 
  + * @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 AgentConfig implements Serializable {
  +    private String serviceName;
  +    private String jmxConnectorUrl;
  +    private String jmxConnectorJndiName;
  +    private String jmxConnectorJndiContextFactory;
  +    private String jaasUserName;
  +    private String jaasPassword;
  +    
  +    public String getJaasPassword() {
  +        return jaasPassword;
  +    }
  +    public void setJaasPassword(String jaasPassword) {
  +        this.jaasPassword = jaasPassword;
  +    }
  +    public String getJaasUserName() {
  +        return jaasUserName;
  +    }
  +    public void setJaasUserName(String jaasUserName) {
  +        this.jaasUserName = jaasUserName;
  +    }
  +    public String getJmxConnectorJndiContextFactory() {
  +        return jmxConnectorJndiContextFactory;
  +    }
  +    public void setJmxConnectorJndiContextFactory(
  +            String jmxConnectorJndiContextFactory) {
  +        this.jmxConnectorJndiContextFactory = jmxConnectorJndiContextFactory;
  +    }
  +    public String getJmxConnectorJndiName() {
  +        return jmxConnectorJndiName;
  +    }
  +    public void setJmxConnectorJndiName(String jmxConnectorJndiName) {
  +        this.jmxConnectorJndiName = jmxConnectorJndiName;
  +    }
  +    public String getJmxConnectorUrl() {
  +        return jmxConnectorUrl;
  +    }
  +    public void setJmxConnectorUrl(String jmxConnectorUrl) {
  +        this.jmxConnectorUrl = jmxConnectorUrl;
  +    }
  +    public String getServiceName() {
  +        return serviceName;
  +    }
  +    public void setServiceName(String serviceName) {
  +        this.serviceName = serviceName;
  +    }
  +
  +}
  
  
  



More information about the jboss-cvs-commits mailing list