[exo-jcr-commits] exo-jcr SVN: r1264 - in kernel/trunk/exo.kernel.container/src: main/java/org/exoplatform/management/annotations and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jan 1 07:41:48 EST 2010


Author: julien_viet
Date: 2010-01-01 07:41:47 -0500 (Fri, 01 Jan 2010)
New Revision: 1264

Added:
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/annotations/Impact.java
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/annotations/ImpactType.java
   kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/
   kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/Bar.java
   kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/Foo.java
   kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/TestMetaData.java
Modified:
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/MetaDataBuilder.java
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/ExoMBeanInfoBuilder.java
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/spi/ManagedMethodMetaData.java
   kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/TestExoMBeanOperation.java
Log:
EXOJCR-360 : Add impact meta data in management layer


Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/MetaDataBuilder.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/MetaDataBuilder.java	2009-12-31 19:06:31 UTC (rev 1263)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/MetaDataBuilder.java	2010-01-01 12:41:47 UTC (rev 1264)
@@ -19,6 +19,8 @@
 package org.exoplatform.container.management;
 
 import org.exoplatform.commons.reflect.AnnotationIntrospector;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
 import org.exoplatform.management.annotations.Managed;
 import org.exoplatform.management.annotations.ManagedDescription;
 import org.exoplatform.management.annotations.ManagedName;
@@ -131,8 +133,12 @@
          ManagedDescription methodDescriptionAnn = methodDescriptions.get(method);
          String methodDescription = methodDescriptionAnn != null ? methodDescriptionAnn.value() : null;
 
+         //
+         Impact impactAnn = method.getAnnotation(Impact.class);
+         ImpactType impactType = impactAnn != null ? impactAnn.value() : ImpactType.WRITE;
+
          // Build the default mbean info
-         ManagedMethodMetaData managedMethod = new ManagedMethodMetaData(method);
+         ManagedMethodMetaData managedMethod = new ManagedMethodMetaData(method, impactType);
          managedMethod.setDescription(methodDescription);
 
          // Overload with annotations meta data

Added: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/annotations/Impact.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/annotations/Impact.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/annotations/Impact.java	2010-01-01 12:41:47 UTC (rev 1264)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.management.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The impact annotates a managed method to describe how it affects the state of the managed resource.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE, ElementType.METHOD})
+public @interface Impact
+{
+
+   ImpactType value() default ImpactType.WRITE;
+
+}

Added: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/annotations/ImpactType.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/annotations/ImpactType.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/annotations/ImpactType.java	2010-01-01 12:41:47 UTC (rev 1264)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.management.annotations;
+
+/**
+ * The type of the impact of a managed method.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public enum ImpactType
+{
+
+   /**
+    * Read operation, does not affect state of the managed resource.
+    * Equivalent of {@link javax.management.MBeanOperationInfo#INFO} for JMX and GET method for Rest.
+    */
+   READ,
+
+   /**
+    * Write operation, changes the state of the managed resource.
+    * Equivalent of {@link javax.management.MBeanOperationInfo#INFO} for JMX and POST method for Rest.
+    */
+   WRITE,
+
+   /**
+    * Write operation, changes the state of the managed resource in an idempotent manner.
+    * Equivalent of {@link javax.management.MBeanOperationInfo#INFO} for JMX and PUT method for Rest.
+    */
+   IDEMPOTENT_WRITE
+
+}

Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/ExoMBeanInfoBuilder.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/ExoMBeanInfoBuilder.java	2009-12-31 19:06:31 UTC (rev 1263)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/ExoMBeanInfoBuilder.java	2010-01-01 12:41:47 UTC (rev 1264)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.management.jmx.impl;
 
+import org.exoplatform.management.annotations.ImpactType;
 import org.exoplatform.management.spi.ManagedMethodMetaData;
 import org.exoplatform.management.spi.ManagedMethodParameterMetaData;
 import org.exoplatform.management.spi.ManagedPropertyMetaData;
@@ -33,6 +34,7 @@
 
 import javax.management.Descriptor;
 import javax.management.IntrospectionException;
+import javax.management.MBeanOperationInfo;
 import javax.management.MBeanParameterInfo;
 import javax.management.modelmbean.ModelMBeanAttributeInfo;
 import javax.management.modelmbean.ModelMBeanConstructorInfo;
@@ -80,7 +82,7 @@
    }
 
    private ModelMBeanOperationInfo buildOperationInfo(Method method, String description, Role role,
-      Collection<ManagedMethodParameterMetaData> parametersMD)
+      Collection<ManagedMethodParameterMetaData> parametersMD, ImpactType impactType)
    {
       ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo(description, method);
 
@@ -110,12 +112,27 @@
       }
 
       //
+      int jmxImpact;
+      switch (impactType)
+      {
+         case READ:
+            jmxImpact = MBeanOperationInfo.INFO;
+            break;
+         case IDEMPOTENT_WRITE:
+         case WRITE:
+            jmxImpact = MBeanOperationInfo.ACTION;
+            break;
+         default:
+            throw new AssertionError();
+      }
+
+      //
       Descriptor operationDescriptor = operationInfo.getDescriptor();
       operationDescriptor.setField("role", role.name);
 
       //
       return new ModelMBeanOperationInfo(operationInfo.getName(), description, parameterInfos, operationInfo
-         .getReturnType(), operationInfo.getImpact(), operationDescriptor);
+         .getReturnType(), jmxImpact, operationDescriptor);
    }
 
    /**
@@ -137,7 +154,7 @@
       for (ManagedMethodMetaData methodMD : typeMD.getMethods())
       {
          ModelMBeanOperationInfo operationInfo =
-            buildOperationInfo(methodMD.getMethod(), methodMD.getDescription(), Role.OP, methodMD.getParameters());
+            buildOperationInfo(methodMD.getMethod(), methodMD.getDescription(), Role.OP, methodMD.getParameters(), methodMD.getImpact());
          operations.add(operationInfo);
       }
 
@@ -165,7 +182,7 @@
             }
             Collection<ManagedMethodParameterMetaData> blah = Collections.emptyList();
             ModelMBeanOperationInfo operationInfo =
-               buildOperationInfo(getter, propertyMD.getGetterDescription(), role, blah);
+               buildOperationInfo(getter, propertyMD.getGetterDescription(), role, blah, ImpactType.READ);
             operations.add(operationInfo);
          }
 
@@ -178,7 +195,7 @@
             s.setName(propertyMD.getSetterParameter().getName());
             Collection<ManagedMethodParameterMetaData> blah = Collections.singletonList(s);
             ModelMBeanOperationInfo operationInfo =
-               buildOperationInfo(setter, propertyMD.getSetterDescription(), Role.SET, blah);
+               buildOperationInfo(setter, propertyMD.getSetterDescription(), Role.SET, blah, ImpactType.IDEMPOTENT_WRITE);
             operations.add(operationInfo);
          }
 

Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/spi/ManagedMethodMetaData.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/spi/ManagedMethodMetaData.java	2009-12-31 19:06:31 UTC (rev 1263)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/spi/ManagedMethodMetaData.java	2010-01-01 12:41:47 UTC (rev 1264)
@@ -18,6 +18,8 @@
  */
 package org.exoplatform.management.spi;
 
+import org.exoplatform.management.annotations.ImpactType;
+
 import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Collections;
@@ -39,24 +41,43 @@
    /** . */
    private final Map<Integer, ManagedMethodParameterMetaData> parameters;
 
+   /** . */
+   private final ImpactType impact;
+
    /**
     * Build a new instance.
     *
     * @param method the method
-    * @throws NullPointerException if the method is null
+    * @param impactType the access mode
+    * @throws NullPointerException if the method is null or the impact is null
     */
-   public ManagedMethodMetaData(Method method) throws NullPointerException
+   public ManagedMethodMetaData(Method method, ImpactType impactType) throws NullPointerException
    {
       if (method == null)
       {
          throw new NullPointerException();
       }
+      if (impactType == null)
+      {
+         throw new NullPointerException();
+      }
 
       //
       this.method = method;
+      this.impact = impactType;
       this.parameters = new HashMap<Integer, ManagedMethodParameterMetaData>();
    }
 
+   public String getName()
+   {
+      return method.getName();
+   }
+
+   public ImpactType getImpact()
+   {
+      return impact;
+   }
+
    public Method getMethod()
    {
       return method;

Modified: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/TestExoMBeanOperation.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/TestExoMBeanOperation.java	2009-12-31 19:06:31 UTC (rev 1263)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/TestExoMBeanOperation.java	2010-01-01 12:41:47 UTC (rev 1264)
@@ -18,6 +18,8 @@
  */
 package org.exoplatform.container.jmx;
 
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
 import org.exoplatform.management.annotations.Managed;
 import org.exoplatform.management.annotations.ManagedDescription;
 import org.exoplatform.management.annotations.ManagedName;
@@ -188,4 +190,51 @@
          return Integer.toString(arg);
       }
    }
+
+   public void test6() throws Exception
+   {
+      Bean bean = register("domain:name=mbean", MBean6.class);
+      MBeanOperationInfo[] operationInfos = bean.info.getOperations();
+      assertNotNull(operationInfos);
+      assertEquals(4, operationInfos.length);
+      MBeanOperationInfo readInfo = bean.info.getOperation("read");
+      assertNotNull(readInfo);
+      assertEquals(MBeanOperationInfo.INFO, readInfo.getImpact());
+      MBeanOperationInfo writeInfo = bean.info.getOperation("write");
+      assertNotNull(writeInfo);
+      assertEquals(MBeanOperationInfo.ACTION, writeInfo.getImpact());
+      MBeanOperationInfo idempotentWriteInfo = bean.info.getOperation("idempotentWrite");
+      assertNotNull(idempotentWriteInfo);
+      assertEquals(MBeanOperationInfo.ACTION, idempotentWriteInfo.getImpact());
+      MBeanOperationInfo defaultImpactInfo = bean.info.getOperation("defaultImpact");
+      assertNotNull(defaultImpactInfo);
+      assertEquals(MBeanOperationInfo.ACTION, defaultImpactInfo.getImpact());
+   }
+
+   @Managed
+   public static class MBean6
+   {
+      @Managed
+      @Impact(ImpactType.READ)
+      public void read()
+      {
+      }
+
+      @Managed
+      @Impact(ImpactType.WRITE)
+      public void write()
+      {
+      }
+
+      @Managed
+      @Impact(ImpactType.IDEMPOTENT_WRITE)
+      public void idempotentWrite()
+      {
+      }
+
+      @Managed
+      public void defaultImpact()
+      {
+      }
+   }
 }

Added: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/Bar.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/Bar.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/Bar.java	2010-01-01 12:41:47 UTC (rev 1264)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.container.management.metadata;
+
+import org.exoplatform.management.annotations.Managed;
+import org.exoplatform.management.annotations.ManagedName;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at Managed
+public class Bar
+{
+
+   @Managed
+   @ManagedName("b")
+   public void a()
+   {
+   }
+}
\ No newline at end of file

Added: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/Foo.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/Foo.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/Foo.java	2010-01-01 12:41:47 UTC (rev 1264)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.container.management.metadata;
+
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
+import org.exoplatform.management.annotations.Managed;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at Managed
+public class Foo
+{
+
+   @Managed
+   @Impact(ImpactType.READ)
+   public void read()
+   {
+   }
+
+   @Managed
+   @Impact(ImpactType.WRITE)
+   public void write()
+   {
+   }
+
+   @Managed
+   @Impact(ImpactType.IDEMPOTENT_WRITE)
+   public void idempotentWrite()
+   {
+   }
+}

Added: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/TestMetaData.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/TestMetaData.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/management/metadata/TestMetaData.java	2010-01-01 12:41:47 UTC (rev 1264)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.container.management.metadata;
+
+import junit.framework.TestCase;
+import org.exoplatform.container.management.MetaDataBuilder;
+import org.exoplatform.management.annotations.ImpactType;
+import org.exoplatform.management.spi.ManagedMethodMetaData;
+import org.exoplatform.management.spi.ManagedTypeMetaData;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TestMetaData extends TestCase
+{
+
+   private Map<String, ManagedMethodMetaData> getMethodMap(ManagedTypeMetaData type)
+   {
+      Map<String, ManagedMethodMetaData> methodMap = new HashMap<String, ManagedMethodMetaData>();
+      for (ManagedMethodMetaData method : type.getMethods())
+      {
+         methodMap.put(method.getName(), method);
+      }
+      return methodMap;
+   }
+
+   public void testImpact()
+   {
+      MetaDataBuilder builder = new MetaDataBuilder(Foo.class);
+      ManagedTypeMetaData type = builder.build();
+      Map<String, ManagedMethodMetaData> methodMap = getMethodMap(type);
+      ManagedMethodMetaData read = methodMap.get("read");
+      assertEquals(ImpactType.READ, read.getImpact());
+      ManagedMethodMetaData write = methodMap.get("write");
+      assertEquals(ImpactType.WRITE, write.getImpact());
+      ManagedMethodMetaData idempotentWrite = methodMap.get("idempotentWrite");
+      assertEquals(ImpactType.IDEMPOTENT_WRITE, idempotentWrite.getImpact());
+   }
+
+   public void testMethodNameOverride()
+   {
+      MetaDataBuilder builder = new MetaDataBuilder(Bar.class);
+      try
+      {
+         builder.build();
+         fail();
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+   }
+}



More information about the exo-jcr-commits mailing list