Class ReflectUtils


  • public class ReflectUtils
    extends java.lang.Object
    Methods to get/set attributes and invoke operations of a given instance.
    Since:
    5.2
    Author:
    Bela Ban
    • Constructor Summary

      Constructors 
      Constructor Description
      ReflectUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void _handleAttrWrite​(java.lang.Object target, java.lang.String attr_name, java.lang.String attr_value)  
      protected static void convert​(java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.Object>> in, java.util.Map<java.lang.String,​java.lang.String> out)  
      static java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.Object>> dumpSelectedAttributes​(java.lang.Object target, java.util.List<java.lang.String> attrs)
      Reads all attributes and values of the given target (annotated with ManagedAttribute and filters them if a non-null list of attributes is given
      static void dumpStats​(java.lang.Object obj, java.util.Map<java.lang.String,​java.lang.Object> map)  
      static void handleAttributeAccess​(java.util.Map<java.lang.String,​java.lang.String> map, java.lang.String attrs, java.lang.Object target)
      Handles an attribute read or write
      static void handleAttrWrite​(java.lang.Object target, java.lang.String attr_name, java.lang.String attr_value)  
      static java.lang.Object invoke​(java.lang.reflect.Method method, java.lang.Object target, java.lang.String[] args)  
      static void invokeOperation​(java.util.Map<java.lang.String,​java.lang.String> map, java.lang.String operation, java.lang.Object target)
      Invokes an operation and puts the return value into map
      static java.lang.String listOperations​(java.lang.Class<?> clazz)
      Prints all operations of clazz annotated with ManagedOperation
      protected static java.lang.String methodToString​(java.lang.reflect.Method m)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReflectUtils

        public ReflectUtils()
    • Method Detail

      • handleAttributeAccess

        public static void handleAttributeAccess​(java.util.Map<java.lang.String,​java.lang.String> map,
                                                 java.lang.String attrs,
                                                 java.lang.Object target)
        Handles an attribute read or write
      • dumpSelectedAttributes

        public static java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.Object>> dumpSelectedAttributes​(java.lang.Object target,
                                                                                                                                          java.util.List<java.lang.String> attrs)
        Reads all attributes and values of the given target (annotated with ManagedAttribute and filters them if a non-null list of attributes is given
        Parameters:
        target - The object to read the attributes from
        attrs - A list of attributes to match against. Example:
        bind
        with match
        bind_addr
        ,
        bind_port
        etc. If
        null
        , all attributes will be read.
        Returns:
        A map of attributes and values, keyed by the object's class
      • dumpStats

        public static void dumpStats​(java.lang.Object obj,
                                     java.util.Map<java.lang.String,​java.lang.Object> map)
      • listOperations

        public static java.lang.String listOperations​(java.lang.Class<?> clazz)
        Prints all operations of clazz annotated with ManagedOperation
      • invokeOperation

        public static void invokeOperation​(java.util.Map<java.lang.String,​java.lang.String> map,
                                           java.lang.String operation,
                                           java.lang.Object target)
                                    throws java.lang.Exception
        Invokes an operation and puts the return value into map
        Parameters:
        map -
        operation - Protocol.OperationName[args], e.g. STABLE.foo[arg1 arg2 arg3]
        target - The target object on which to invoke the operation
        Throws:
        java.lang.Exception
      • invoke

        public static java.lang.Object invoke​(java.lang.reflect.Method method,
                                              java.lang.Object target,
                                              java.lang.String[] args)
                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • convert

        protected static void convert​(java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.Object>> in,
                                      java.util.Map<java.lang.String,​java.lang.String> out)
      • handleAttrWrite

        public static void handleAttrWrite​(java.lang.Object target,
                                           java.lang.String attr_name,
                                           java.lang.String attr_value)
                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • _handleAttrWrite

        public static void _handleAttrWrite​(java.lang.Object target,
                                            java.lang.String attr_name,
                                            java.lang.String attr_value)
      • methodToString

        protected static java.lang.String methodToString​(java.lang.reflect.Method m)