Class ListenerMethodFinder

java.lang.Object
it.rebirthproject.ufoeb.services.ListenerMethodFinder

public class ListenerMethodFinder extends Object
The ListenerMethodFinder is a service used to retrieve registered listeners methods annotated with Listen and to store them inside the MemoryState
  • Field Details

    • BRIDGE

      private static final int BRIDGE
      In newer class files, compilers may add methods. Those are called bridge or synthetic methods. UfoEventBus must ignore both. There modifiers are not public but defined in the Java class file format:
      See Also:
    • SYNTHETIC

      private static final int SYNTHETIC
      In newer class files, compilers may add methods. Those are called bridge or synthetic methods. UfoEventBus must ignore both. There modifiers are not public but defined in the Java class file format:
      See Also:
    • MODIFIERS_IGNORE

      private static final int MODIFIERS_IGNORE
      In newer class files, compilers may add methods. Those are called bridge or synthetic methods. UfoEventBus must ignore both. There modifiers are not public but defined in the Java class file format:
      See Also:
    • EMPTY_INHERITANCE_PACKAGE_FRONTIER_PATH

      private static final String EMPTY_INHERITANCE_PACKAGE_FRONTIER_PATH
      A default empty inheritance package frontier path
      See Also:
    • listenerSuperclassInheritance

      private final boolean listenerSuperclassInheritance
      This parameter should be used when you want to use inheritance over a listener and all its superclasses. Enabling it will let the bus look for all listeners' methods considering also all their superclasses methods. The default value is to look for only the listener's class methods.
      See Also:
    • throwNotValidMethodException

      private final boolean throwNotValidMethodException
      if set then an EventBusException is thrown when an invalid Listen annotated method is found in a Listener.
      See Also:
    • throwNoListenerAnnotationException

      private final boolean throwNoListenerAnnotationException
      If a registering listener does not have any Listen annotated method or, in case of event inheritance enabled, also its super classes or interfaces does not have any Listen annotated method, then an EventBusException is thrown.
      See Also:
    • useLambdaFactoryInsteadOfStandardReflection

      private final boolean useLambdaFactoryInsteadOfStandardReflection
      This set the usage of Lambdafactory instead of standard java reflection
      See Also:
    • inheritancePackageFrontierPath

      private final String inheritancePackageFrontierPath
      Sets the package used to stop the iteration over classes while using event inheritance. If a class belongs to the set package then the iteration stops. This parameter must be used only when event inheritance policy is enabled otherwise it is useless even if set.
      See Also:
  • Constructor Details

    • ListenerMethodFinder

      public ListenerMethodFinder(boolean listenerSuperclassInheritance, boolean throwNotValidMethodException, boolean throwNoListenerAnnotationException, boolean useLambdaFactoryInsteadOfStandardReflection, String inheritancePackageFrontierPath)
      Class constructor used to build a ListenerMethodFinder
      Parameters:
      listenerSuperclassInheritance - Parameter used to initialize the attribute listenerSuperclassInheritance
      throwNotValidMethodException - Parameter used to initialize the attribute throwNotValidMethodException
      throwNoListenerAnnotationException - Parameter used to initialize the attribute throwNoListenerAnnotationException
      useLambdaFactoryInsteadOfStandardReflection - Parameter used to initialize the attribute useLambdaFactoryInsteadOfStandardReflection
      inheritancePackageFrontierPath - Parameter used to initialize the attribute inheritancePackageFrontierPath
  • Method Details

    • findListenerMethods

      public void findListenerMethods(Object listenerToRegister, MemoryState memoryState) throws EventBusException
      Method used to retrieve all the listener's methods annotated with the Listen annotation and to update the MemoryState accordingly.
      Parameters:
      listenerToRegister - The Listen annotated methods' listener.
      memoryState - The eventbus MemoryState
      Throws:
      EventBusException - is thrown if some exception occurs during the execution of this method
    • isClassProcessableByPackage

      private boolean isClassProcessableByPackage(String className)
      This method is used to check if the listener class is processable analyzing its package. There are two methods: - the check over a given inheritance frontier path package (for example the package of the application that uses the EventBus). - the check over hardcoded basic java packages (that can depends even on Android platform). This method is used only when the frontier path is not specified.
      Parameters:
      className - The listener class
      Returns:
      A boolean that states if the loop must continue or not.
    • findAllMethods

      private Method[] findAllMethods(Class<?> clazz) throws EventBusException
      This method finds all methods defined in a given class.
      Parameters:
      clazz - The given class to search for methods.
      Returns:
      The methods found in the given class.
      Throws:
      EventBusException - If the reflection raises an exception, this will be wrapped into an EventBusException