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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 9 13:34:44 EST 2010


Author: ataylor
Date: 2010-02-09 13:34:44 -0500 (Tue, 09 Feb 2010)
New Revision: 100769

Added:
   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/Operation.java
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/ResultsFormatter.java
Removed:
   branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanUtil.java
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/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/resources/META-INF/rhq-plugin.xml
Log:
added new hornetq component and tidied up abstraction

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-09 18:19:49 UTC (rev 100768)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQComponent.java	2010-02-09 18:34:44 UTC (rev 100769)
@@ -12,7 +12,10 @@
  */
 package org.jboss.as.integration.hornetq.jopr;
 
-import org.jboss.as.integration.hornetq.jopr.util.MBeanUtil;
+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.rhq.core.domain.configuration.Configuration;
 import org.rhq.core.domain.configuration.PropertyList;
 import org.rhq.core.domain.configuration.PropertySimple;
@@ -27,9 +30,9 @@
 import org.rhq.core.pluginapi.operation.OperationFacet;
 import org.rhq.core.pluginapi.operation.OperationResult;
 
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -39,7 +42,7 @@
  */
 public class HornetQComponent implements ResourceComponent, MeasurementFacet, OperationFacet
 {
-   private MBeanUtil util;
+   private MBeanInvoker util;
 
    private ObjectName objectName;
 
@@ -47,34 +50,17 @@
 
    private ResourceContext resourceContext;
 
+   private MBeanServer mBeanServer;
+
    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()))
          {
-            Object attr = util.getAttribute(objectName, request.getName());
-            String data;
-            if(attr instanceof Object[])
-            {
-               Object[] objects = (Object[]) attr;
-               StringBuilder sb = new StringBuilder();
-               for (int i = 0, objectsLength = objects.length; i < objectsLength; i++)
-               {
-                  Object object = objects[i];
-                  if(i > 0)
-                  {
-                     sb.append(", ");
-                  }
-                  sb.append(object.toString());
-               }
-               data = sb.toString();
-            }
-            else
-            {
-               data = attr == null?null:attr.toString();
-            }
-            report.addData(new MeasurementDataTrait(request, data));
+            Object attr = util.getAttribute(objectName, operation.getOperationName());
+            report.addData(resultsFormatter.formatMetricResults(attr, operation, resourceContext, request));
          }
       }
    }
@@ -89,6 +75,8 @@
 
    public void start(final ResourceContext resourceContext) throws InvalidPluginConfigurationException, Exception
    {
+      HornetQServerComponent hornetQServerComponent = (HornetQServerComponent) resourceContext.getParentResourceComponent();
+      mBeanServer = hornetQServerComponent.getMBeanServer();
       PropertySimple objectNameProperty = resourceContext.getPluginConfiguration().getSimpleProperties().get("objectName");
       if(objectNameProperty == null)
       {
@@ -105,7 +93,7 @@
       {
          objectName = new ObjectName(mBeanName);
       }
-      util = new MBeanUtil();
+      util = new MBeanInvoker(mBeanServer);
       this.resourceContext = resourceContext;
       resultsFormatter = new ResultsFormatter();
    }
@@ -120,158 +108,7 @@
       return AvailabilityType.UP;
    }
 
-   static class Operation
-   {
-      final private String operationName;
-      final private String resultsType;
 
-      Operation(String operationName, String resultsType)
-      {
-         this.operationName = operationName;
-         this.resultsType = resultsType;
-      }
-
-      public String getOperationName()
-      {
-         return operationName;
-      }
-
-      public String getResultsType()
-      {
-         return resultsType;
-      }
-
-      static Operation getOperation(String oper)
-      {
-         String[] split = oper.split(",", 3);
-         String operationName = split[0];
-         String resultsType = null;
-         for (int i = 1, splitLength = split.length; i < splitLength; i++)
-         {
-            String s = split[i];
-            if(s.startsWith("operation"))
-            {
-               operationName = s.substring(s.indexOf("=") + 1);
-            }
-            else if(s.startsWith("result"))
-            {
-               resultsType = s.substring(s.indexOf("=") + 1);
-            }
-         }
-         return new Operation(operationName, resultsType);
-      }
-   }
-
-   static class ResultsFormatter
-   {
-      OperationResult formatResults(final Operation oper, final Object result, final ResourceContext resourceContext)
-      {
-         if (result == null)
-         {
-            return null;
-         }
-         else
-         {
-
-            if (oper.getResultsType() == null)
-            {
-               return formatStringResults(result.toString());
-            }
-            else
-            {
-               if ("String".equalsIgnoreCase(oper.getResultsType()))
-               {
-                  return formatStringResults(result.toString());
-               }
-               else if ("JMSMessage".equalsIgnoreCase(oper.getResultsType()))
-               {
-                  return formatJmsMessageResults(result);
-               }
-               else if ("String[]".equalsIgnoreCase(oper.getResultsType()))
-               {
-                  return formatStringArrayResults(result);
-               }
-               else if ("SubscriptionInfo".equalsIgnoreCase(oper.getResultsType()))
-               {
-                  return formatSubscriptionInfoResults(result);
-               }
-               else
-               {
-                  return formatStringResults(result.toString());
-               }
-            }
-         }
-      }
-
-      OperationResult formatStringResults(final Object result)
-      {
-         return new OperationResult((String) result);
-      }
-
-      OperationResult formatJmsMessageResults(final Object result)
-      {
-         OperationResult operationResult = new OperationResult();
-         Configuration c = operationResult.getComplexResults();
-         PropertyList property = new PropertyList("result");
-         Map[] map = (Map[]) result;
-         for (Map map1 : map)
-         {
-            org.rhq.core.domain.configuration.PropertyMap p1 = new org.rhq.core.domain.configuration.PropertyMap("element");
-            property.add(p1);
-            for (Object o1 : map1.keySet())
-            {
-               p1.put(new PropertySimple((String) o1, map1.get(o1)));
-            }
-         }
-         c.put(property);
-         return operationResult;
-      }
-
-      OperationResult formatSubscriptionInfoResults(final Object result)
-      {
-         OperationResult operationResult = new OperationResult();
-         Configuration c = operationResult.getComplexResults();
-         PropertyList property = new PropertyList("result");
-         Object[] map = (Object[]) result;
-         for (Object o : map)
-         {
-            org.rhq.core.domain.configuration.PropertyMap p1 = new org.rhq.core.domain.configuration.PropertyMap("element");
-            property.add(p1);
-            Object[] subscriptionInfo = (Object[]) o;
-            String name = (String) subscriptionInfo[0];
-            String clientID = (String) subscriptionInfo[1];
-            String subName = (String) subscriptionInfo[2];
-            Boolean durable = (Boolean) subscriptionInfo[3];
-            Integer messageCount = (Integer) subscriptionInfo[4];
-            String filter = (String) subscriptionInfo[5];
-            p1.put(new PropertySimple("name", name));
-            p1.put(new PropertySimple("clientID", clientID));
-            p1.put(new PropertySimple("subName", subName));
-            p1.put(new PropertySimple("durable", durable));
-            p1.put(new PropertySimple("messageCount", messageCount));
-            p1.put(new PropertySimple("filter", filter));
-         }
-         c.put(property);
-         return operationResult;
-      }
-
-      OperationResult formatStringArrayResults(final Object result)
-      {
-         OperationResult operationResult = new OperationResult();
-         Configuration c = operationResult.getComplexResults();
-         PropertyList property = new PropertyList("result");
-         String[] Strings = (String[]) result;
-         property.add(new PropertySimple("element", "test"));
-         for (String string : Strings)
-         {
-            property.add(new PropertySimple("element", string));
-         }
-         c.put(property);
-         return operationResult;
-      }
-   }
-
-
    private static OperationDefinition getOperationDefinition(final String operationName, final ResourceContext resourceContext)
    {
       ResourceType resourceType = resourceContext.getResourceType();

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-09 18:19:49 UTC (rev 100768)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerComponent.java	2010-02-09 18:34:44 UTC (rev 100769)
@@ -21,6 +21,7 @@
 import org.rhq.core.pluginapi.operation.OperationFacet;
 import org.rhq.core.pluginapi.operation.OperationResult;
 
+import javax.management.MBeanServer;
 import java.util.Set;
 
 /**
@@ -33,6 +34,8 @@
 
    private ResourceContext resourceContext;
 
+   private MBeanServer mBeanServer;
+
    public void getValues(final MeasurementReport report, final Set<MeasurementScheduleRequest> measurementScheduleRequests) throws Exception
    {
       for (MeasurementScheduleRequest request : measurementScheduleRequests)
@@ -50,6 +53,7 @@
    public void start(final ResourceContext resourceContext) throws InvalidPluginConfigurationException, Exception
    {
       this.resourceContext = resourceContext;
+      mBeanServer = org.jboss.mx.util.MBeanServerLocator.locate();
    }
 
    public void stop()
@@ -71,4 +75,9 @@
    {
       this.queueNames = queueNames;
    }
+
+   public MBeanServer getMBeanServer()
+   {
+      return mBeanServer;
+   }
 }

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-09 18:19:49 UTC (rev 100768)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/HornetQServerDiscoveryComponent.java	2010-02-09 18:34:44 UTC (rev 100769)
@@ -20,11 +20,12 @@
 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
 
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
+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;
 
@@ -38,11 +39,9 @@
    {
       ObjectName name = new ObjectName("org.hornetq:module=JMS,type=Server");
       MBeanServer beanServer = org.jboss.mx.util.MBeanServerLocator.locate();
+
       MBeanInfo info = beanServer.getMBeanInfo(name);
       String version = (String) beanServer.getAttribute(name, "Version");
-      String[] queueNames = (String[]) beanServer.getAttribute(name, "QueueNames");
-      MBeanAttributeInfo[] attributeInfos = info.getAttributes();
-      //ctx.getParentResourceComponent().setQueueNames(queueNames);
       Set<DiscoveredResourceDetails> set = new HashSet<DiscoveredResourceDetails>();
       Configuration c = new Configuration();
       DiscoveredResourceDetails detail = new DiscoveredResourceDetails(

Copied: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanInvoker.java (from rev 100348, branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanUtil.java)
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanInvoker.java	                        (rev 0)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanInvoker.java	2010-02-09 18:34:44 UTC (rev 100769)
@@ -0,0 +1,81 @@
+/*
+ * 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++;
+      }
+   }
+}

Deleted: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanUtil.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanUtil.java	2010-02-09 18:19:49 UTC (rev 100768)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/MBeanUtil.java	2010-02-09 18:34:44 UTC (rev 100769)
@@ -1,87 +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 MBeanUtil
-{
-   private boolean initialized = false;
-
-   private MBeanServer beanServer;
-
-   private void init() throws Exception
-   {
-      beanServer = MBeanServerLocator.locate();
-      initialized = true;
-   }
-
-   public Object invoke(final ObjectName objectName, final String oper, final Collection<PropertySimple> props) throws Exception
-   {
-      if(!initialized)
-      {
-         init();
-      }
-      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
-   {
-      if(!initialized)
-      {
-         init();
-      }
-      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("String"))
-            {
-               params[pos] = prop.getStringValue();
-               signature[pos] = "java.lang.String";
-            }
-         }
-         pos++;
-      }
-   }
-}

Added: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/Operation.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/Operation.java	                        (rev 0)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/Operation.java	2010-02-09 18:34:44 UTC (rev 100769)
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ *         Created Feb 9, 2010
+ */
+public class Operation
+{
+   final private String operationName;
+      final private String resultsType;
+
+      Operation(String operationName, String resultsType)
+      {
+         this.operationName = operationName;
+         this.resultsType = resultsType;
+      }
+
+      public String getOperationName()
+      {
+         return operationName;
+      }
+
+      public String getResultsType()
+      {
+         return resultsType;
+      }
+
+      public static Operation getOperation(String oper)
+      {
+         String[] split = oper.split(",", 3);
+         String operationName = split[0];
+         String resultsType = null;
+         for (int i = 1, splitLength = split.length; i < splitLength; i++)
+         {
+            String s = split[i];
+            if(s.startsWith("operation"))
+            {
+               operationName = s.substring(s.indexOf("=") + 1);
+            }
+            else if(s.startsWith("result"))
+            {
+               resultsType = s.substring(s.indexOf("=") + 1);
+            }
+         }
+         return new Operation(operationName, resultsType);
+      }
+}

Added: branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/ResultsFormatter.java
===================================================================
--- branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/ResultsFormatter.java	                        (rev 0)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/main/java/org/jboss/as/integration/hornetq/jopr/util/ResultsFormatter.java	2010-02-09 18:34:44 UTC (rev 100769)
@@ -0,0 +1,218 @@
+/*
+ * 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.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.measurement.MeasurementDataTrait;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.operation.OperationResult;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ *         Created Feb 9, 2010
+ */
+public class ResultsFormatter
+{
+   public OperationResult formatResults(final Operation oper, final Object result, final ResourceContext resourceContext)
+      {
+         if (result == null)
+         {
+            return null;
+         }
+         else
+         {
+
+            if (oper.getResultsType() == null)
+            {
+               return formatStringResults(result.toString());
+            }
+            else
+            {
+               if ("String".equalsIgnoreCase(oper.getResultsType()))
+               {
+                  return formatStringResults(result.toString());
+               }
+               else if ("JMSMessage".equalsIgnoreCase(oper.getResultsType()))
+               {
+                  return formatJmsMessageResults(result);
+               }
+               else if ("String[]".equalsIgnoreCase(oper.getResultsType()))
+               {
+                  return formatStringArrayResults(result);
+               }
+               else if ("SubscriptionInfo".equalsIgnoreCase(oper.getResultsType()))
+               {
+                  return formatSubscriptionInfoResults(result);
+               }
+               else
+               {
+                  return formatStringResults(result.toString());
+               }
+            }
+         }
+      }
+
+      public MeasurementDataTrait formatMetricResults(Object attr, Operation operation, ResourceContext resourceContext, MeasurementScheduleRequest request)
+      {
+         String data;
+         if("roles".equalsIgnoreCase(operation.getResultsType()))
+         {
+            data = formatRolesMetric((Object[]) attr);
+         }
+         else if("connectorpairs".equalsIgnoreCase(operation.getResultsType()))
+         {
+            data = formatConnectorPairsMetric((Object[]) attr);
+         }
+         else if(attr instanceof Object[])
+         {
+            Object[] objects = (Object[]) attr;
+            data = formatObjectArray(objects);
+         }
+         else
+         {
+            data = attr == null?null:attr.toString();
+         }
+         return new MeasurementDataTrait(request, data);
+      }
+      OperationResult formatStringResults(final Object result)
+      {
+         return new OperationResult((String) result);
+      }
+
+      String formatRolesMetric(Object[] results)
+      {
+         StringBuffer sb = new StringBuffer();
+         for (int i = 0, resultsLength = results.length; i < resultsLength; i++)
+         {
+            Object[] result = (Object[]) results[i];
+            if(i > 0)
+            {
+               sb.append(",");
+            }
+            sb.append("{name=").append(result[0].toString());
+            sb.append(",SEND=").append(result[1].toString());
+            sb.append(",CONSUME=").append(result[2].toString());
+            sb.append(",CREATE_DURABLE_QUEUE=").append(result[3].toString());
+            sb.append(",DELETE_DURABLE_QUEUE=").append(result[4].toString());
+            sb.append(",CREATE_NON_DURABLE_QUEUE=").append(result[5].toString());
+            sb.append(",DELETE_NON_DURABLE_QUEUE=").append(result[6].toString());
+            sb.append(",MANAGE=").append(result[7].toString()).append("}");
+         }
+         return sb.toString();
+      }
+
+      String formatConnectorPairsMetric(Object[] results)
+      {
+         StringBuffer sb = new StringBuffer();
+         for (int i = 0, resultsLength = results.length; i < resultsLength; i++)
+         {
+            Object[] result = (Object[]) results[i];
+            if(i > 0)
+            {
+               sb.append(",");
+            }
+            sb.append("{a=").append(result[0].toString());
+            sb.append(",b=").append(result[1].toString()).append("}");
+         }
+         return sb.toString();
+      }
+      OperationResult formatJmsMessageResults(final Object result)
+      {
+         OperationResult operationResult = new OperationResult();
+         Configuration c = operationResult.getComplexResults();
+         PropertyList property = new PropertyList("result");
+         Map[] map = (Map[]) result;
+         for (Map map1 : map)
+         {
+            org.rhq.core.domain.configuration.PropertyMap p1 = new org.rhq.core.domain.configuration.PropertyMap("element");
+            property.add(p1);
+            for (Object o1 : map1.keySet())
+            {
+               p1.put(new PropertySimple((String) o1, map1.get(o1)));
+            }
+         }
+         c.put(property);
+         return operationResult;
+      }
+
+      OperationResult formatSubscriptionInfoResults(final Object result)
+      {
+         OperationResult operationResult = new OperationResult();
+         Configuration c = operationResult.getComplexResults();
+         PropertyList property = new PropertyList("result");
+         Object[] map = (Object[]) result;
+         for (Object o : map)
+         {
+            org.rhq.core.domain.configuration.PropertyMap p1 = new org.rhq.core.domain.configuration.PropertyMap("element");
+            property.add(p1);
+            Object[] subscriptionInfo = (Object[]) o;
+            String name = (String) subscriptionInfo[0];
+            String clientID = (String) subscriptionInfo[1];
+            String subName = (String) subscriptionInfo[2];
+            Boolean durable = (Boolean) subscriptionInfo[3];
+            Integer messageCount = (Integer) subscriptionInfo[4];
+            String filter = (String) subscriptionInfo[5];
+            p1.put(new PropertySimple("name", name));
+            p1.put(new PropertySimple("clientID", clientID));
+            p1.put(new PropertySimple("subName", subName));
+            p1.put(new PropertySimple("durable", durable));
+            p1.put(new PropertySimple("messageCount", messageCount));
+            p1.put(new PropertySimple("filter", filter));
+         }
+         c.put(property);
+         return operationResult;
+      }
+
+      OperationResult formatStringArrayResults(final Object result)
+      {
+         OperationResult operationResult = new OperationResult();
+         Configuration c = operationResult.getComplexResults();
+         PropertyList property = new PropertyList("result");
+         String[] Strings = (String[]) result;
+         property.add(new PropertySimple("element", "test"));
+         for (String string : Strings)
+         {
+            property.add(new PropertySimple("element", string));
+         }
+         c.put(property);
+         return operationResult;
+      }
+
+      private String formatObjectArray(Object[] objects)
+   {
+      StringBuilder sb = new StringBuilder();
+      for (int i = 0, objectsLength = objects.length; i < objectsLength; i++)
+      {
+         Object object = objects[i];
+         if(i > 0)
+         {
+            sb.append(", ");
+         }
+
+         if(object instanceof Object[])
+         {
+            sb.append("{").append(formatObjectArray((Object[]) object)).append("}");
+         }
+         else
+         {
+            sb.append(object.toString());
+         }
+      }
+      return sb.toString();
+   }
+}

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-09 18:19:49 UTC (rev 100768)
+++ branches/Branch_Hornet_Temporary_2/hornetq-int/src/resources/META-INF/rhq-plugin.xml	2010-02-09 18:34:44 UTC (rev 100769)
@@ -38,6 +38,18 @@
                </results>
             </operation>
 '>
+      <!ENTITY hornetqcomponentMetrics '
+                 <metric property="Started"
+                 displayName="Started"
+                 description="is this component started"
+                 dataType="trait" displayType="summary"/>
+'>
+      <!ENTITY hornetqcomponentOperations '
+            <operation name="start" displayName="start" description="Starts this HornetQ component.">
+            </operation>
+            <operation name="stop" displayName="stop" description="Stops this HornetQ component.">
+            </operation>
+'>
       ]>
 <plugin name="HornetQ"
         displayName="HornetQPlugin"
@@ -51,7 +63,8 @@
 
       <server name="HornetQ Server"
             discovery="HornetQServerDiscoveryComponent"
-            class="HornetQServerComponent">
+            class="HornetQServerComponent"
+            supportsManualAdd="true">
          <subcategories>
             <subcategory name="JMS"
                          description="JMS Management">
@@ -62,6 +75,14 @@
                 description="Core Management">
             </subcategory>
         </subcategories>
+         <plugin-configuration>
+                <c:simple-property name="connectorAddress" description="JMX Remoting address of the remote HornetQ Instance"  />
+                <!-- 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"
+                                     defaultValue="service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1090/jmxconnector"/>
+                </c:template>
+         </plugin-configuration>
          <metric property="hornetqversion"
                  displayName="HornetQ Version"
                  description="the HornetQ Version"
@@ -761,6 +782,171 @@
                  description="he names of the queues created on this server"
                  dataType="trait" displayType="summary"/>
          </service>
+         <service name="Acceptors"
+                  discovery="HornetQDiscoveryComponent"
+                  subCategory="Core"
+                  class="HornetQComponent">
+            <plugin-configuration>
+                <c:simple-property name="objectName" default="org.hornetq:module=Core,type=Acceptor"/>
+                <c:simple-property name="useResourceKeyForName" type="boolean" default="true"/>
+            </plugin-configuration>
+            &hornetqcomponentOperations;
+            &hornetqcomponentMetrics;
+            <metric property="Name"
+                 displayName="Name"
+                 description="the name of the acceptor created on this server"
+                 dataType="trait" displayType="summary"/>
+            <metric property="FactoryClassName"
+                 displayName="Factory Class Name"
+                 description="the name of the factory used to create this acceptor"
+                 dataType="trait" displayType="summary"/>
+            <metric property="Parameters"
+                 displayName="Parameters"
+                 description="this Acceptor's parameters"
+                 dataType="trait" displayType="summary"/>
+         </service>
+         <service name="Addresses"
+                  discovery="HornetQDiscoveryComponent"
+                  subCategory="Core"
+                  class="HornetQComponent">
+            <plugin-configuration>
+                <c:simple-property name="objectName" default="org.hornetq:module=Core,type=Address"/>
+                <c:simple-property name="useResourceKeyForName" type="boolean" default="true"/>
+            </plugin-configuration>
+            <operation name="addRole" displayName="Add Role" description="Add a Role to this address.">
+              <parameters>
+                  <c:simple-property required="true" name="name" displayName="Name of the role to add"/>
+                  <c:simple-property required="true" type="boolean" name="boolean:send" displayName="Can the user send to this address?"/>
+                  <c:simple-property required="true" type="boolean" name="boolean:consume" displayName="Can the user consume from this address?"/>
+                  <c:simple-property required="true" type="boolean" name="boolean:createDurableQueue" displayName="Can the user create a durable queue?"/>
+                  <c:simple-property required="true" type="boolean" name="boolean:deleteDurableQueue" displayName="Can the user delete a durable queue?"/>
+                  <c:simple-property required="true" type="boolean" name="boolean:createNonDurableQueue" displayName="Can the user create a temp queue?"/>
+                  <c:simple-property required="true" type="boolean" name="boolean:deleteNonDurableQueue" displayName="Can the user delete a temp queue?"/>
+                  <c:simple-property required="true" type="boolean" name="boolean:manage" displayName="Can the user send management messages?"/>
+		        </parameters>
+            </operation>
+            <operation name="removeRole" displayName="Remove Role" description="Remove a Role from this address.">
+              <parameters>
+                  <c:simple-property required="true" name="name" displayName="Name of the role to remove"/>  
+		        </parameters>
+            </operation>
+            <metric property="Address"
+                 displayName="Address"
+                 description="the address"
+                 dataType="trait" displayType="summary"/>
+            <metric property="Roles,result=roles"
+                 displayName="Roles"
+                 description="Returns the roles (name and permissions) associated to this address"
+                 dataType="trait" displayType="summary"/>
+            <metric property="QueueNames"
+                 displayName="Queue Names"
+                 description="Returns the names of the queues bound to this address"
+                 dataType="trait" displayType="summary"/>
+            <metric property="NumberOfPages"
+                 displayName="Number Of Pages"
+                 description="Returns the number of pages used by this address"
+                 dataType="trait" displayType="summary"/>
+            <metric property="NumberOfBytesPerPage"
+                 displayName="Number Of Bytes Per Page"
+                 description="Returns the number of bytes used by each page for this address"
+                 dataType="trait" displayType="summary"/>
+         </service>
+         <service name="Bridges"
+                  discovery="HornetQDiscoveryComponent"
+                  subCategory="Core"
+                  class="HornetQComponent">
+            <plugin-configuration>
+                <c:simple-property name="objectName" default="org.hornetq:module=Core,type=Bridge"/>
+                <c:simple-property name="useResourceKeyForName" type="boolean" default="true"/>
+            </plugin-configuration>
+            &hornetqcomponentMetrics;
+            <metric property="Name"
+                 displayName="Name"
+                 description="name of this bridge"
+                 dataType="trait" displayType="summary"/>
+            <metric property="QueueName"
+                 displayName="QueueName"
+                 description="name of the queue this bridge is consuming messages from"
+                 dataType="trait" displayType="summary"/>
+            <metric property="ForwardingAddress"
+                 displayName="Forwarding Address"
+                 description="the address this bridge will forward messages to"
+                 dataType="trait" displayType="summary"/>
+            <metric property="FilterString"
+                 displayName="Filter String"
+                 description="the filter string associated to this bridge"
+                 dataType="trait" displayType="summary"/>
+            <metric property="TransformerClassName"
+                 displayName="Transformer Class Name"
+                 description="the name of the org.hornetq.core.server.cluster.Transformer implementation associated to this bridge"
+                 dataType="trait" displayType="summary"/>
+            <metric property="ConnectorPair"
+                 displayName="Connector Pair"
+                 description="the pair of connectors used by this bridge"
+                 dataType="trait" displayType="summary"/>
+            <metric property="DiscoveryGroupName"
+                 displayName="Discovery Group Name"
+                 description="the name of the discovery group used by this bridge"
+                 dataType="trait" displayType="summary"/>
+            <metric property="RetryInterval"
+                 displayName="Retry Interval"
+                 description="the retry interval used by this bridge"
+                 dataType="trait" displayType="summary"/>
+            <metric property="RetryIntervalMultiplier"
+                 displayName="Retry Interval Multiplier"
+                 description="the retry interval multiplier used by this bridge"
+                 dataType="trait" displayType="summary"/>
+            <metric property="ReconnectAttempts"
+                 displayName="Reconnect Attempts"
+                 description="the number of reconnection attempts used by this bridge"
+                 dataType="trait" displayType="summary"/>
+            <metric property="FailoverOnServerShutdown"
+                 displayName="Failover On Server Shutdown"
+                 description="whether the session used by this bridge will failover if the target server is normally shutdown."
+                 dataType="trait" displayType="summary"/>
+            <metric property="ReconnectAttempts"
+                 displayName="Reconnect Attempts"
+                 description="the number of reconnection attempts used by this bridge"
+                 dataType="trait" displayType="summary"/>
+            <metric property="UseDuplicateDetection"
+                 displayName="Use Duplicate Detection"
+                 description="whether this bridge is using duplicate detection"
+                 dataType="trait" displayType="summary"/>
+         </service>
+         <service name="Broadcast Groups"
+                  discovery="HornetQDiscoveryComponent"
+                  subCategory="Core"
+                  class="HornetQComponent">
+            <plugin-configuration>
+                <c:simple-property name="objectName" default="org.hornetq:module=Core,type=BroadcastGroup"/>
+                <c:simple-property name="useResourceKeyForName" type="boolean" default="true"/>
+            </plugin-configuration>
+            &hornetqcomponentMetrics;
+            <metric property="Name"
+                 displayName="Name"
+                 description="the configuration name of this broadcast group"
+                 dataType="trait" displayType="summary"/>
+            <metric property="LocalBindPort"
+                 displayName="Local Bind Port"
+                 description="the local port this broadcast group is bound to"
+                 dataType="trait" displayType="summary"/>
+            <metric property="GroupAddress"
+                 displayName="Group Address"
+                 description="the address this broadcast group is broadcasting to"
+                 dataType="trait" displayType="summary"/>
+            <metric property="GroupPort"
+                 displayName="Group Port"
+                 description="the port this broadcast group is broadcasting to"
+                 dataType="trait" displayType="summary"/>
+            <metric property="BroadcastPeriod"
+                 displayName="Broadcast Period"
+                 description="the period used by this broadcast group"
+                 dataType="trait" displayType="summary"/>
+            <metric property="ConnectorPairs,result=connectorpairs"
+                 displayName="Connector Pairs"
+                 description="the pairs of live-backup connectors that are broadcasted by this broadcast group"
+                 dataType="trait" displayType="summary"/>
+         </service>
       </server>
 
 </plugin>




More information about the jboss-cvs-commits mailing list