Package javax.management

Examples of javax.management.Descriptor


      if (attrInfo == null) throw new AttributeNotFoundException("Cannot find ModelMBeanAttributeInfo for attribute " + attribute);
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Attribute info is: " + attrInfo);
      if (!attrInfo.isReadable()) throw new AttributeNotFoundException("Attribute " + attribute + " is not readable");

      // This returns a clone of the mbean descriptor, we use it read only
      Descriptor mbeanDescriptor = info.getMBeanDescriptor();
      if (mbeanDescriptor == null) throw new AttributeNotFoundException("MBean descriptor cannot be null");
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean descriptor is: " + mbeanDescriptor);

      // This descriptor is a clone
      Descriptor attributeDescriptor = attrInfo.getDescriptor();
      if (attributeDescriptor == null) throw new AttributeNotFoundException("Attribute descriptor for attribute " + attribute + " cannot be null");
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Attribute descriptor is: " + attributeDescriptor);

      Object returnValue = null;

      String lastUpdateField = "lastUpdatedTimeStamp";

      int staleness = getStaleness(attributeDescriptor, mbeanDescriptor, lastUpdateField);

      if (staleness == ALWAYS_STALE || staleness == STALE)
      {
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Value is stale");

         String getter = (String)attributeDescriptor.getFieldValue("getMethod");
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("getMethod field is: " + getter);
         if (getter == null)
         {
            // No getter, use default value
            returnValue = attributeDescriptor.getFieldValue("default");

            if (returnValue != null)
            {
               // Check if the return type is of the same type
               // As an extension allow covariant return type
               Class returned = returnValue.getClass();
               Class declared = loadClassWithContextClassLoader(attrInfo.getType());

               checkAssignability(returned, declared);
            }

            if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("getAttribute for attribute " + attribute + " returns default value: " + returnValue);
         }
         else
         {
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Invoking attribute getter...");
            // As an extension, allow attributes to be called on target objects also
            Object target = resolveTargetObject(attributeDescriptor);
            returnValue = invokeMethod(target, getter, new Class[0], new Object[0]);
            if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Returned value is: " + returnValue);

            if (returnValue != null)
            {
               // Check if the return type is of the same type
               // As an extension allow covariant return type
               Class returned = returnValue.getClass();
               Class declared = loadClassWithContextClassLoader(attrInfo.getType());

               checkAssignability(returned, declared);
            }

            // Cache the new value only if caching is needed
            if (staleness != ALWAYS_STALE)
            {
               attributeDescriptor.setField("value", returnValue);
               attributeDescriptor.setField(lastUpdateField, new Long(System.currentTimeMillis()));
               if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Returned value has been cached");

               // And now replace the descriptor with the updated clone
               info.setDescriptor(attributeDescriptor, "attribute");
            }

            if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("getAttribute for attribute " + attribute + " returns invoked value: " + returnValue);
         }
      }
      else
      {
         // Return cached value
         returnValue = attributeDescriptor.getFieldValue("value");

         if (returnValue != null)
         {
            // Check if the return type is of the same type
            // As an extension allow covariant return type
View Full Code Here


      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Attribute info is: " + attrInfo);

      if (!attrInfo.isWritable()) throw new AttributeNotFoundException("Attribute " + attrName + " is not writable");

      // This returns a clone of the mbean descriptor, we use it read only
      Descriptor mbeanDescriptor = info.getMBeanDescriptor();
      if (mbeanDescriptor == null) throw new AttributeNotFoundException("MBean descriptor cannot be null");
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean descriptor is: " + mbeanDescriptor);

      // This descriptor is a clone
      Descriptor attributeDescriptor = attrInfo.getDescriptor();
      if (attributeDescriptor == null) throw new AttributeNotFoundException("Attribute descriptor for attribute " + attrName + " cannot be null");
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Attribute descriptor is: " + attributeDescriptor);

      String lastUpdateField = "lastUpdatedTimeStamp";

      Object oldValue = null;
      try
      {
         oldValue = getAttribute(attrName);
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Previous value of attribute " + attrName + ": " + oldValue);
      }
      catch (Exception x)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot get previous value of attribute " + attrName, x);
      }

      // Check if setMethod is present
      String method = (String)attributeDescriptor.getFieldValue("setMethod");
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("setMethod field is: " + method);
      if (method != null)
      {
         Class declared = loadClassWithContextClassLoader(attrInfo.getType());
         if (attrValue != null)
         {
            Class parameter = attrValue.getClass();
            checkAssignability(parameter, declared);
         }

         // As an extension, allow attributes to be called on target objects also
         Object target = resolveTargetObject(attributeDescriptor);
         invokeMethod(target, method, new Class[]{declared}, new Object[]{attrValue});

         // Cache the value only if currencyTimeLimit is not 0, ie it is not always stale
         int staleness = getStaleness(attributeDescriptor, mbeanDescriptor, lastUpdateField);
         if (staleness != ALWAYS_STALE)
         {
            attributeDescriptor.setField("value", attrValue);
            attributeDescriptor.setField(lastUpdateField, new Long(System.currentTimeMillis()));
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Attribute's value has been cached");
         }
         else
         {
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Always stale, avoiding to cache attribute's value");
         }
      }
      else
      {
         if (attrValue != null)
         {
            Class parameter = attrValue.getClass();
            Class declared = loadClassWithContextClassLoader(attrInfo.getType());

            checkAssignability(parameter, declared);
         }

         // Always store the value in the descriptor: no setMethod
         attributeDescriptor.setField("value", attrValue);
      }

      // And now replace the descriptor with the updated clone
      info.setDescriptor(attributeDescriptor, "attribute");
View Full Code Here

         }
      }
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Operation info is: " + operInfo);

      // This descriptor is a clone
      Descriptor operationDescriptor = operInfo.getDescriptor();
      if (operationDescriptor == null) throw new MBeanException(new ServiceNotFoundException("Operation descriptor for operation " + method + " cannot be null"));
      String role = (String)operationDescriptor.getFieldValue("role");
      if (role == null || !role.equals("operation")) throw new MBeanException(new ServiceNotFoundException("Operation descriptor field 'role' must be 'operation', not " + role));
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Operation descriptor is: " + operationDescriptor);

      // This returns a clone of the mbean descriptor, we use it read only
      Descriptor mbeanDescriptor = info.getMBeanDescriptor();
      if (mbeanDescriptor == null) throw new MBeanException(new ServiceNotFoundException("MBean descriptor cannot be null"));
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean descriptor is: " + mbeanDescriptor);

      Object returnValue = null;
View Full Code Here

   {
      // Get a copy to avoid synchronization
      ModelMBeanInfo info = getModelMBeanInfo();

      // First look if there is a suitable notification descriptor, otherwise use MBean descriptor
      Descriptor descriptor = null;
      Logger modelMBeanLogger = null;
      if (notificationType != null)
      {
         descriptor = info.getDescriptor(notificationType, "notification");
         modelMBeanLogger = findLogger(descriptor);
View Full Code Here

      {
         // Not yet initialized
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Can't find persister, ModelMBeanInfo is null");
         return null;
      }
      Descriptor mbeanDescriptor = info.getMBeanDescriptor();
      if (mbeanDescriptor == null)
      {
         // This is normally should not happen if ModelMBeanInfoSupport is used
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Can't find persister, MBean descriptor is null");
         return null;
      }

      String location = (String)mbeanDescriptor.getFieldValue("persistLocation");
      String name = (String)mbeanDescriptor.getFieldValue("persistName");
      String mbeanName = (String)mbeanDescriptor.getFieldValue("name");
      if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Persistence fields: location=" + location + ", name=" + name);

      if (mbeanName == null && name == null)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Persistence is not supported by this ModelMBean");
View Full Code Here

              makeDescriptor(openType,
                             defaultValue, legalValues, minValue, maxValue));

        this.openType = openType;

        Descriptor d = getDescriptor();
        this.defaultValue = defaultValue;
        this.minValue = minValue;
        this.maxValue = maxValue;
        // We already converted the array into an unmodifiable Set
        // in the descriptor.
        this.legalValues = (Set<?>) d.getFieldValue("legalValues");

        check(this);
    }
View Full Code Here

              makeDescriptor(openType,
                             defaultValue, legalValues, minValue, maxValue));

        this.openType = openType;

        Descriptor d = getDescriptor();
        this.defaultValue = defaultValue;
        this.minValue = minValue;
        this.maxValue = maxValue;
        // We already converted the array into an unmodifiable Set
        // in the descriptor.
        this.legalValues = (Set<?>) d.getFieldValue("legalValues");

        check(this);
    }
View Full Code Here

    static boolean equal(OpenMBeanParameterInfo x1, OpenMBeanParameterInfo x2) {
        if (x1 instanceof DescriptorRead) {
            if (!(x2 instanceof DescriptorRead))
                return false;
            Descriptor d1 = ((DescriptorRead) x1).getDescriptor();
            Descriptor d2 = ((DescriptorRead) x2).getDescriptor();
            if (!d1.equals(d2))
                return false;
        } else if (x2 instanceof DescriptorRead)
            return false;
View Full Code Here

        //
        return myToString;
    }

    static String toString(OpenMBeanParameterInfo info) {
        Descriptor d = (info instanceof DescriptorRead) ?
            ((DescriptorRead) info).getDescriptor() : null;
        return
            info.getClass().getName() +
            "(name=" + info.getName() +
            ",openType=" + info.getOpenType() +
View Full Code Here

        modelMBeanConstructors = mbi.getConstructors();
        modelMBeanOperations = mbi.getOperations();
        modelMBeanNotifications = mbi.getNotifications();

        try {
            Descriptor mbeandescriptor = mbi.getMBeanDescriptor();
            modelMBeanDescriptor = validDescriptor(mbeandescriptor);
        } catch (MBeanException mbe) {
            modelMBeanDescriptor = validDescriptor(null);
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
                MODELMBEAN_LOGGER.logp(Level.FINER,
View Full Code Here

TOP

Related Classes of javax.management.Descriptor

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.