Package javax.management

Examples of javax.management.Descriptor


            attributes[i].isWritable(),
            attributes[i].isIs()
         );
        
         // by default, conversion metadata should not try to cache attributes
         Descriptor d = attrInfo.getDescriptor();
         d.setField(CURRENCY_TIME_LIMIT, CACHE_NEVER);
         attrInfo.setDescriptor(d);
        
         mmbAttributes[i] = attrInfo;

         // if we're doing attribute operation mapping, find the accessor methods
         // from the Standard MBean interface, and create the 'setter' and 'getter'
         // management operations for them. Map the Model MBean attributes to
         // these operations.
         if (createAttributeOperationMapping)
         {
            String getterOperationName  = null;
            String setterOperationName  = null;
            Descriptor getterDescriptor = null;
            Descriptor setterDescriptor = null;
           
            // figure out the getter type
            if (attributes[i].isReadable())
            {
               if (attributes[i].isIs())
                  getterOperationName = "is" + attributes[i].getName();
               else
                  getterOperationName = "get" + attributes[i].getName();
                 
               // create a descriptor for 'getter' mgmt operation
               getterDescriptor = new DescriptorSupport();
               getterDescriptor.setField(NAME, getterOperationName);
               getterDescriptor.setField(DESCRIPTOR_TYPE, OPERATION_DESCRIPTOR);
               getterDescriptor.setField(ROLE, GETTER);
              
               // create the new management operation
               ModelMBeanOperationInfo opInfo = new ModelMBeanOperationInfo(
                     getterOperationName,
                     "Read accessor operation for '" + attributes[i].getName() + "' attribute.",
                     new MBeanParameterInfo[0],    // void signature
                     attributes[i].getType(),      // return type
                     MBeanOperationInfo.INFO,      // impact
                     getterDescriptor
               );

               // modify the attributes descriptor to map the read operation
               // to the above created management operation
               Descriptor attrDescriptor = mmbAttributes[i].getDescriptor();
               attrDescriptor.setField(GET_METHOD, getterOperationName);
               mmbAttributes[i].setDescriptor(attrDescriptor);
              
               accessorOperations.add(opInfo);
            }
           
            // figure out the setter
            if (attributes[i].isWritable())
            {
               setterOperationName = "set" + attributes[i].getName();  
              
               // create a descriptor for 'setter' mgmt operation
               setterDescriptor = new DescriptorSupport();
               setterDescriptor.setField(NAME, setterOperationName);
               setterDescriptor.setField(DESCRIPTOR_TYPE, OPERATION_DESCRIPTOR);
               setterDescriptor.setField(ROLE, SETTER);
              
               // create the new management operation
               ModelMBeanOperationInfo opInfo = new ModelMBeanOperationInfo(
                     setterOperationName,
                     "Write accessor operation for '" + attributes[i].getName() + "' attribute.",
                    
                     new MBeanParameterInfo[] {
                        new MBeanParameterInfo("value", attributes[i].getType(), "Attribute's value.")
                     },
                    
                     Void.TYPE.getName(),
                     MBeanOperationInfo.ACTION,
                     setterDescriptor
               );
              
               // modify the attributes descriptor to map the read operation
               // to the above created management operation
               Descriptor attrDescriptor = mmbAttributes[i].getDescriptor();
               attrDescriptor.setField(SET_METHOD, setterOperationName);
               mmbAttributes[i].setDescriptor(attrDescriptor);
              
               accessorOperations.add(opInfo);
            }
         }           
View Full Code Here


         Attribute persistPeriod = root.getAttribute(PERSIST_PERIOD);
         Attribute persistLocation = root.getAttribute(PERSIST_LOCATION);
         Attribute persistName = root.getAttribute(PERSIST_NAME);
         Attribute currTimeLimit = root.getAttribute(CURRENCY_TIME_LIMIT);

         Descriptor descr = new DescriptorSupport();
         descr.setField("name", mmbClassName);
         descr.setField("descriptorType", "mbean");

         if (persistPolicy != null)
            descr.setField(PERSIST_POLICY, persistPolicy.getValue());
         if (persistPeriod != null)
            descr.setField(PERSIST_PERIOD, persistPeriod.getValue());
         if (persistLocation != null)
            descr.setField(PERSIST_LOCATION, persistLocation.getValue());
         if (persistName != null)
            descr.setField(PERSIST_NAME, persistName.getValue());
         if (currTimeLimit != null)
            descr.setField(CURRENCY_TIME_LIMIT, currTimeLimit.getValue());

         ModelMBeanInfo info = buildMBeanMetaData(
            description, constructors, operations,
            attributes, notifications, descr
         );
View Full Code Here

         Attribute persistPeriod = attr.getAttribute(PERSIST_PERIOD);
         Attribute setMethod = attr.getAttribute(SET_METHOD);
         Attribute getMethod = attr.getAttribute(GET_METHOD);
         Attribute currTimeLimit = attr.getAttribute(CURRENCY_TIME_LIMIT);

         Descriptor descr = new DescriptorSupport();
         descr.setField("name", name);
         descr.setField("descriptorType", "attribute");

         if (persistPolicy != null)
            descr.setField(PERSIST_POLICY, persistPolicy.getValue());
         if (persistPeriod != null)
            descr.setField(PERSIST_PERIOD, persistPeriod.getValue());
         if (setMethod != null)
            descr.setField(SET_METHOD, setMethod.getValue());
         if (getMethod != null)
            descr.setField(GET_METHOD, getMethod.getValue());
         if (currTimeLimit != null)
            descr.setField(CURRENCY_TIME_LIMIT, currTimeLimit.getValue());

         // if no method mapping, enable caching automatically
         if (setMethod == null && getMethod == null && currTimeLimit == null)
            descr.setField(CURRENCY_TIME_LIMIT, "-1");        
           
         // defaults read-write
         boolean isReadable = true;
         boolean isWritable = true;
View Full Code Here

   {
      try
      {
         MBeanServer server = MBeanServerFactory.createMBeanServer();
        
         Descriptor descriptor = new DescriptorSupport();
         descriptor.setField(NAME, "Active");
         descriptor.setField(DESCRIPTOR_TYPE, ATTRIBUTE_DESCRIPTOR);
         descriptor.setField(PERSIST_POLICY, PM_ON_TIMER);
         descriptor.setField(PERSIST_PERIOD, "1000");
        
         ModelMBeanAttributeInfo attrInfo = new ModelMBeanAttributeInfo(
               "Active",
               boolean.class.getName(),
               "Test Attribute",
View Full Code Here

   // Public --------------------------------------------------------
  
   public Object invoke(Invocation invocation) throws InvocationException
   {
      // get the attribute's descriptor
      Descriptor d    = invocation.getDescriptor();
     
      // check the invocation access point: setAttribute()  
      if (invocation.getType().equals(Invocation.OP_SETATTRIBUTE))
      {
         // setAttribute always contains one arg
         Object value    = invocation.getArgs() [0];
        
         // store the old value of this attribute for notification
         Object oldValue = d.getFieldValue(VALUE);

         // check if the attribute maps to a setter
         String setMethod = (String)d.getFieldValue(SET_METHOD);

         MBeanInvoker invoker = invocation.getInvoker();              
        
         if (setMethod != null)
         { 
            // TODO: should investigate chaining invocations rather than
            //       going back to the invoker (JPL)
           
            // if setter was found, invoke the corresponding setter operation
            try
            {
               invoker.invoke(setMethod, new Object[] { value }, new String[] { invocation.getAttributeType() });
            }
            catch (Throwable t)
            {
               throw new InvocationException(t);
            }
         }

         // get the currency time limit value
         String timeLimit = (String)d.getFieldValue(CURRENCY_TIME_LIMIT);
         long limit = (timeLimit == null) ? 0 : Long.parseLong(timeLimit);
           
         // if caching is not disabled, update the descriptor fields
         if (limit != 0)
         {
            d.setField(VALUE, value);
            d.setField(LAST_UPDATED_TIME_STAMP, "" + System.currentTimeMillis() / 1000);
            invocation.setDescriptor(d);
         }
        
         // send notification
         try
         {
            ((ModelMBeanInvoker)invoker).sendAttributeChangeNotification(
               new Attribute(invocation.getName(), oldValue),
               new Attribute(invocation.getName(), value)
            );        
         }
         catch (MBeanException e)
         {
            throw new InvocationException(e, "attribute change notification error");
         }
      }
        
      else if (invocation.getType().equals(Invocation.OP_GETATTRIBUTE))
      {  
         // get the attribute's descriptor
         String getMethod = (String)d.getFieldValue(GET_METHOD);
        
         if (getMethod != null)
         {
            String timeLimit = (String)d.getFieldValue(CURRENCY_TIME_LIMIT);
            long limit = (timeLimit == null) ? 0 : Long.parseLong(timeLimit);

            if (limit == -1)
               return d.getFieldValue(VALUE);
 
            // if >0 caching is enabled
            if (limit > 0)
            {
               String timeStamp = (String)d.getFieldValue(LAST_UPDATED_TIME_STAMP);
               long lastUpdate = (timeStamp == null) ? 0 : Long.parseLong(timeStamp);
          
               // if the value hasn't gone stale, return from the descriptor
               if (System.currentTimeMillis() < lastUpdate * 1000 + limit * 1000)
                  return d.getFieldValue(VALUE);
            }

            // we got here means either stale value in descriptior, or zero time limit
            MBeanInvoker invoker = invocation.getInvoker();
            Object value = null;
           
            try
            {
               value = invoker.invoke(getMethod, new Object[0], new String[0]);
            }
            catch (Throwable t)
            {
               throw new InvocationException(t);
            }
           
            // update the descriptor
            d.setField(VALUE, value);
            d.setField(LAST_UPDATED_TIME_STAMP, "" + System.currentTimeMillis() / 1000);
           
            invocation.setDescriptor(d);
         }
      }
     
      //Object o = invocation.ret(d.getFieldValue(VALUE));
      //return o;
     
      //super.invoke(invocation);
      return d.getFieldValue(VALUE);
     
/*     if (invocation.getInvocationType() == Invocation.OPERATION)
         return getNext().invoke(invocation);

      try
View Full Code Here

      return mbeanDescriptor;
   }

   public void setMBeanDescriptor(Descriptor inMBeanDescriptor) throws MBeanException
   {
      Descriptor descr = (Descriptor)inMBeanDescriptor.clone();
      addDefaultMBeanDescriptorFields(descr);

      this.mbeanDescriptor = descr;
   }
View Full Code Here

       *        not mandated by the spec). Hence the deprecated tag.   [JPL]
       */
      if (descrName.equals(mbeanDescriptor.getFieldValue(ModelMBeanConstants.NAME)))
         return mbeanDescriptor;

      Descriptor descr = null;

      descr = (Descriptor)getAttributeDescriptors().get(descrName);
      if (descr != null)
         return descr;

View Full Code Here

   {
      MBeanAttributeInfo[] attrInfo;
      MBeanConstructorInfo[] consInfo;
      MBeanOperationInfo[] operInfo;
      MBeanNotificationInfo[] ntfyInfo;
      Descriptor desc;

      ObjectInputStream.GetField getField = ois.readFields();
      switch (Serialization.version)
      {
      case Serialization.V1R0:
View Full Code Here

            for (int i = 0; i < attrs.length; i++)
                System.out.println("  AttributeInfo=" + attrs[i]);
            MBeanConstructorInfo consts[] = info.getConstructors();
            for (int i = 0; i < consts.length; i++)
                System.out.println("  ConstructorInfo=" + consts[i]);
            Descriptor descs[] = info.getDescriptors(null);
            for (int i = 0; i < descs.length; i++)
                System.out.println("  Descriptor=" + descs[i]);
            MBeanNotificationInfo notifs[] = info.getNotifications();
            for (int i = 0; i < notifs.length; i++)
                System.out.println("  Notification=" + notifs[i]);
View Full Code Here

    */
   public void testDescriptorSupportDefaultConstructor()
   {
      try
      {
         Descriptor d1 = new DescriptorSupport();
      }
      catch (AssertionFailedError e)
      {
         throw e;
      }
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.