Package org.infinispan.jmx.annotations

Examples of org.infinispan.jmx.annotations.ManagedAttribute


      // traverse class hierarchy and find all annotated fields
      for (Class<?> clazz = getObject().getClass(); clazz != null; clazz = clazz.getSuperclass()) {

         Field[] fields = clazz.getDeclaredFields();
         for (Field field : fields) {
            ManagedAttribute attr = field.getAnnotation(ManagedAttribute.class);
            if (attr != null) {
               String fieldName = renameToJavaCodingConvention(field.getName());
               MBeanAttributeInfo info = new MBeanAttributeInfo(fieldName, field.getType()
                       .getCanonicalName(), attr.description(), true, !Modifier.isFinal(field
                       .getModifiers()) && attr.writable(), false);

               atts.put(fieldName, new FieldAttributeEntry(info, field));
            }
         }
      }
View Full Code Here


      List<Method> objectMethods = new ArrayList<Method>(Arrays.asList(Object.class.getMethods()));
      methods.removeAll(objectMethods);

      for (Method method : methods) {
         // does method have @ManagedAttribute annotation?
         ManagedAttribute attr = method.getAnnotation(ManagedAttribute.class);
         if (attr != null) {
            String methodName = method.getName();
            if (!methodName.startsWith("get") && !methodName.startsWith("set")
                    && !methodName.startsWith("is")) {
               log.ignoringManagedAttribute(methodName);
            } else {
               MBeanAttributeInfo info = null;
               String attributeName = null;
               boolean writeAttribute = false;
               if (isSetMethod(method)) { // setter
                  attributeName = methodName.substring(3);
                  info = new MBeanAttributeInfo(attributeName, method.getParameterTypes()[0]
                          .getCanonicalName(), attr.description(), true, true, false);
                  writeAttribute = true;
               } else { // getter
                  if (method.getParameterTypes().length == 0
                          && method.getReturnType() != java.lang.Void.TYPE) {
                     // we found is method
                     if (methodName.startsWith("is")) {
                        attributeName = methodName.substring(2);
                        info = new MBeanAttributeInfo(attributeName, method.getReturnType().getCanonicalName(),
                              attr.description(), true, atts.containsKey(attributeName), true);
                     } else {
                        // this has to be get
                        attributeName = methodName.substring(3);
                        info = new MBeanAttributeInfo(attributeName, method.getReturnType().getCanonicalName(),
                              attr.description(), true, atts.containsKey(attributeName), false);
                     }
                  } else {
                     log.invalidManagedAttributeMethod(method.getName());
                     continue;
                  }
               }

               AttributeEntry ae = atts.get(attributeName);
               // is it a read method?
               if (!writeAttribute) {
                  // we already have annotated field as read
                  if (ae instanceof FieldAttributeEntry && ae.getInfo().isReadable()) {
                     log.readManagedAttributeAlreadyPresent(method);
                  }
                  // we already have annotated set method
                  else if (ae instanceof MethodAttributeEntry) {
                     MethodAttributeEntry mae = (MethodAttributeEntry) ae;
                     if (mae.hasSetMethod()) {
                        atts.put(attributeName, new MethodAttributeEntry(mae.getInfo(), mae
                                .getSetMethod(), method));
                     }
                  } // we don't have such entry
                  else {
                     atts.put(attributeName, new MethodAttributeEntry(info, null, method));
                  }
               }// is it a set method?
               else {
                  if (ae instanceof FieldAttributeEntry) {
                     // we already have annotated field as write
                     if (ae.getInfo().isWritable()) {
                        log.writeManagedAttributeAlreadyPresent(methodName);
                     } else {
                        // we already have annotated field as read
                        // lets make the field writable
                        Field f = ((FieldAttributeEntry) ae).getField();
                        MBeanAttributeInfo i = new MBeanAttributeInfo(ae.getInfo().getName(), f
                                .getType().getCanonicalName(), attr.description(), true, Modifier
                                .isFinal(f.getModifiers()) ? false : true, false);
                        atts.put(attributeName, new FieldAttributeEntry(i, f));
                     }
                  }
                  // we already have annotated getOrIs method
View Full Code Here

      // traverse class hierarchy and find all annotated fields
      for (Class<?> clazz = getObject().getClass(); clazz != null; clazz = clazz.getSuperclass()) {

         Field[] fields = clazz.getDeclaredFields();
         for (Field field : fields) {
            ManagedAttribute attr = field.getAnnotation(ManagedAttribute.class);
            if (attr != null) {
               String fieldName = renameToJavaCodingConvention(field.getName());
               MBeanAttributeInfo info = new MBeanAttributeInfo(fieldName, field.getType()
                       .getCanonicalName(), attr.description(), true, !Modifier.isFinal(field
                       .getModifiers()) && attr.writable(), false);

               atts.put(fieldName, new FieldAttributeEntry(info, field));
            }
         }
      }
View Full Code Here

      List<Method> objectMethods = new ArrayList<Method>(Arrays.asList(Object.class.getMethods()));
      methods.removeAll(objectMethods);

      for (Method method : methods) {
         // does method have @ManagedAttribute annotation?
         ManagedAttribute attr = method.getAnnotation(ManagedAttribute.class);
         if (attr != null) {
            String methodName = method.getName();
            if (!methodName.startsWith("get") && !methodName.startsWith("set")
                    && !methodName.startsWith("is")) {
               log.ignoringManagedAttribute(methodName);
            } else {
               MBeanAttributeInfo info = null;
               String attributeName = null;
               boolean writeAttribute = false;
               if (isSetMethod(method)) { // setter
                  attributeName = methodName.substring(3);
                  info = new MBeanAttributeInfo(attributeName, method.getParameterTypes()[0]
                          .getCanonicalName(), attr.description(), true, true, false);
                  writeAttribute = true;
               } else { // getter
                  if (method.getParameterTypes().length == 0
                          && method.getReturnType() != java.lang.Void.TYPE) {
                     // we found is method
                     if (methodName.startsWith("is")) {
                        attributeName = methodName.substring(2);
                        info = new MBeanAttributeInfo(attributeName, method.getReturnType().getCanonicalName(),
                              attr.description(), true, atts.containsKey(attributeName), true);
                     } else {
                        // this has to be get
                        attributeName = methodName.substring(3);
                        info = new MBeanAttributeInfo(attributeName, method.getReturnType().getCanonicalName(),
                              attr.description(), true, atts.containsKey(attributeName), false);
                     }
                  } else {
                     log.invalidManagedAttributeMethod(method.getName());
                     continue;
                  }
               }

               AttributeEntry ae = atts.get(attributeName);
               // is it a read method?
               if (!writeAttribute) {
                  // we already have annotated field as read
                  if (ae instanceof FieldAttributeEntry && ae.getInfo().isReadable()) {
                     log.readManagedAttributeAlreadyPresent(method);
                  }
                  // we already have annotated set method
                  else if (ae instanceof MethodAttributeEntry) {
                     MethodAttributeEntry mae = (MethodAttributeEntry) ae;
                     if (mae.hasSetMethod()) {
                        atts.put(attributeName, new MethodAttributeEntry(mae.getInfo(), mae
                                .getSetMethod(), method));
                     }
                  } // we don't have such entry
                  else {
                     atts.put(attributeName, new MethodAttributeEntry(info, null, method));
                  }
               }// is it a set method?
               else {
                  if (ae instanceof FieldAttributeEntry) {
                     // we already have annotated field as write
                     if (ae.getInfo().isWritable()) {
                        log.writeManagedAttributeAlreadyPresent(methodName);
                     } else {
                        // we already have annotated field as read
                        // lets make the field writable
                        Field f = ((FieldAttributeEntry) ae).getField();
                        MBeanAttributeInfo i = new MBeanAttributeInfo(ae.getInfo().getName(), f
                                .getType().getCanonicalName(), attr.description(), true, Modifier
                                .isFinal(f.getModifiers()) ? false : true, false);
                        atts.put(attributeName, new FieldAttributeEntry(i, f));
                     }
                  }
                  // we already have annotated getOrIs method
View Full Code Here

      // traverse class hierarchy and find all annotated fields
      for (Class<?> clazz = getObject().getClass(); clazz != null; clazz = clazz.getSuperclass()) {

         Field[] fields = clazz.getDeclaredFields();
         for (Field field : fields) {
            ManagedAttribute attr = field.getAnnotation(ManagedAttribute.class);
            if (attr != null) {
               String fieldName = renameToJavaCodingConvention(field.getName());
               MBeanAttributeInfo info = new MBeanAttributeInfo(fieldName, field.getType()
                       .getCanonicalName(), attr.description(), true, !Modifier.isFinal(field
                       .getModifiers()) && attr.writable(), false);

               atts.put(fieldName, new FieldAttributeEntry(info, field));
            }
         }
      }
View Full Code Here

      List<Method> objectMethods = new ArrayList<Method>(Arrays.asList(Object.class.getMethods()));
      methods.removeAll(objectMethods);

      for (Method method : methods) {
         //does method have @ManagedAttribute annotation?
         ManagedAttribute attr = method.getAnnotation(ManagedAttribute.class);
         if (attr != null) {
            String methodName = method.getName();
            if (!methodName.startsWith("get") && !methodName.startsWith("set")
                  && !methodName.startsWith("is")) {
               if (log.isWarnEnabled())
                  log.warn("method name " + methodName
                        + " doesn't start with \"get\", \"set\", or \"is\""
                        + ", but is annotated with @ManagedAttribute: will be ignored");
            } else {
               MBeanAttributeInfo info = null;
               //Is name field of @ManagedAttributed used?
               String attributeName = attr.name().length() > 0 ? attr.name().trim() : null;
               boolean writeAttribute = false;
               if (isSetMethod(method)) { // setter
                  attributeName = (attributeName == null) ? methodName.substring(3) : attributeName;
                  info = new MBeanAttributeInfo(attributeName,
                                                method.getParameterTypes()[0].getCanonicalName(),
                                                attr.description(),
                                                true,
                                                true,
                                                false);
                  writeAttribute = true;
               } else { // getter
                  if (method.getParameterTypes().length == 0 && method.getReturnType() != java.lang.Void.TYPE) {
                     boolean hasSetter = atts.containsKey(attributeName);
                     //we found is method
                     if (methodName.startsWith("is")) {
                        attributeName = (attributeName == null) ? methodName.substring(2) : attributeName;
                        info = new MBeanAttributeInfo(attributeName,
                                                      method.getReturnType().getCanonicalName(),
                                                      attr.description(),
                                                      true,
                                                      hasSetter,
                                                      true);
                     } else {
                        //this has to be get
                        attributeName = (attributeName == null) ? methodName.substring(3) : attributeName;
                        info = new MBeanAttributeInfo(attributeName,
                                                      method.getReturnType().getCanonicalName(),
                                                      attr.description(),
                                                      true,
                                                      hasSetter,
                                                      false);
                     }
                  } else {
                     if (log.isWarnEnabled()) {
                        log.warn("Method " + method.getName()
                              + " must have a valid return type and zero parameters");
                     }
                     continue;
                  }
               }

               AttributeEntry ae = atts.get(attributeName);
               //is it a read method?
               if (!writeAttribute) {
                  //we already have annotated field as read
                  if (ae instanceof FieldAttributeEntry && ae.getInfo().isReadable()) {
                     log.warn("not adding annotated method " + method
                           + " since we already have read attribute");
                  }
                  //we already have annotated set method
                  else if (ae instanceof MethodAttributeEntry) {
                     MethodAttributeEntry mae = (MethodAttributeEntry) ae;
                     if (mae.hasSetMethod()) {
                        atts.put(attributeName,
                                 new MethodAttributeEntry(mae.getInfo(), mae.getSetMethod(), method));
                     }
                  } //we don't have such entry
                  else {
                     atts.put(attributeName, new MethodAttributeEntry(info, null, method));
                  }
               }//is it a set method?
               else {
                  if (ae instanceof FieldAttributeEntry) {
                     //we already have annotated field as write
                     if (ae.getInfo().isWritable()) {
                        log.warn("Not adding annotated method " + methodName
                              + " since we already have writable attribute");
                     } else {
                        //we already have annotated field as read
                        //lets make the field writable
                        Field f = ((FieldAttributeEntry) ae).getField();
                        MBeanAttributeInfo i = new MBeanAttributeInfo(ae.getInfo().getName(),
                                                                      f.getType().getCanonicalName(),
                                                                      attr.description(),
                                                                      true,
                                                                      Modifier.isFinal(f.getModifiers()) ? false : true,
                                                                      false);
                        atts.put(attributeName, new FieldAttributeEntry(i, f));
                     }
View Full Code Here

      //traverse class hierarchy and find all annotated fields
      for (Class<?> clazz = getObject().getClass(); clazz != null; clazz = clazz.getSuperclass()) {

         Field[] fields = clazz.getDeclaredFields();
         for (Field field : fields) {
            ManagedAttribute attr = field.getAnnotation(ManagedAttribute.class);
            if (attr != null) {
               String fieldName = renameToJavaCodingConvention(field.getName());
               MBeanAttributeInfo info = new MBeanAttributeInfo(fieldName,
                                                                field.getType().getCanonicalName(),
                                                                attr.description(),
                                                                true,
                                                                Modifier.isFinal(field.getModifiers()) ? false : attr.writable(),
                                                                false);

               atts.put(fieldName, new FieldAttributeEntry(info, field));
            }
         }
View Full Code Here

      List<Method> objectMethods = new ArrayList<Method>(Arrays.asList(Object.class.getMethods()));
      methods.removeAll(objectMethods);

      for (Method method : methods) {
         // does method have @ManagedAttribute annotation?
         ManagedAttribute attr = method.getAnnotation(ManagedAttribute.class);
         if (attr != null) {
            String methodName = method.getName();
            if (!methodName.startsWith("get") && !methodName.startsWith("set")
                     && !methodName.startsWith("is")) {
               if (log.isWarnEnabled())
                  log.warn("method name " + methodName
                           + " doesn't start with \"get\", \"set\", or \"is\""
                           + ", but is annotated with @ManagedAttribute: will be ignored");
            } else {
               MBeanAttributeInfo info = null;
               String attributeName = null;
               boolean writeAttribute = false;
               if (isSetMethod(method)) { // setter
                  attributeName = methodName.substring(3);
                  info = new MBeanAttributeInfo(attributeName, method.getParameterTypes()[0]
                           .getCanonicalName(), attr.description(), true, true, false);
                  writeAttribute = true;
               } else { // getter
                  if (method.getParameterTypes().length == 0
                           && method.getReturnType() != java.lang.Void.TYPE) {
                     boolean hasSetter = atts.containsKey(attributeName);
                     // we found is method
                     if (methodName.startsWith("is")) {
                        attributeName = methodName.substring(2);
                        info = new MBeanAttributeInfo(attributeName, method.getReturnType()
                                 .getCanonicalName(), attr.description(), true, hasSetter, true);
                     } else {
                        // this has to be get
                        attributeName = methodName.substring(3);
                        info = new MBeanAttributeInfo(attributeName, method.getReturnType()
                                 .getCanonicalName(), attr.description(), true, hasSetter, false);
                     }
                  } else {
                     if (log.isWarnEnabled()) {
                        log.warn("Method " + method.getName()
                                 + " must have a valid return type and zero parameters");
                     }
                     continue;
                  }
               }

               AttributeEntry ae = atts.get(attributeName);
               // is it a read method?
               if (!writeAttribute) {
                  // we already have annotated field as read
                  if (ae instanceof FieldAttributeEntry && ae.getInfo().isReadable()) {
                     log.warn("not adding annotated method " + method
                              + " since we already have read attribute");
                  }
                  // we already have annotated set method
                  else if (ae instanceof MethodAttributeEntry) {
                     MethodAttributeEntry mae = (MethodAttributeEntry) ae;
                     if (mae.hasSetMethod()) {
                        atts.put(attributeName, new MethodAttributeEntry(mae.getInfo(), mae
                                 .getSetMethod(), method));
                     }
                  } // we don't have such entry
                  else {
                     atts.put(attributeName, new MethodAttributeEntry(info, null, method));
                  }
               }// is it a set method?
               else {
                  if (ae instanceof FieldAttributeEntry) {
                     // we already have annotated field as write
                     if (ae.getInfo().isWritable()) {
                        log.warn("Not adding annotated method " + methodName
                                 + " since we already have writable attribute");
                     } else {
                        // we already have annotated field as read
                        // lets make the field writable
                        Field f = ((FieldAttributeEntry) ae).getField();
                        MBeanAttributeInfo i = new MBeanAttributeInfo(ae.getInfo().getName(), f
                                 .getType().getCanonicalName(), attr.description(), true, Modifier
                                 .isFinal(f.getModifiers()) ? false : true, false);
                        atts.put(attributeName, new FieldAttributeEntry(i, f));
                     }
                  }
                  // we already have annotated getOrIs method
View Full Code Here

      // traverse class hierarchy and find all annotated fields
      for (Class<?> clazz = getObject().getClass(); clazz != null; clazz = clazz.getSuperclass()) {

         Field[] fields = clazz.getDeclaredFields();
         for (Field field : fields) {
            ManagedAttribute attr = field.getAnnotation(ManagedAttribute.class);
            if (attr != null) {
               String fieldName = renameToJavaCodingConvention(field.getName());
               MBeanAttributeInfo info = new MBeanAttributeInfo(fieldName, field.getType()
                        .getCanonicalName(), attr.description(), true, !Modifier.isFinal(field
                     .getModifiers()) && attr.writable(), false);

               atts.put(fieldName, new FieldAttributeEntry(info, field));
            }
         }
      }
View Full Code Here

         String prefix = withNamePrefix ? mbean.objectName() + '.' : "";
         CtClass ctClass = classPool.get(clazz.getName());

         CtMethod[] ctMethods = ctClass.getMethods();
         for (CtMethod ctMethod : ctMethods) {
            ManagedAttribute managedAttr = (ManagedAttribute) ctMethod.getAnnotation(ManagedAttribute.class);
            ManagedOperation managedOp = (ManagedOperation) ctMethod.getAnnotation(ManagedOperation.class);

            if (managedAttr != null) {
               String property = prefix + getPropertyFromBeanConvention(ctMethod);

               String attrDisplayName = managedAttr.displayName();
               if (attrDisplayName.length() == 0) {
                  throw new RuntimeException("Missing displayName on: " + property);
               }
               String displayName = withNamePrefix ? "[" + mbean.objectName() + "] " + attrDisplayName : attrDisplayName;
               validateDisplayName(displayName);

               Element metric = doc.createElement("metric");
               metric.setAttribute("property", property);
               metric.setAttribute("displayName", displayName);
               metric.setAttribute("displayType", managedAttr.displayType().toString());
               metric.setAttribute("dataType", managedAttr.dataType().toString());
               metric.setAttribute("units", managedAttr.units().toString());
               metric.setAttribute("description", managedAttr.description());

               parent.appendChild(metric);
            }

            if (managedOp != null) {
               String name;
               if (!managedOp.name().isEmpty()) {
                  name = prefix + managedOp.name();
               } else {
                  name = prefix + ctMethod.getName();
               }

               Object[][] paramAnnotations = ctMethod.getParameterAnnotations();
               Element parameters = doc.createElement("parameters");
               for (Object[] paramAnnotationsInEach : paramAnnotations) {
                  boolean annotatedParameter = false;
                  for (Object annot : paramAnnotationsInEach) {
                     if (annot instanceof Parameter) {
                        Parameter param = (Parameter) annot;
                        Element prop = doc.createElementNS(URN_XMLNS_RHQ_CONFIGURATION, "simple-property");
                        name += "|" + param.name();
                        prop.setAttribute("name", param.name());
                        prop.setAttribute("description", param.description());
                        parameters.appendChild(prop);
                        annotatedParameter = true;
                     }
                  }
                  if (!annotatedParameter) {
                     throw new RuntimeException("Duplicate operation name: " + name);
                  }
               }

               if (uniqueOperations.contains(name)) {
                  throw new RuntimeException("Duplicate operation name: " + name);
               }
               uniqueOperations.add(name);

               String opDisplayName = managedOp.displayName();
               if (opDisplayName.length() == 0) {
                  throw new RuntimeException("Missing displayName on: " + name);
               }
               String displayName = withNamePrefix ? "[" + mbean.objectName() + "] " + opDisplayName : opDisplayName;
               validateDisplayName(displayName);

               Element operation = doc.createElement("operation");
               operation.setAttribute("name", name);
               operation.setAttribute("displayName", displayName);
               if (managedAttr != null) {
                  operation.setAttribute("description", managedAttr.description());
               } else {
                  operation.setAttribute("description", managedOp.description());
               }

               if(parameters.hasChildNodes()) {
                  operation.appendChild(parameters);
               }
               CtClass returnType = ctMethod.getReturnType();
               if (!returnType.equals(CtClass.voidType) && !returnType.equals(Void.TYPE)) {
                  Element results = doc.createElement("results");
                  Element prop = doc.createElementNS(URN_XMLNS_RHQ_CONFIGURATION, "simple-property");
                  prop.setAttribute("name", "operationResult");
                  results.appendChild(prop);
                  operation.appendChild(results);
               }
               parent.appendChild(operation);
            }
         }

         CtField[] ctFields = ctClass.getDeclaredFields();
         for (CtField ctField : ctFields) {
            ManagedAttribute managedAttr = (ManagedAttribute) ctField.getAnnotation(ManagedAttribute.class);
            if (managedAttr != null) {
               String property = prefix + getPropertyFromBeanConvention(ctField);
               Element metric = doc.createElement("metric");
               metric.setAttribute("property", property);

               String displayName = withNamePrefix ? "[" + mbean.objectName() + "] " + managedAttr.displayName() : managedAttr.displayName();
               validateDisplayName(displayName);
               metric.setAttribute("property", property);
               metric.setAttribute("displayName", displayName);
               metric.setAttribute("displayType", managedAttr.displayType().toString());
               metric.setAttribute("dataType", managedAttr.dataType().toString());
               metric.setAttribute("units", managedAttr.units().toString());
               metric.setAttribute("description", managedAttr.description());
               parent.appendChild(metric);
            }
         }

      }
View Full Code Here

TOP

Related Classes of org.infinispan.jmx.annotations.ManagedAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.