Class HookFactory

java.lang.Object
org.jppf.utils.hooks.HookFactory

public class HookFactory extends Object
Factcory methods for the registration and invocation of hooks.
Author:
Laurent Cohen
  • Constructor Details

    • HookFactory

      public HookFactory()
  • Method Details

    • newInstance

      public static HookFactory newInstance()
      Create a new HookFactory.
      Returns:
      a new HookFactory instance.
    • registerConfigSingleHook

      public <T> Hook<T> registerConfigSingleHook(JPPFProperty<String> property, Class<T> infClass, T defaultImpl, ClassLoader classLoader)
      Register a hook defined via a configuration property, of which a single instance is discovered and invoked.
      Type Parameters:
      T - the type of the hook interface.
      Parameters:
      property - the name of the property used to specify the hook implementation class name.
      infClass - the class of the hook's interface.
      defaultImpl - the default implementation, which may be null.
      classLoader - the class loader used to load the implementation.
      Returns:
      the registered hook as a Hook instance.
    • registerConfigSingleHook

      public <T> Hook<T> registerConfigSingleHook(JPPFProperty<String> property, Class<T> infClass, T defaultImpl, ClassLoader classLoader, Class<?>[] paramTypes, Object... params)
      Register a hook defined via a configuration property, of which a single instance is discovered and invoked.
      Type Parameters:
      T - the type of the hook interface.
      Parameters:
      property - the name of the property used to specify the hook implementation class name.
      infClass - the class of the hook's interface.
      defaultImpl - the default implementation, which may be null.
      classLoader - the class loader used to load the implementation.
      paramTypes - types of the parameters to pass to the constructor.
      params - the parameters to pass to the constructor.
      Returns:
      the registered hook as a Hook instance.
    • registerSPISingleHook

      public <T> Hook<T> registerSPISingleHook(Class<T> infClass, T defaultImpl, ClassLoader classLoader)
      Register a hook defined via SPI, of which a single instance is discovered and invoked.
      Type Parameters:
      T - the type of the hook interface.
      Parameters:
      infClass - the class of the hook's interface.
      defaultImpl - the default implementation, which may be null.
      classLoader - the class loader used to load the implementation.
      Returns:
      the registered hook as a Hook instance.
    • registerSPISingleHook

      public <T> Hook<T> registerSPISingleHook(Class<T> infClass, T defaultImpl, ClassLoader classLoader, Class<?>[] paramTypes, Object... params)
      Register a hook defined via SPI, of which a single instance is discovered and invoked.
      Type Parameters:
      T - the type of the hook interface.
      Parameters:
      infClass - the class of the hook's interface.
      defaultImpl - the default implementation, which may be null.
      classLoader - the class loader used to load the implementation.
      paramTypes - types of the parameters to pass to the constructor.
      params - the parameters to pass to the constructor.
      Returns:
      the registered hook as a Hook instance.
    • registerSPIMultipleHook

      public <T> Hook<T> registerSPIMultipleHook(Class<T> infClass, T defaultImpl, ClassLoader classLoader)
      Register a hook defined via SPI, for which all looked up instances are discovered and invoked.
      Type Parameters:
      T - the type of the hook interface.
      Parameters:
      infClass - the class of the hook's interface.
      defaultImpl - the default implementation, which may be null.
      classLoader - the class loader used to load the implementation.
      Returns:
      the registered hook as a Hook instance.
    • registerSPIMultipleHook

      public <T> Hook<T> registerSPIMultipleHook(Class<T> infClass, T defaultImpl, ClassLoader classLoader, Class<?>[] paramTypes, Object... params)
      Register a hook defined via SPI, for which all looked up instances are discovered and invoked.
      Type Parameters:
      T - the type of the hook interface.
      Parameters:
      infClass - the class of the hook's interface.
      defaultImpl - the default implementation, which may be null.
      classLoader - the class loader used to load the implementation.
      paramTypes - types of the parameters to pass to the constructor.
      params - the parameters to pass to the constructor.
      Returns:
      the registered hook as a Hook instance.
    • unregister

      public <T> void unregister(Class<T> infClass)
      Register a hook defined via SPI, of which a single instance is discovered and invoked.
      Type Parameters:
      T - the type of the hook interface.
      Parameters:
      infClass - the class of the hook's interface.
    • invokeHook

      public Object[] invokeHook(String inf, String methodName, Object... parameters)
      Invoke all instances of the hook with the specified interface name, with the specified parameters.
      Parameters:
      inf - the hook's interface name.
      methodName - the name of the implementation method to invoke.
      parameters - the parameters with which to invoke the hook.
      Returns:
      the hook instance return value if the hook id defined with a single instance, null otherwise.
    • invokeHook

      public Object[] invokeHook(Class<?> inf, String methodName, Object... parameters)
      Invoke all instances of the hook with the specified interface name, with the specified parameters.
      Parameters:
      inf - the hook's interface.
      methodName - the name of the implementation method to invoke.
      parameters - the parameters with which to invoke the hook.
      Returns:
      the hook instance return value if the hook id defined with a single instance, null otherwise.
    • invokeSingleHook

      public Object invokeSingleHook(String inf, String methodName, Object... parameters)
      Invoke all instances of the hook with the specified interface name, with the specified parameters.
      Parameters:
      inf - the hook's interface name.
      methodName - the name of the implementation method to invoke.
      parameters - the parameters with which to invoke the hook.
      Returns:
      the hook instance return value if the hook id defined with a single instance, null otherwise.
    • invokeSingleHook

      public Object invokeSingleHook(Class<?> inf, String methodName, Object... parameters)
      Invoke all instances of the hook with the specified interface name, with the specified parameters.
      Parameters:
      inf - the hook's interface.
      methodName - the name of the implementation method to invoke.
      parameters - the parameters with which to invoke the hook.
      Returns:
      the hook instance return value if the hook id defined with a single instance, null otherwise.
    • reset

      public void reset()
      Reset this factory to its original state.