JPPF Issue Tracker
Please log in to bookmark issues
CLOSED  Task JPPF-159  -  Provide an API for easily implementing simple hooks in any area
Posted Jun 21, 2013 - updated Jun 22, 2013
icon_info.png This issue has been closed with status "Closed" and resolution "RESOLVED".
Issue details
  • Type of issue
  • Status
  • Assigned to
    Not assigned to anyone
  • Progress
  • Type of bug
    Not triaged
  • Likelihood
    Not triaged
  • Effect
    Not triaged
  • Posted by
  • Owned by
    Not owned by anyone
  • Estimated time
    Not estimated
  • Category
  • Resolution
  • Priority
  • Targetted for
    icon_milestones.png JPPF 4.0
Issue description
We define simple hooks as an interface whose implementation is specified via a configuration property, and where a single implementation is used at runtime.

For instance, if we have a "DriverWelcome" hook which displays a welcome message when the driver starts:
package jppf.welcome;
public interface DriverWelcome {
  void welcome();
with a default implementation:
package jppf.welcome;
public class DefaultDriverWelcome implements DriverWelcome {
  public void welcome() {
    System.out.println("Hello driver world!");
We could imagine having a factory to register and invoke the hooks, such as:
public class HookFactory {
  public static HookFactory newInstance() {
    return new HookFactory();
  public void registerHook(String configProperty, String interfaceClassName, String defaultImplClassName, String methodName) {
    // ...
  public void invokeHook(String configProperty, Object...parameters) {
    // ...
Here, the configProperty name is used as unique key to identify each hook. Then we would define and ivoke the DriverWelcome hook with:
HookFactory factory = HookFactory.newInstance();
factory.registerHook("jppf.driver.welcome", "jppf.welcome.DriverWelcome", "jppf.welcome.DefaultDriverWelcome", "welcome");
// ... later on ...
factory.invokeHook("jppf.driver.welcome"); // no parameters to the welcome() method
This would greatly simplify the work of adding new hooks in the code.

Comment posted by
Jun 21, 20:57
This could also be extended to plugins that are located and loaded via the SPI framework and which are just run once, like startup classes or node initialization hooks, etc...

I think it's preferable to leave more complex customizations out of it, such as listeners (node life cycle, server connection listener, etc...) as this would become pretty complex to use and would thereofre defeat the purpose of this generic hook idea.
Comment posted by
icon_reply.pngJun 21, 21:08, in reply to comment #1
Given my previous comment, we might have to change what is used as a key, like the interface qualified name for instance.
Comment posted by
Jun 22, 21:18
This is now implemented. Changes committed to SVN trunk revision 2765

The issue was updated with the following change(s):
  • This issue has been closed
  • The status has been updated, from New to Closed.
  • This issue's progression has been updated to 100 percent completed.
  • The resolution has been updated, from Not determined to RESOLVED.