JPPF Issue Tracker
star_faded.png
Please log in to bookmark issues
task_small.png
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
    Task
  • Status
     
    Closed
  • Assigned to
    Not assigned to anyone
  • Progress
       
  • Type of bug
    Not triaged
  • Likelihood
    Not triaged
  • Effect
    Not triaged
  • Posted by
     lolo4j
  • Owned by
    Not owned by anyone
  • Estimated time
    Not estimated
  • Category
    Core
  • Resolution
    RESOLVED
  • Priority
    Normal
  • 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 {
  @Override
  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.

#1
Comment posted by
 lolo4j
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.
#2
Comment posted by
 lolo4j
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.
#3
Comment posted by
 lolo4j
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.