Package org.jppf.utils.hooks
Class HookFactory
java.lang.Object
org.jppf.utils.hooks.HookFactory
Factcory methods for the registration and invocation of hooks.
- Author:
- Laurent Cohen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionObject[]invokeHook(Class<?> inf, String methodName, Object... parameters) Invoke all instances of the hook with the specified interface name, with the specified parameters.Object[]invokeHook(String inf, String methodName, Object... parameters) Invoke all instances of the hook with the specified interface name, with the specified parameters.invokeSingleHook(Class<?> inf, String methodName, Object... parameters) Invoke all instances of the hook with the specified interface name, with the specified parameters.invokeSingleHook(String inf, String methodName, Object... parameters) Invoke all instances of the hook with the specified interface name, with the specified parameters.static HookFactoryCreate a newHookFactory.<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.<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.<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.<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.<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.<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.voidreset()Reset this factory to its original state.<T> voidunregister(Class<T> infClass) Register a hook defined via SPI, of which a single instance is discovered and invoked.
-
Constructor Details
-
HookFactory
public HookFactory()
-
-
Method Details
-
newInstance
Create a newHookFactory.- Returns:
- a new
HookFactoryinstance.
-
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
Hookinstance.
-
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
Hookinstance.
-
registerSPISingleHook
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
Hookinstance.
-
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
Hookinstance.
-
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
Hookinstance.
-
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
Hookinstance.
-
unregister
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
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
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
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
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.
-