User: juhalindfors
  Date: 02/03/19 14:51:00

  Modified:    src/main/org/jboss/mx/interceptor Tag: BranchMX_1_0
                        MBeanAttributeInterceptor.java
  Log:
  merge to 1.0
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +78 -13    
jmx/src/main/org/jboss/mx/interceptor/MBeanAttributeInterceptor.java
  
  Index: MBeanAttributeInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/org/jboss/mx/interceptor/MBeanAttributeInterceptor.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- MBeanAttributeInterceptor.java    8 Mar 2002 10:38:48 -0000       1.2
  +++ MBeanAttributeInterceptor.java    19 Mar 2002 22:51:00 -0000      1.2.2.1
  @@ -17,6 +17,8 @@
   import javax.management.modelmbean.ModelMBeanInfoSupport;
   
   import org.jboss.mx.modelmbean.ModelMBeanConstants;
  +import org.jboss.mx.modelmbean.ModelBase;    // should be renamed ModelMBeanInvoker
  +import org.jboss.mx.server.MBeanInvoker;
   
   /**
    * Quick hack, non mapping/caching attribute interceptor
  @@ -31,13 +33,15 @@
   {
   
      // Attributes ----------------------------------------------------
  -   private ModelMBeanInfo info = null;
  -
  +   private ModelMBeanInfo info  = null;
  +   private MBeanInvoker invoker = null;
  +   
      // Constructors --------------------------------------------------
  -   public MBeanAttributeInterceptor(ModelMBeanInfo info)
  +   public MBeanAttributeInterceptor(ModelMBeanInfo info, MBeanInvoker invoker)
      {
         super("MBean Attribute Interceptor");
         this.info = info;
  +      this.invoker = invoker;
      }
   
      // Public --------------------------------------------------------
  @@ -48,22 +52,83 @@
   
         try
         {
  +         // name of the attribute
  +         String attrName = invocation.getName();
  +
            // this is mighty slow as we copy all over, will do for now
  -         Descriptor d = info.getDescriptor(invocation.getName(), 
ATTRIBUTE_DESCRIPTOR);
  -         
  +         Descriptor d = info.getDescriptor(attrName, ATTRIBUTE_DESCRIPTOR);
  +                  
  +         // SetAttribute         
            if (invocation.getImpact() == Invocation.WRITE)
            {
  -            d.setField(VALUE, invocation.getArgs() [0]);
  -            info.setDescriptor(d, ATTRIBUTE_DESCRIPTOR);
  +            Object value    = invocation.getArgs() [0];
  +            Object oldValue = d.getFieldValue(VALUE);
  +            
  +            String setMethod = (String)d.getFieldValue(SET_METHOD);
  +            
  +            // if setMethod is available, invoke it
  +            if (setMethod != null)
  +            {               
  +               invoker.invoke(setMethod, new Object[] { value }, 
invocation.getSignature());
  +            }
  +
  +            // if caching is not disabled (currencyTimeLimit != 0) update 
descriptors
  +            String timeLimit = (String)d.getFieldValue(CURRENCY_TIME_LIMIT);
  +            long limit = (timeLimit == null) ? 0 : Long.parseLong(timeLimit);
               
  -            // there's no mapping there
  -            //return getNext().invoke(invocation);
  -            return d.getFieldValue(VALUE);
  +            if (limit != 0)
  +            {
  +               d.setField(VALUE, value);
  +               d.setField(LAST_UPDATED_TIME_STAMP, "" + System.currentTimeMillis() 
/ 1000);
  +               info.setDescriptor(d, ATTRIBUTE_DESCRIPTOR);
  +            }
  +            
  +            // send notification
  +            ((ModelBase)invoker).sendAttributeChangeNotification(
  +                  new Attribute(attrName, oldValue),
  +                  new Attribute(attrName, value)
  +            );
            }
  +         
  +         // GetAttribute
            else
  -         {
  -            return d.getFieldValue(VALUE);
  +         {   
  +            String getMethod = (String)d.getFieldValue(GET_METHOD);
  +            
  +            // are we mapping to a getter operation ?
  +            if (getMethod != null)
  +            {
  +               // are we caching the attribute value?
  +               String timeLimit = (String)d.getFieldValue(CURRENCY_TIME_LIMIT);
  +               long limit = (timeLimit == null) ? 0 : Long.parseLong(timeLimit);
  +
  +               // if -1 we never invoke the getter
  +               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
  +               Object value = invoker.invoke(getMethod, new Object[0], new 
String[0]);
  +               
  +               // update the descriptor
  +               d.setField(VALUE, value);
  +               d.setField(LAST_UPDATED_TIME_STAMP, "" + System.currentTimeMillis() 
/ 1000);
  +               
  +               info.setDescriptor(d, ATTRIBUTE_DESCRIPTOR);
  +            }
            }
  +         
  +         return d.getFieldValue(VALUE);
         }
         catch (Throwable t)
         {
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to