Package javax.management

Examples of javax.management.MBeanAttributeInfo


    }

    protected MBeanAttributeInfo[] createMBeanAttributeInfo()
    {
        return new MBeanAttributeInfo[]
        { new MBeanAttributeInfo("Threshold", String.class.getName(),
                "The \"threshold\" state of the logger hierarchy.", true, true, false) };
    }
View Full Code Here


    private MBeanInfo createMBeanInfo(final ServiceReference serviceReference) {
        final List<MBeanAttributeInfo> attrs = new ArrayList<MBeanAttributeInfo>();

        // add relevant service properties
        if ( serviceReference.getProperty(HealthCheck.NAME) != null ) {
            attrs.add(new MBeanAttributeInfo(HealthCheck.NAME, String.class.getName(), "The name of the health check service.", true, false, false));
        }
        if ( serviceReference.getProperty(HealthCheck.TAGS) != null ) {
            attrs.add(new MBeanAttributeInfo(HealthCheck.TAGS, String.class.getName(), "The tags of the health check service.", true, false, false));
        }
        if ( serviceReference.getProperty(Constants.SERVICE_PID) != null ) {
            attrs.add(new MBeanAttributeInfo(Constants.SERVICE_PID, String.class.getName(), "The persistence identifier of the service.", true, false, false));
        }

        // add standard attributes
        attrs.add(new MBeanAttributeInfo(HC_OK_ATTRIBUTE_NAME, Boolean.class.getName(), "The health check result", true, false, false));
        attrs.add(new MBeanAttributeInfo(HC_STATUS_ATTRIBUTE_NAME, String.class.getName(), "The health check status", true, false, false));
        attrs.add(new MBeanAttributeInfo(HC_ELAPSED_TIMED_ATTRIBUTE_NAME, Long.class.getName(), "The elapsed time in miliseconds", true, false, false));
        attrs.add(new MBeanAttributeInfo(HC_FINISHED_AT_ATTRIBUTE_NAME, Date.class.getName(), "The date when the execution finished", true, false, false));
        attrs.add(new MBeanAttributeInfo(HC_TIMED_OUT_ATTRIBUTE_NAME, Boolean.class.getName(), "Indicates of the execution timed out", true, false, false));
        attrs.add(new OpenMBeanAttributeInfoSupport(HC_LOG_ATTRIBUTE_NAME, "The health check result log", LOG_TABLE_TYPE, true, false, false));

        final String description;
        if ( serviceReference.getProperty(Constants.SERVICE_DESCRIPTION) != null ) {
            description = serviceReference.getProperty(Constants.SERVICE_DESCRIPTION).toString();
View Full Code Here

        List<MBeanAttributeInfo> attributesList = new ArrayList<MBeanAttributeInfo>();
        Set<String> typeNames = new HashSet<String>();
        Iterator<Entry<String, TimeSeries>> statIter = statistics.iterator();
        while (statIter.hasNext()) {
            Entry<String, TimeSeries> entry = statIter.next();
            attributesList.add(new MBeanAttributeInfo("PerSecond_"
                    + entry.getKey(), long.class.getName(),
                    "Current per second value of " + entry.getKey(),
                    true, false, false));
            attributesList.add(new MBeanAttributeInfo("LastMinutePerSecond_"
                    + entry.getKey(), long[].class.getName(),
                    "Last minute of per seconds values of "
                            + entry.getKey(), true, false, false));
            attributesList.add(new MBeanAttributeInfo("PerMinute"
                    + entry.getKey(), long.class.getName(),
                    "Current per minute value of " + entry.getKey(),
                    true, false, false));
            attributesList.add(new MBeanAttributeInfo("LastHourPerMinute_"
                    + entry.getKey(), long[].class.getName(),
                    "Last hour of per minute values of "
                            + entry.getKey(), true, false, false));
            attributesList.add(new MBeanAttributeInfo("PerHour_"
                    + entry.getKey(), long.class.getName(),
                    "Current per hour value of " + entry.getKey(), true,
                    false, false));
            attributesList.add(new MBeanAttributeInfo("LastWeekPerHour_"
                    + entry.getKey(), long[].class.getName(),
                    "Last week of per hour values of " + entry.getKey(),
                    true, false, false));
            attributesList.add(new MBeanAttributeInfo("PerWeek_"
                    + entry.getKey(), long.class.getName(),
                    "Current per week value of " + entry.getKey(), true,
                    false, false));
            attributesList.add(new MBeanAttributeInfo("LastYearPerWeek_"
                    + entry.getKey(), long[].class.getName(),
                    "Last year of per week values of " + entry.getKey(),
                    true, false, false));
            typeNames.add(entry.getKey());
        }
        for (Type t : Type.values()) {
            final String name = t.name();
            if (!typeNames.contains(name)) {
                attributesList.add(new MBeanAttributeInfo(name, long.class
                        .getName(), "Current counter value of " + name,
                        true, false, false));
                typeNames.add(name);
            }
        }
View Full Code Here

        findFields();
        findMethods();
       
    attrInfo = new MBeanAttributeInfo[atts.size()];
    int i = 0;
    MBeanAttributeInfo info = null;
    for (AttributeEntry entry : atts.values()) {
      info = entry.getInfo();
      attrInfo[i++] = info;
    }
   
View Full Code Here

 
  private void findDescription() {
        MBean mbean=getObject().getClass().getAnnotation(MBean.class);
        if(mbean != null && mbean.description() != null && mbean.description().trim().length() > 0) {
            description=mbean.description();
            MBeanAttributeInfo info=new MBeanAttributeInfo(ResourceMBean.MBEAN_DESCRITION,
                                                           "java.lang.String",
                                                           "MBean description",
                                                           true,
                                                           false,
                                                           false);
View Full Code Here

                if(expose) {
                    String fieldName = attributeNameToMethodName(field.getName());
                    String descr=attr != null? attr.description() : prop.description();
                    boolean writable=attr != null? attr.writable() : prop.writable();

                    MBeanAttributeInfo info=new MBeanAttributeInfo(fieldName,
                                                                   field.getType().getCanonicalName(),
                                                                   descr,
                                                                   true,
                                                                   !Modifier.isFinal(field.getModifiers()) && writable,
                                                                   false);
View Full Code Here

    }
           
        String descr=attr != null ? attr.description() : prop != null? prop.description() : null;

        boolean writeAttribute=false;
        MBeanAttributeInfo info=null;
        if(isSetMethod(method)) { // setter
            attributeName=(attributeName==null)?methodName.substring(3):attributeName;
            info=new MBeanAttributeInfo(attributeName,
                                        method.getParameterTypes()[0].getCanonicalName(),
                                        descr,
                                        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(),
                                                descr,
                                                true,
                                                hasSetter,
                                                true);
                }
                else {
                    // this has to be get
                    attributeName=(attributeName==null)?methodName.substring(3):attributeName;
                    info=new MBeanAttributeInfo(attributeName,
                                                method.getReturnType().getCanonicalName(),
                                                descr,
                                                true,
                                                hasSetter,
                                                false);
                }
      } else {
              log.warn("Method " + method.getName() + " must have a valid return type and zero parameters");
                //silently skip this method
                return;
            }
        }
           
        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, findSetter(obj.getClass(), attributeName), 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(),
                                                                descr,
                                                                true,
                                                                !Modifier.isFinal(f.getModifiers()),
                                                                false);
View Full Code Here

            Iterator < PropertyField > iterator = m_configMap.getProperties()
                .iterator();
            while (iterator.hasNext()) {
                PropertyField propertyField = iterator.next();
                lAttributes.add(new MBeanAttributeInfo(propertyField.getName(),
                    propertyField.getType(), propertyField.getDescription(),
                    propertyField.isReadable(), propertyField.isWritable(),
                    false));
            }
            dAttributes = lAttributes
View Full Code Here

            else
               attribute = name.substring(3);

            String descr = description == null ? null : description.getAttributeDescription(attribute);

            MBeanAttributeInfo info = (MBeanAttributeInfo)attributes.get(attribute);

            if (info != null)
            {
               // JMX spec does not allow overloading attributes.
               // If an attribute with the same name already exists the MBean is not compliant
               if (!info.getType().equals(method.getReturnType().getName()))
               {
                  if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean is not compliant: has overloaded attribute " + attribute);
                  return null;
               }
               else
               {
                  // They return the same value,
                  if (getterNames.get(name) != null)
                  {
                    // This is the case of an attribute being present in multiple interfaces
                    // Ignore all but the first, since they resolve to the same method anyways
                   continue;                    
                  }
                 
          // there is a chance that one is a get-getter and one is a is-getter
          // for a boolean attribute. In this case, the MBean is not compliant.
                  if (info.isReadable())
                  {
                     if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean is not compliant: has overloaded attribute " + attribute);
                     return null;
                  }

                  // MBeanAttributeInfo is already present due to a setter method, just update its readability
                  info = new MBeanAttributeInfo(attribute, info.getType(), info.getDescription(), true, info.isWritable(), isIs);
               }
            }
            else
            {
               info = new MBeanAttributeInfo(attribute, method.getReturnType().getName(), descr, true, false, isIs);
            }

            // Replace if exists
            attributes.put(attribute, info);
      getterNames.put(name,method);
         }
         else if (Utils.isAttributeSetter(method))
         {
            String name = method.getName();
            String attribute = name.substring(3);

            String descr = description == null ? null : description.getAttributeDescription(attribute);

            MBeanAttributeInfo info = (MBeanAttributeInfo)attributes.get(attribute);

            if (info != null)
            {
               // JMX spec does not allow overloading attributes.
               // If an attribute with the same name already exists the MBean is not compliant
               if (!info.getType().equals(method.getParameterTypes()[0].getName()))
               {
                  if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean is not compliant: has overloaded attribute " + attribute);
                  return null;
               }
               else
               {
                  // MBeanAttributeInfo is already present due to a getter method, just update its writability
                  info = new MBeanAttributeInfo(info.getName(), info.getType(), info.getDescription(), info.isReadable(), true, info.isIs());
               }
            }
            else
            {
               info = new MBeanAttributeInfo(attribute, method.getParameterTypes()[0].getName(), descr, false, true, false);
            }

            // Replace if exists
            attributes.put(attribute, info);
         }
View Full Code Here

      MBeanAttributeInfo[] attrs = info.getAttributes();
      if (attrs == null || attrs.length == 0) throw new AttributeNotFoundException("No attributes defined for this MBean");

      for (int i = 0; i < attrs.length; ++i)
      {
         MBeanAttributeInfo attr = attrs[i];
         if (attr == null) continue;

         if (attribute.equals(attr.getName()))
         {
            if (!attr.isReadable()) throw new ReflectionException(new NoSuchMethodException("No getter defined for attribute: " + attribute));

            // Found, invoke via reflection
            String prefix = null;
            if (attr.isIs())
               prefix = "is";
            else
               prefix = "get";

            try
            {
               return invoke(resource, prefix + attr.getName(), new Class[0], new Object[0]);
            }
            catch (InvalidAttributeValueException x)
            {
               throw new ReflectionException(x);
            }
View Full Code Here

TOP

Related Classes of javax.management.MBeanAttributeInfo

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.