Package javax.management

Examples of javax.management.Descriptor


    */
   public void testDescriptorSupportInitialSizeConstructor()
   {
      try
      {
         Descriptor d2 = new DescriptorSupport(100);
       
         try
         {
            Descriptor d3 = new DescriptorSupport(0);
           
            // shouldn't reach here
            fail("RuntimeOperationsException should have been thrown when DescriptorSupport is created with zero initial size.");
         }
         catch (RuntimeOperationsException e)
         {
            // this is expected
         }
        
         try
         {
            Descriptor d4 = new DescriptorSupport(-100);
           
            // shouldn't reach here
            fail("RuntimeOperationsException should have been thrown when DescriptorSupport is created with negative initial size.");
         }
         catch (RuntimeOperationsException e)
View Full Code Here


      try
      {
         DescriptorSupport d = new DescriptorSupport();
         d.setField("foo", "bar");
        
         Descriptor clone = (Descriptor)d.clone();
         assertTrue(clone.getFieldValue("foo").equals("bar"));
      }
      catch (AssertionFailedError e)
      {
         throw e;
      }
View Full Code Here

    /**
     * @return notificationInfo
     */
    public MBeanNotificationInfo[] getNotificationInfo() {
        MBeanNotificationInfo[] result = new MBeanNotificationInfo[2];
        Descriptor genericDescriptor = new DescriptorSupport(new String[]{"name=GENERIC",
                "descriptorType=notification", "log=T", "severity=5", "displayName=jmx.modelmbean.generic"});
        result[0] = new ModelMBeanNotificationInfo(new String[]{"jmx.modelmbean.generic"}, "GENERIC",
                "A text notification has been issued by the managed resource", genericDescriptor);
        Descriptor attributeDescriptor = new DescriptorSupport(new String[]{"name=ATTRIBUTE_CHANGE",
                "descriptorType=notification", "log=T", "severity=5", "displayName=jmx.attribute.change"});
        result[1] = new ModelMBeanNotificationInfo(new String[]{"jmx.attribute.change"}, "ATTRIBUTE_CHANGE",
                "Signifies that an observed MBean attribute value has changed", attributeDescriptor);
        return result;
    }
View Full Code Here

      else
      {
         MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes();
         for (int i = 0; i < ai.length; i++)
         {
            Descriptor d = ((ModelMBeanAttributeInfo)ai[i]).getDescriptor();
            filter.enableAttribute((String)d.getFieldValue("name"));
         }
      }

      getAttributeChangeBroadcaster().addNotificationListener(listener, filter, handback);
View Full Code Here

      else
      {
         MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes();
         for (int i = 0; i < ai.length; i++)
         {
            Descriptor d = ((ModelMBeanAttributeInfo)ai[i]).getDescriptor();
            filter.enableAttribute((String)d.getFieldValue("name"));
         }
      }

      getAttributeChangeBroadcaster().removeNotificationListener(listener, filter, handback);
View Full Code Here

      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

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.