costin      01/06/28 00:26:14

  Modified:    src/share/org/apache/tomcat/util/hooks Hooks.java
  Log:
  Decouple the Hook ( and the core ) from introspection, open it for
  better ( declarative or code generation ) mechanisms.
  
  The current implementation will still use the introspection ( until
  modules.xml will include the correct declarations about the callbacks ).
  
  As a side note, I repeated an old benchamark to find out if "too many hooks
  will affect performance"
  Surprisingly for me ( I didn't expected that ) - it does, with about 5%
  If you disable the code that sets up the hook chains with only the
  modules that are actually involved ( that's avg 3-4 calls per chain, most
  have 1-2 ), and if you run ~100.000 requests ( few times ), you may find
   a statistical difference ( now that we cut most of the hotspots from
  tomcat - a year ago it was none ).
  
  The surprise is that I expected the JIT to just eliminate the empty calls -
  5% is not insignificant.
  ( of course, this is just theoretical - there is no reason to
  add all the modules in all chains - that have been resolved a long ago, but
  it's interesting to know that it had such a small impact. )
  
  Revision  Changes    Path
  1.5       +24 -25    jakarta-tomcat/src/share/org/apache/tomcat/util/hooks/Hooks.java
  
  Index: Hooks.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/hooks/Hooks.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Hooks.java        2001/02/20 03:14:11     1.4
  +++ Hooks.java        2001/06/28 07:26:08     1.5
  @@ -62,7 +62,7 @@
   import java.io.*;
   import java.net.*;
   import java.util.*;
  -import java.lang.reflect.*;
  +import org.apache.tomcat.util.IntrospectionUtils;
   
   /** Hooks support. Hooks implement a chain-of-command pattern, and
    * are commonly used in most web servers as a mechanism of extensibility.
  @@ -201,30 +201,29 @@
       /** Test if the interceptor implements a particular
        *  method
        */
  -    public static boolean hasHook( Object obj, String methodN ) {
  -     try {
  -         Method myMethods[]=obj.getClass().getMethods();
  -         for( int i=0; i< myMethods.length; i++ ) {
  -             if( methodN.equals ( myMethods[i].getName() )) {
  -                 // check if it's overriden
  -                 Class declaring=myMethods[i].getDeclaringClass();
  -                 Class parentOfDeclaring=declaring.getSuperclass();
  -                 // this works only if the base class doesn't extend
  -                 // another class.
  -
  -                 // if the method is declared in a top level class
  -                 // like BaseInterceptor parent is Object, otherwise
  -                 // parent is BaseInterceptor or an intermediate class
  -                 if( ! "java.lang.Object".
  -                     equals(parentOfDeclaring.getName() )) {
  -                     return true;
  -                 }
  -             }
  -         }
  -     } catch ( Exception ex ) {
  -         ex.printStackTrace();
  -     }
  -     return false;
  +    private static boolean hasHook( Object obj, String methodN ) {
  +     if( hookFinder==null ) 
  +         return true;
  +     return hookFinder.hasHook( obj, methodN );
  +
       }
   
  +    // -------------------- hook for hook detection --------------------
  +    
  +    /** Interface that decouples the Hooks from the introspection code.
  +     We want to allow future modes that are not based on introspection -
  +     for example declarative ( using modules.xml declarations ) or
  +     based on code generation ( introspection done at deploy time ).
  +    */
  +    public static interface HookFinder {
  +     public boolean hasHook( Object obj, String hookName );
  +    }
  +    
  +    // 
  +    static HookFinder hookFinder=null;
  +    
  +    public static void setHookFinder( HookFinder hf ) {
  +     hookFinder=hf;
  +    }
  +    
   }
  
  
  

Reply via email to