[jboss-cvs] JBossAS SVN: r100966 - in branches/Branch_Hornet_Temporary_2/hornetq-int: src/main/java/org/jboss/as/integration/hornetq/jopr and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 15 09:05:23 EST 2010


Author: ataylor
Date: 2010-02-15 09:05:22 -0500 (Mon, 15 Feb 2010)
New Revision: 100966

Added:
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/EMSHelper.java
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/Invoker.java
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/JMXInvoker.java
Removed:
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanInvoker.java
Modified:
   branches/Branch_Hornet_Temporary_2/hornetq-int/pom.xml
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQComponent.java
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQDiscoveryComponent.java
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerComponent.java
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerDiscoveryComponent.java
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/MBeanComponent.java
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/resources/META-INF/rhq-plugin.xml
Log:
cleand up code, added manual add support

Modified: branches/Branch_Hornet_Temporary_2/hornetq-int/pom.xml
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/pom.xml	2010-02-15 13:17:38 UTC (rev 100965)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/pom.xml	2010-02-15 14:05:22 UTC (rev 100966)
@@ -147,6 +147,12 @@
       <version>1.4.0.B01</version>
       <scope>compile</scope>
      </dependency>
+      <dependency>
+         <groupId>org.rhq</groupId>
+         <artifactId>rhq-jmx-plugin</artifactId>
+         <version>1.4.0.B01</version>
+         <scope>provided</scope>
+      </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>

Modified: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQComponent.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQComponent.java	2010-02-15 13:17:38 UTC (rev 100965)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQComponent.java	2010-02-15 14:05:22 UTC (rev 100966)
@@ -12,18 +12,10 @@
  */
 package org.jboss.as.integration.hornetq.jopr;
 
-import org.hornetq.core.security.CheckType;
-import org.jboss.as.integration.hornetq.jopr.util.MBeanInvoker;
-import org.jboss.as.integration.hornetq.jopr.util.Operation;
-import org.jboss.as.integration.hornetq.jopr.util.ResultsFormatter;
+import org.jboss.as.integration.hornetq.jopr.util.*;
 import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertyMap;
 import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.configuration.definition.*;
 import org.rhq.core.domain.measurement.*;
-import org.rhq.core.domain.operation.OperationDefinition;
-import org.rhq.core.domain.resource.ResourceType;
 import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
 import org.rhq.core.pluginapi.inventory.ResourceComponent;
 import org.rhq.core.pluginapi.inventory.ResourceContext;
@@ -31,9 +23,6 @@
 import org.rhq.core.pluginapi.operation.OperationFacet;
 import org.rhq.core.pluginapi.operation.OperationResult;
 
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
@@ -44,26 +33,24 @@
  * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
  *         Created Feb 2, 2010
  */
-public class HornetQComponent implements ResourceComponent, MeasurementFacet, OperationFacet, MBeanComponent
+public class HornetQComponent extends MBeanComponent implements ResourceComponent, MeasurementFacet, OperationFacet
 {
-   private MBeanInvoker util;
+   private String objectName;
 
-   private ObjectName objectName;
-
    private ResultsFormatter resultsFormatter;
 
    private ResourceContext resourceContext;
 
-   private MBeanServer mBeanServer;
+   private Invoker invoker;
 
    public void getValues(final MeasurementReport report, final Set<MeasurementScheduleRequest> measurementScheduleRequests) throws Exception
    {
       for (MeasurementScheduleRequest request : measurementScheduleRequests)
       {
          Operation operation = Operation.getOperation(request.getName());
-         if(DataType.TRAIT.equals(request.getDataType()))
+         if (DataType.TRAIT.equals(request.getDataType()))
          {
-            Object attr = util.getAttribute(objectName, operation.getOperationName());
+            Object attr = invoker.getAttribute(objectName, operation.getOperationName());
             report.addData(resultsFormatter.formatMetricResults(attr, operation, resourceContext, request));
          }
       }
@@ -73,58 +60,52 @@
    {
       Operation operation = Operation.getOperation(oper);
       Collection<PropertySimple> props = configuration.getSimpleProperties().values();
-      Object o = util.invoke(objectName, operation.getOperationName(), props);
+      Object o = invoker.invoke(objectName, operation.getOperationName(), props);
       return resultsFormatter.formatResults(operation, o, resourceContext);
    }
 
    public void start(final ResourceContext resourceContext) throws InvalidPluginConfigurationException, Exception
    {
-      try
-      {
-         MBeanComponent hornetQServerComponent = (MBeanComponent) resourceContext.getParentResourceComponent();
-         mBeanServer = hornetQServerComponent.getMBeanServer();
+      MBeanComponent hornetQServerComponent = (MBeanComponent) resourceContext.getParentResourceComponent();
+      invoker = hornetQServerComponent.getInvoker();
 
-         PropertySimple objectNameProperty = resourceContext.getPluginConfiguration().getSimpleProperties().get(OBJECT_NAME);
-         PropertySimple useParentObjectName = resourceContext.getPluginConfiguration().getSimpleProperties().get(USE_PARENT_OBJECT_NAME);
-         PropertySimple resourceNameProperty = resourceContext.getPluginConfiguration().getSimpleProperties().get(RESOURCE_NAME_PROPERTY);
-         PropertySimple searchStringProperty = resourceContext.getPluginConfiguration().getSimpleProperties().get(SEARCH_STRING);
-         
-         if(objectNameProperty == null && useParentObjectName == null)
-         {
-            throw new InvalidPluginConfigurationException("objectName or useParentObjectName should be configured on service plugin " + resourceContext.getResourceKey());
-         }
+      Map<String, PropertySimple> props = resourceContext.getPluginConfiguration().getSimpleProperties();
+      PropertySimple objectNameProperty = props.get(OBJECT_NAME);
+      PropertySimple useParentObjectName = props.get(USE_PARENT_OBJECT_NAME);
+      PropertySimple resourceNameProperty = props.get(RESOURCE_NAME_PROPERTY);
+      PropertySimple searchStringProperty = props.get(SEARCH_STRING);
+      boolean useParentObject = useParentObjectName != null && (useParentObjectName.getBooleanValue() == null ? false : useParentObjectName.getBooleanValue());
 
-         String mBeanName;
-         if(useParentObjectName != null && useParentObjectName.getBooleanValue())
-         {
-            HornetQComponent hornetQComponent = (HornetQComponent) resourceContext.getParentResourceComponent();
-            mBeanName =  hornetQComponent.getObjectName().getCanonicalName(); 
-         }
-         else
-         {
-            mBeanName = objectNameProperty.getStringValue();
-         }
-         if(searchStringProperty != null)
-         {
-            objectName = new ObjectName(mBeanName + "," + resourceNameProperty.getStringValue() + "=" + resourceContext.getResourceKey().split(":")[1]);
-         }
-         else
-         {
-            objectName = new ObjectName(mBeanName);
-         }
-         util = new MBeanInvoker(mBeanServer);
-         this.resourceContext = resourceContext;
-         resultsFormatter = new ResultsFormatter();
+      if (objectNameProperty == null && useParentObjectName == null)
+      {
+         throw new InvalidPluginConfigurationException("objectName or useParentObjectName should be configured on service plugin " + resourceContext.getResourceKey());
       }
-      catch (Throwable e)
+
+      String mBeanName;
+      if (useParentObject)
       {
-         e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+         HornetQComponent hornetQComponent = (HornetQComponent) resourceContext.getParentResourceComponent();
+         mBeanName = hornetQComponent.getObjectName();
       }
+      else
+      {
+         mBeanName = objectNameProperty.getStringValue();
+      }
+      if (searchStringProperty != null)
+      {
+         objectName = mBeanName + "," + resourceNameProperty.getStringValue() + "=" + resourceContext.getResourceKey().split(":")[1];
+      }
+      else
+      {
+         objectName = mBeanName;
+      }
+      this.resourceContext = resourceContext;
+      resultsFormatter = new ResultsFormatter();
    }
 
    public void stop()
    {
-      mBeanServer = null;
+      invoker = null;
    }
 
    public AvailabilityType getAvailability()
@@ -132,15 +113,16 @@
       return AvailabilityType.UP;
    }
 
-   public MBeanServer getMBeanServer()
+
+   public String getObjectName()
    {
-      return mBeanServer;
+      return objectName;
    }
 
-
-   public ObjectName getObjectName()
+   @Override
+   Invoker getInvoker()
    {
-      return objectName;
+      return invoker;
    }
 
    /*private static OperationDefinition getOperationDefinition(final String operationName, final ResourceContext resourceContext)

Modified: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQDiscoveryComponent.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQDiscoveryComponent.java	2010-02-15 13:17:38 UTC (rev 100965)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQDiscoveryComponent.java	2010-02-15 14:05:22 UTC (rev 100966)
@@ -12,16 +12,18 @@
  */
 package org.jboss.as.integration.hornetq.jopr;
 
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertyMap;
+import org.jboss.as.integration.hornetq.jopr.util.EMSHelper;
+import org.jboss.as.integration.hornetq.jopr.util.Invoker;
+import org.jboss.as.integration.hornetq.jopr.util.JMXInvoker;
+import org.mc4j.ems.connection.bean.EmsBean;
 import org.rhq.core.domain.configuration.PropertySimple;
 import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
 import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
 
-import javax.management.*;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -38,10 +40,12 @@
    {
       Set<DiscoveredResourceDetails> set = new HashSet<DiscoveredResourceDetails>();
 
-      PropertySimple objectNameProperty = ctx.getDefaultPluginConfiguration().getSimpleProperties().get(OBJECT_NAME);
-      PropertySimple useParentObjectName = ctx.getDefaultPluginConfiguration().getSimpleProperties().get(USE_PARENT_OBJECT_NAME);
-      PropertySimple resourceNameProperty = ctx.getDefaultPluginConfiguration().getSimpleProperties().get(RESOURCE_NAME_PROPERTY);
-      PropertySimple searchStringProperty = ctx.getDefaultPluginConfiguration().getSimpleProperties().get(SEARCH_STRING);
+      Map<String, PropertySimple> props = ctx.getDefaultPluginConfiguration().getSimpleProperties();
+      PropertySimple objectNameProperty = props.get(OBJECT_NAME);
+      PropertySimple useParentObjectName = props.get(USE_PARENT_OBJECT_NAME);
+      PropertySimple resourceNameProperty = props.get(RESOURCE_NAME_PROPERTY);
+      PropertySimple searchStringProperty = props.get(SEARCH_STRING);
+      boolean useParentObject = useParentObjectName != null && (useParentObjectName.getBooleanValue() == null ? false : useParentObjectName.getBooleanValue());
 
       if (objectNameProperty == null && useParentObjectName == null)
       {
@@ -50,23 +54,23 @@
 
       if (searchStringProperty != null)
       {
-         ObjectName name;
-         if(useParentObjectName != null && useParentObjectName.getBooleanValue())
+         String name;
+         if(useParentObject)
          {
             HornetQComponent hornetQComponent = (HornetQComponent) ctx.getParentResourceComponent();
-            name = new ObjectName(hornetQComponent.getObjectName() + "," + searchStringProperty.getStringValue());
+            name = hornetQComponent.getObjectName() + "," + searchStringProperty.getStringValue();
          }
          else
          {
             String mBeanName = objectNameProperty.getStringValue();
-            name = new ObjectName(mBeanName + "," + searchStringProperty.getStringValue());
+            name = mBeanName + "," + searchStringProperty.getStringValue();
          }
-
-         MBeanServer beanServer = org.jboss.mx.util.MBeanServerLocator.locate();
-         Set<ObjectInstance> objectInstances = beanServer.queryMBeans(name, null);
-         for (ObjectInstance instance : objectInstances)
+         EMSHelper emsHelper = new EMSHelper();
+         Invoker invoker = new JMXInvoker(emsHelper.loadConnection(ctx.getDefaultPluginConfiguration()));
+         List<EmsBean> beans = invoker.query(name);
+         for (EmsBean bean : beans)
          {
-            String resourceName = instance.getObjectName().getKeyProperty(resourceNameProperty.getStringValue());
+            String resourceName = bean.getBeanName().getKeyProperty(resourceNameProperty.getStringValue());
             String resourceKey = ctx.getResourceType().getName() + ":" + resourceName;
             System.out.println("resourceKey = " + resourceKey);
             DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
@@ -94,6 +98,8 @@
             );
          set.add(detail);
       }
+
+
       return set;
 
    }

Modified: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerComponent.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerComponent.java	2010-02-15 13:17:38 UTC (rev 100965)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerComponent.java	2010-02-15 14:05:22 UTC (rev 100966)
@@ -12,27 +12,25 @@
  */
 package org.jboss.as.integration.hornetq.jopr;
 
-import org.rhq.core.domain.configuration.Configuration;
+import org.jboss.as.integration.hornetq.jopr.util.EMSHelper;
+import org.jboss.as.integration.hornetq.jopr.util.Invoker;
+import org.jboss.as.integration.hornetq.jopr.util.JMXInvoker;
 import org.rhq.core.domain.measurement.*;
 import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
 import org.rhq.core.pluginapi.inventory.ResourceComponent;
 import org.rhq.core.pluginapi.inventory.ResourceContext;
 import org.rhq.core.pluginapi.measurement.MeasurementFacet;
-import org.rhq.core.pluginapi.operation.OperationFacet;
-import org.rhq.core.pluginapi.operation.OperationResult;
-
-import javax.management.MBeanServer;
 import java.util.Set;
 
 /**
  * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
  *         Created Jan 26, 2010
  */
-public class HornetQServerComponent implements ResourceComponent, MeasurementFacet,  MBeanComponent
+public class HornetQServerComponent extends MBeanComponent implements ResourceComponent, MeasurementFacet
 {
    private ResourceContext resourceContext;
 
-   private MBeanServer mBeanServer;
+   private Invoker invoker;
 
    public void getValues(final MeasurementReport report, final Set<MeasurementScheduleRequest> measurementScheduleRequests) throws Exception
    {
@@ -51,7 +49,8 @@
    public void start(final ResourceContext resourceContext) throws InvalidPluginConfigurationException, Exception
    {
       this.resourceContext = resourceContext;
-      mBeanServer = org.jboss.mx.util.MBeanServerLocator.locate();
+      EMSHelper emsHelper = new EMSHelper();
+      invoker = new JMXInvoker(emsHelper.loadConnection(resourceContext.getPluginConfiguration()));
    }
 
    public void stop()
@@ -64,8 +63,9 @@
      return AvailabilityType.UP;
    }
 
-   public MBeanServer getMBeanServer()
+   @Override
+   public Invoker getInvoker()
    {
-      return mBeanServer;
+      return invoker;
    }
 }

Modified: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerDiscoveryComponent.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerDiscoveryComponent.java	2010-02-15 13:17:38 UTC (rev 100965)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerDiscoveryComponent.java	2010-02-15 14:05:22 UTC (rev 100966)
@@ -12,20 +12,14 @@
  */
 package org.jboss.as.integration.hornetq.jopr;
 
-import org.jboss.deployers.spi.management.ManagementView;
-import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.as.integration.hornetq.jopr.util.EMSHelper;
+import org.jboss.as.integration.hornetq.jopr.util.Invoker;
+import org.jboss.as.integration.hornetq.jopr.util.JMXInvoker;
 import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
-import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
-import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
-import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.pluginapi.inventory.*;
+import org.rhq.plugins.jmx.JMXDiscoveryComponent;
 
-import javax.management.*;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-import javax.naming.InitialContext;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -33,14 +27,18 @@
  * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
  *         Created Jan 26, 2010
  */
-public class HornetQServerDiscoveryComponent implements ResourceDiscoveryComponent<HornetQServerComponent>
+public class HornetQServerDiscoveryComponent implements ResourceDiscoveryComponent<HornetQServerComponent>, ManualAddFacet
 {
+   private static final String ORG_HORNETQ_MODULE_JMS_TYPE_SERVER = "org.hornetq:module=JMS,type=Server";
+
    public Set<DiscoveredResourceDetails> discoverResources(final ResourceDiscoveryContext<HornetQServerComponent> ctx) throws InvalidPluginConfigurationException, Exception
    {
-      ObjectName name = new ObjectName("org.hornetq:module=JMS,type=Server");
-      MBeanServer beanServer = org.jboss.mx.util.MBeanServerLocator.locate();
-      String version = (String) beanServer.getAttribute(name, "Version");
+
       Set<DiscoveredResourceDetails> set = new HashSet<DiscoveredResourceDetails>();
+
+      EMSHelper emsHelper = new EMSHelper();
+      Invoker invoker = new JMXInvoker(emsHelper.loadConnection(ctx.getDefaultPluginConfiguration()));
+      String version = (String) invoker.getAttribute(ORG_HORNETQ_MODULE_JMS_TYPE_SERVER, "Version");
       Configuration c = new Configuration();
       DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
                ctx.getResourceType(), // Resource type
@@ -54,4 +52,30 @@
       set.add(detail);
       return set;
    }
+
+   public DiscoveredResourceDetails discoverResource(Configuration configuration, ResourceDiscoveryContext ctx) throws InvalidPluginConfigurationException
+   {
+      try
+      {
+         EMSHelper emsHelper = new EMSHelper();
+         Invoker invoker = new JMXInvoker(emsHelper.loadConnection(ctx.getDefaultPluginConfiguration()));
+         String version = (String) invoker.getAttribute(ORG_HORNETQ_MODULE_JMS_TYPE_SERVER, "Version");
+         Configuration c = new Configuration();
+         PropertySimple serverUrl = ctx.getDefaultPluginConfiguration()
+                  .getSimple(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY);
+         return new DiscoveredResourceDetails(
+                  ctx.getResourceType(), // Resource type
+                  "HornetQServer" + serverUrl.getStringValue(), // Resource key
+                  "HornetQ Remote Server " + serverUrl.getStringValue(), // Resource name
+                  version, // Resource version
+                  "HornetQ Remote Server", // Description
+                  c, // Plugin config
+                  null // Process info from a process scan
+            );
+      }
+      catch (Exception e)
+      {
+         throw new InvalidPluginConfigurationException(e);
+      }
+   }
 }

Modified: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/MBeanComponent.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/MBeanComponent.java	2010-02-15 13:17:38 UTC (rev 100965)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/MBeanComponent.java	2010-02-15 14:05:22 UTC (rev 100966)
@@ -1,12 +1,57 @@
 package org.jboss.as.integration.hornetq.jopr;
 
-import javax.management.MBeanServer;
+import org.jboss.as.integration.hornetq.jopr.util.Invoker;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 
 /**
  * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
  *         Created Feb 11, 2010
  */
-public interface MBeanComponent
+public abstract class MBeanComponent
 {
-   MBeanServer getMBeanServer();
+   abstract Invoker getInvoker();
+
+   public static Object getInstance(String classname) throws ClassNotFoundException, IllegalAccessException, InstantiationException
+   {
+      if (classname == null) throw new IllegalArgumentException("Cannot load null class!");
+      Class clazz = loadClass(classname);
+      return getInstance(clazz);
+   }
+
+   public static Class loadClass(String classname) throws ClassNotFoundException
+   {
+      ClassLoader cl = Thread.currentThread().getContextClassLoader();
+      if (cl == null)
+         cl = ClassLoader.getSystemClassLoader();
+      return cl.loadClass(classname);
+   }
+
+   public static <T> T getInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException
+   {
+      // first look for a getInstance() constructor
+      T instance = null;
+      try
+      {
+         Method factoryMethod = getFactoryMethod(clazz);
+         if (factoryMethod != null) instance = (T) factoryMethod.invoke(null);
+      }
+      catch (Exception e)
+      {
+         // no factory method or factory method failed.  Try a constructor.
+         instance = null;
+      }
+      if (instance == null) instance = clazz.newInstance();
+      return instance;
+   }
+
+   private static Method getFactoryMethod(Class c)
+   {
+      for (Method m : c.getMethods())
+      {
+         if (m.getName().equals("getInstance") && m.getParameterTypes().length == 0 && Modifier.isStatic(m.getModifiers()))
+            return m;
+      }
+      return null;
+   }
 }

Added: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/EMSHelper.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/EMSHelper.java	                        (rev 0)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/EMSHelper.java	2010-02-15 14:05:22 UTC (rev 100966)
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+package org.jboss.as.integration.hornetq.jopr.util;
+
+import org.mc4j.ems.connection.ConnectionFactory;
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.settings.ConnectionSettings;
+import org.mc4j.ems.connection.support.ConnectionProvider;
+import org.mc4j.ems.connection.support.metadata.ConnectionTypeDescriptor;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.plugins.jmx.JMXDiscoveryComponent;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ *         Created Feb 12, 2010
+ */
+public class EMSHelper
+{
+   private static String INVM_TRANSPORT_TYPE = "org.mc4j.ems.connection.support.metadata.InternalVMTypeDescriptor";
+
+   private static String REMOTE_TRANSPORT_TYPE = "org.mc4j.ems.connection.support.metadata.J2SE5ConnectionTypeDescriptor";
+
+   EmsConnection connection = null;
+
+   public synchronized EmsConnection loadConnection(Configuration pluginConfig) throws Exception
+   {
+      if (this.connection == null)
+      {
+         try
+         {
+            //Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
+
+            ConnectionSettings connectionSettings = new ConnectionSettings();
+
+            PropertySimple serverUrl = pluginConfig
+                  .getSimple(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY);
+            String connectionType;
+            if(serverUrl != null && serverUrl.getStringValue() != null)
+            {
+               connectionType = REMOTE_TRANSPORT_TYPE;
+               connectionSettings.setServerUrl(serverUrl.getStringValue());
+            }
+            else
+            {
+               connectionType = INVM_TRANSPORT_TYPE;
+            }
+            connectionSettings.initializeConnectionType((ConnectionTypeDescriptor) getInstance(
+                  connectionType));
+
+            /*if (connectionSettings.getAdvancedProperties() == null)
+            {
+               connectionSettings.setAdvancedProperties(new Properties());
+            }*/
+
+            ConnectionFactory connectionFactory = new ConnectionFactory();
+
+
+            ConnectionProvider connectionProvider = connectionFactory.getConnectionProvider(connectionSettings);
+            this.connection = connectionProvider.connect();
+
+            this.connection.loadSynchronous(false); // this loads all the MBeans
+
+            System.out.println("connectionProvider = " + connectionProvider.getClass().getName());
+         }
+         catch (Exception e)
+         {
+
+            // The connection will be established even in the case that the principal cannot be authenticated,
+            // but the connection will not work. That failure seems to come from the call to loadSynchronous after
+            // the connection is established. If we get to this point that an exception was thrown, close any
+            // connection that was made and null it out so we can try to establish it again.
+            if (connection != null)
+            {
+               connection.close();
+               connection = null;
+            }
+
+            throw e;
+         }
+      }
+
+      return connection;
+   }
+
+   public static Object getInstance(String classname) throws ClassNotFoundException, IllegalAccessException, InstantiationException
+   {
+      if (classname == null) throw new IllegalArgumentException("Cannot load null class!");
+      Class clazz = loadClass(classname);
+      return getInstance(clazz);
+   }
+
+   public static Class loadClass(String classname) throws ClassNotFoundException
+   {
+      ClassLoader cl = Thread.currentThread().getContextClassLoader();
+      if (cl == null)
+         cl = ClassLoader.getSystemClassLoader();
+      return cl.loadClass(classname);
+   }
+
+   public static <T> T getInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException
+   {
+      // first look for a getInstance() constructor
+      T instance = null;
+      try
+      {
+         Method factoryMethod = getFactoryMethod(clazz);
+         if (factoryMethod != null) instance = (T) factoryMethod.invoke(null);
+      }
+      catch (Exception e)
+      {
+         // no factory method or factory method failed.  Try a constructor.
+         instance = null;
+      }
+      if (instance == null) instance = clazz.newInstance();
+      return instance;
+   }
+
+   private static Method getFactoryMethod(Class c)
+   {
+      for (Method m : c.getMethods())
+      {
+         if (m.getName().equals("getInstance") && m.getParameterTypes().length == 0 && Modifier.isStatic(m.getModifiers()))
+            return m;
+      }
+      return null;
+   }
+
+
+}

Added: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/Invoker.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/Invoker.java	                        (rev 0)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/Invoker.java	2010-02-15 14:05:22 UTC (rev 100966)
@@ -0,0 +1,22 @@
+package org.jboss.as.integration.hornetq.jopr.util;
+
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.mc4j.ems.connection.bean.operation.EmsOperation;
+import org.rhq.core.domain.configuration.PropertySimple;
+
+import javax.management.ObjectName;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ *         Created Feb 12, 2010
+ */
+public interface Invoker
+{
+   public Object invoke(final String objectName, final String oper, final Collection<PropertySimple> props) throws Exception;
+
+   public Object getAttribute(final String objectName, final String attr) throws Exception;
+
+   List<EmsBean> query(String name);
+}

Added: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/JMXInvoker.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/JMXInvoker.java	                        (rev 0)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/JMXInvoker.java	2010-02-15 14:05:22 UTC (rev 100966)
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+package org.jboss.as.integration.hornetq.jopr.util;
+
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
+import org.mc4j.ems.connection.bean.operation.EmsOperation;
+import org.rhq.core.domain.configuration.PropertySimple;
+
+import javax.management.ObjectName;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ *         Created Feb 12, 2010
+ */
+public class JMXInvoker implements Invoker
+{
+   EmsConnection connection;
+
+
+   public JMXInvoker(EmsConnection connection)
+   {
+      this.connection = connection;
+   }
+
+   public Object invoke(final String objectName, final String oper, final Collection<PropertySimple> props) throws Exception
+   {
+      Object[] params = new Object[props.size()];
+      Class[] signature = new Class[props.size()];
+      populateParams(props, params, signature);
+      EmsBean bean = connection.getBean(objectName);
+      EmsOperation ops = bean.getOperation(oper, signature);
+      return ops.invoke(params);
+   }
+
+   public Object getAttribute(final String objectName, final String attr) throws Exception
+   {
+      EmsBean bean = connection.getBean(objectName);
+      EmsAttribute attribute = bean.getAttribute(attr);
+      return attribute.getValue();
+   }
+
+   public List<EmsBean> query(String name)
+   {
+      return connection.queryBeans(name);
+   }
+
+   private static void populateParams(final Collection<PropertySimple> props, final Object[] params, final Class[] signature)
+   {
+      int pos = 0;
+      for (PropertySimple prop : props)
+      {
+         String[] val = prop.getName().split(":");
+         if(val.length == 1)
+         {
+            params[pos] = prop.getStringValue();
+            signature[pos] = java.lang.String.class;
+         }
+         else
+         {
+            if(val[0].equals("Boolean"))
+            {
+               params[pos] = prop.getBooleanValue();
+               signature[pos] = java.lang.Boolean.class;
+            }
+            else if(val[0].equals("boolean"))
+            {
+               params[pos] = prop.getBooleanValue();
+               signature[pos] = boolean.class;
+            }
+            else if(val[0].equals("String"))
+            {
+               params[pos] = prop.getStringValue();
+               signature[pos] = java.lang.String.class;
+            }
+         }
+         pos++;
+      }
+   }
+}

Deleted: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanInvoker.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanInvoker.java	2010-02-15 13:17:38 UTC (rev 100965)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanInvoker.java	2010-02-15 14:05:22 UTC (rev 100966)
@@ -1,81 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *    http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.  See the License for the specific language governing
- * permissions and limitations under the License.
- */
-package org.jboss.as.integration.hornetq.jopr.util;
-
-import org.jboss.mx.util.MBeanServerLocator;
-import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertySimple;
-
-import javax.management.MBeanInfo;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import java.util.Collection;
-
-/**
- * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
- *         Created Jan 26, 2010
- */
-public class MBeanInvoker
-{
-   private MBeanServer beanServer;
-
-   public MBeanInvoker(MBeanServer mBeanServer)
-   {
-      beanServer = mBeanServer;
-   }
-
-   public Object invoke(final ObjectName objectName, final String oper, final Collection<PropertySimple> props) throws Exception
-   {
-      Object[] params = new Object[props.size()];
-      String[] signature = new String[props.size()];
-      populateParams(props, params, signature);
-      return beanServer.invoke(objectName, oper, params, signature);
-   }
-
-   public Object getAttribute(final ObjectName objectName, final String attr) throws Exception
-   {
-      return beanServer.getAttribute(objectName, attr);
-   }
-   private static void populateParams(final Collection<PropertySimple> props, final Object[] params, final String[] signature)
-   {
-      int pos = 0;
-      for (PropertySimple prop : props)
-      {
-         String[] val = prop.getName().split(":");
-         if(val.length == 1)
-         {
-            params[pos] = prop.getStringValue();
-            signature[pos] = "java.lang.String";
-         }
-         else
-         {
-            if(val[0].equals("Boolean"))
-            {
-               params[pos] = prop.getBooleanValue();
-               signature[pos] = "java.lang.Boolean";
-            }
-            else if(val[0].equals("boolean"))
-            {
-               params[pos] = prop.getBooleanValue();
-               signature[pos] = "boolean";
-            }
-            else if(val[0].equals("String"))
-            {
-               params[pos] = prop.getStringValue();
-               signature[pos] = "java.lang.String";
-            }
-         }
-         pos++;
-      }
-   }
-}

Modified: branches/Branch_Hornet_Temporary_2/hornetq-int/src/resources/META-INF/rhq-plugin.xml
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/resources/META-INF/rhq-plugin.xml	2010-02-15 13:17:38 UTC (rev 100965)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/resources/META-INF/rhq-plugin.xml	2010-02-15 14:05:22 UTC (rev 100966)
@@ -55,6 +55,7 @@
         displayName="HornetQPlugin"
         description="Supports management and monitoring of HornetQ Servers"
         package="org.jboss.as.integration.hornetq.jopr"
+        version="2.1.5"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="urn:xmlns:rhq-plugin"
         xmlns:c="urn:xmlns:rhq-configuration">
@@ -63,7 +64,8 @@
 
       <server name="HornetQ Server"
             discovery="HornetQServerDiscoveryComponent"
-            class="HornetQServerComponent"
+            class="HornetQServerComponent"   
+            singleton="true"
             supportsManualAdd="true">
          <subcategories>
             <subcategory name="JMS"
@@ -74,10 +76,10 @@
             </subcategory>
         </subcategories>
          <plugin-configuration>
-                <c:simple-property name="connectorAddress" description="JMX Remoting address of the remote HornetQ Instance"  />
+                <c:simple-property name="connectorAddress" required="false" description="JMX Remoting address of the remote HornetQ Instance (leave blank for InVM)"  />
                 <!-- The template section is only for manual resource additions, and default parameters and the ones presented to the user. -->
-                <c:template name="defaultManualDiscovery" description="The default setup for HornetQ">
-                  <c:simple-property name="connectorAddress" displayName="URL of the remote server"
+                <c:template name="HornetQRemoteDiscovery" description="The default setup for HornetQ">
+                  <c:simple-property name="connectorAddress" displayName="URL of the remote server using (service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1090/jmxconnector)"
                                      defaultValue="service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1090/jmxconnector"/>
                 </c:template>
          </plugin-configuration>




More information about the jboss-cvs-commits mailing list